Skip to content
This repository has been archived by the owner on Feb 3, 2024. It is now read-only.

Commit

Permalink
Deprecate and replace date formatting getters
Browse files Browse the repository at this point in the history
These toFormat calls were not localized and are not needed anymore,
let's replace them with the helper that makes everything much nicer.
  • Loading branch information
jrjohnson committed Oct 3, 2023
1 parent 694d3c0 commit bdda99f
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 11 deletions.
10 changes: 5 additions & 5 deletions addon/components/session-offerings-list.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div class="offering-block">
<div class="offering-block-date">
<span class="offering-block-date-dayofweek">
{{block.dayOfWeek}}
{{format-date block.date weekday="long"}}
</span>
<span class="offering-block-date-dayofmonth">
{{format-date block.date month="long" day="numeric"}}
Expand All @@ -22,13 +22,13 @@
<label class="offering-block-time-time-starts-label">
{{t "general.starts"}}:
</label>
{{offeringTimeBlock.longStartText}}
{{format-date offeringTimeBlock.startDate weekday="long" month="long" day="numeric" hour="numeric" minute="numeric"}}
</div>
<div class="offering-block-time-time-ends">
<label class="offering-block-time-time-ends-label">
{{t "general.ends"}}:
</label>
{{offeringTimeBlock.longEndText}}
{{format-date offeringTimeBlock.endDate weekday="long" month="long" day="numeric" hour="numeric" minute="numeric"}}
</div>
</div>
{{else}}
Expand All @@ -37,13 +37,13 @@
<label class="offering-block-time-time-starttime-label">
{{t "general.starts"}}:
</label>
{{offeringTimeBlock.startTime}}
{{format-date offeringTimeBlock.startDate hour="numeric" minute="numeric"}}
</span>
<span class="offering-block-time-time-endtime">
<label class="offering-block-time-time-endtime-label">
{{t "general.ends"}}:
</label>
{{offeringTimeBlock.endTime}}
{{format-date offeringTimeBlock.endDate hour="numeric" minute="numeric"}}
</span>
</div>
{{/if}}
Expand Down
45 changes: 43 additions & 2 deletions addon/utils/offering-date-block.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { DateTime } from 'luxon';
import { sortBy } from './array-helpers';
import { deprecate } from '@ember/debug';

class OfferingBlock {
offerings = [];
Expand All @@ -26,14 +27,26 @@ class OfferingDateBlock extends OfferingBlock {
}

get dateStamp() {
return DateTime.fromJSDate(this.date).toFormat('X');
return DateTime.fromJSDate(this.date).toUnixInteger();
}

get dayOfWeek() {
deprecate(`Calling dayOfWeek on OfferingDateBlock. Format this from date instead`, false, {
id: 'common.date-block-formats',
for: 'ilios-common',
until: '85',
since: '84',
});
return DateTime.fromJSDate(this.date).toFormat('EEEE');
}

get dayOfMonth() {
deprecate(`Calling dayOfMonth on OfferingDateBlock. Format this from date instead`, false, {
id: 'common.date-block-formats',
for: 'ilios-common',
until: '85',
since: '84',
});
return DateTime.fromJSDate(this.date).toFormat('MMMM d');
}

Expand Down Expand Up @@ -66,7 +79,7 @@ class OfferingTimeBlock extends OfferingBlock {
}

get isMultiDay() {
return this.startDate.toFormat('oooYYYY') !== this.endDate.toFormat('oooYYYY');
return !this.startDate.hasSame(this.endDate, 'day');
}

//pull our times out of the key
Expand All @@ -81,18 +94,46 @@ class OfferingTimeBlock extends OfferingBlock {
}

get startTime() {
deprecate(`Calling startTime on OfferingTimeBlock. Format this from startDate instead`, false, {
id: 'common.date-block-formats',
for: 'ilios-common',
until: '85',
since: '84',
});
return this.startDate.toFormat('t');
}

get endTime() {
deprecate(`Calling endTime on OfferingTimeBlock. Format this from endDate instead`, false, {
id: 'common.date-block-formats',
for: 'ilios-common',
until: '85',
since: '84',
});
return this.endDate.toFormat('t');
}

get longStartText() {
deprecate(
`Calling longStartText on OfferingTimeBlock. Format this from startDate instead`,
false,
{
id: 'common.date-block-formats',
for: 'ilios-common',
until: '85',
since: '84',
},
);
return this.startDate.toFormat('EEEE MMMM d @ t');
}

get longEndText() {
deprecate(`Calling longEndText on OfferingTimeBlock. Format this from endDate instead`, false, {
id: 'common.date-block-formats',
for: 'ilios-common',
until: '85',
since: '84',
});
return this.endDate.toFormat('EEEE MMMM d @ t');
}

Expand Down
23 changes: 19 additions & 4 deletions tests/acceptance/course/session/offerings-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,26 @@ module('Acceptance | Session - Offerings', function (hooks) {
assert.strictEqual(blocks[2].timeBlockOfferings.offerings.length, 1);
assert.strictEqual(
blocks[2].multiDayStart,
'Starts: ' + DateTime.fromJSDate(this.offering3.startDate).toFormat('cccc MMMM d @ h:mm a'),
'Starts: ' +
this.intl.formatDate(this.offering3.startDate, {
month: 'long',
day: 'numeric',
weekday: 'long',
hour: 'numeric',
minute: 'numeric',
}),
);

assert.strictEqual(
blocks[2].multiDayEnd,
'Ends: ' + DateTime.fromJSDate(this.offering3.endDate).toFormat('cccc MMMM d @ h:mm a'),
'Ends: ' +
this.intl.formatDate(this.offering3.endDate, {
month: 'long',
day: 'numeric',
weekday: 'long',
hour: 'numeric',
minute: 'numeric',
}),
);
});

Expand Down Expand Up @@ -357,8 +372,8 @@ module('Acceptance | Session - Offerings', function (hooks) {
assert.notOk(block.hasEndTime);
assert.strictEqual(block.dayOfWeek, 'Sunday');
assert.strictEqual(block.dayOfMonth, 'September 11');
assert.strictEqual(block.multiDayStart, 'Starts: Sunday September 11 @ 2:15 AM');
assert.strictEqual(block.multiDayEnd, 'Ends: Monday September 12 @ 5:30 PM');
assert.strictEqual(block.multiDayStart, 'Starts: Sunday, September 11 at 2:15 AM');
assert.strictEqual(block.multiDayEnd, 'Ends: Monday, September 12 at 5:30 PM');
assert.strictEqual(block.timeBlockOfferings.offerings.length, 1);

assert.strictEqual(block.timeBlockOfferings.offerings[0].learnerGroups.length, 2);
Expand Down

0 comments on commit bdda99f

Please sign in to comment.