-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add date and time utils to use in downstream projects #1726
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The module is called time.ts
in client and date.ts
in LMS, so I decided to call it date-and-time.ts
.
9840b1c
to
bd95bcb
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1726 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 66 67 +1
Lines 1121 1195 +74
Branches 439 449 +10
=========================================
+ Hits 1121 1195 +74 ☔ View full report in Codecov by Sentry. |
bd95bcb
to
10817a5
Compare
export function formatDateTime( | ||
date: Date | string, | ||
options?: FormatDateTimeOptions, | ||
): string { | ||
return format( | ||
typeof date === 'string' ? new Date(date) : date, | ||
{ | ||
year: 'numeric', | ||
month: 'short', | ||
day: '2-digit', | ||
weekday: options?.includeWeekday ? 'long' : undefined, | ||
hour: '2-digit', | ||
minute: '2-digit', | ||
}, | ||
options?.Intl, | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function consolidates formatDate
from client, which includes the weekday, and formatDateTime
from LMS, which returns the same format but without the weekday.
The formatDateTime
name seems more correct, and the dynamic inclusion of the weekday is now handled by an optional config option.
it('returned function cancels the timer', () => { | ||
const date = new Date().toISOString(); | ||
const callback = sandbox.stub(); | ||
const cancel = decayingInterval(date, callback); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could modernize this API in future by returning an AbortSignal
. This would make the meaning of the return value more obvious and potentially simplify use in other browser APIs.
10817a5
to
41868eb
Compare
This PR brings and consolidates in the shared library a few time and date related utilities that we have defined in
client
andLMS
over time:So far we have been copying the few things that were needed in both places, but we are going to need the functions around relative times, which would duplicate most of the code.