-
Notifications
You must be signed in to change notification settings - Fork 1
Conversation
1a95c61
to
1e9c9fb
Compare
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.
nice work 👍
@@ -137,7 +105,9 @@ export const timeAgo = ( | |||
// Simple date - "9 Nov 2019" | |||
return [ | |||
then.getDate(), | |||
verbose ? longMonth(then.getMonth()) : shortMonth(then.getMonth()), | |||
verbose |
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.
ah! a lot nicer :)
? then.toLocaleString('default', { month: 'long' }) | ||
: then.toLocaleString('default', { month: 'short' }), |
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.
@oliverlloyd how do you feel about these? guardian is at 98.99% support (greater than es module support). are they going to have wierd unexpected effects?
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.
Given that the other functions in this file return English strings, and the style guide is British English, is it possible we want to use 'en-GB'
here?
? then.toLocaleString('default', { month: 'long' }) | |
: then.toLocaleString('default', { month: 'short' }), | |
? then.toLocaleString('en-GB', { month: 'long' }) | |
: then.toLocaleString('en-GB', { month: 'short' }), |
I think using 'default'
will use the browser/system's default locale, and will therefore give the month in the language for that locale? For example, in French if the system is set to French. You can test this with the following snippet of code:
const d = new Date();
d.toLocaleString('default', { month: 'long' });
in Node by setting the LANG
environment variable:
LANG=fr_FR node
or in a browser by changing the macOS system language to e.g. French, restarting your browser, and then pulling up a console (tested in Firefox and Safari).
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.
Completely agree with @JamieB-gu here! I would be tempted to move this to a separate PR, as it’s possibly a breaking change, or at least most definitly a feature.
I am one such user who would not want my dates in French if I’m browsing an english-language website.
My suggestion for the existing code would be:
const longMonth = (month: number): string =>
([
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December',
] as const)[month] ?? "Unknown";
const shortMonth = (month: number) => longMonth(month).slice(0,3);
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 is a great point – 'en-GB'
should resolve that though?
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.
I think then.toLocaleString('en-GB', { month: 'short' })
best respects the design guide
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.
I thought that toLocaleString
was not well supported in browsers, but it seems like that’s not the case, there’s only missing data for about 3% of browsers.
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.
Support is available for everything that supports es modules afaict?
have a ☕ first
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 is great, but I would not change the behaviour of timeAgo
as part of this change.
? then.toLocaleString('default', { month: 'long' }) | ||
: then.toLocaleString('default', { month: 'short' }), |
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.
Completely agree with @JamieB-gu here! I would be tempted to move this to a separate PR, as it’s possibly a breaking change, or at least most definitly a feature.
I am one such user who would not want my dates in French if I’m browsing an english-language website.
My suggestion for the existing code would be:
const longMonth = (month: number): string =>
([
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December',
] as const)[month] ?? "Unknown";
const shortMonth = (month: number) => longMonth(month).slice(0,3);
I don’t think this should go in as-is, because of the timeAgo
changes.
Co-authored-by: Max Duval <[email protected]>
Co-authored-by: Max Duval <[email protected]>
Co-authored-by: Max Duval <[email protected]>
what do you think needs to change to make them ok? the if the |
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.
Indeed, with the great support of toLocaleString
, I think this is good to go!
? then.toLocaleString('default', { month: 'long' }) | ||
: then.toLocaleString('default', { month: 'short' }), |
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.
I thought that toLocaleString
was not well supported in browsers, but it seems like that’s not the case, there’s only missing data for about 3% of browsers.
🎉 This PR is included in version 7.1.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
@sndrs did we want to change the |
Doh! Yes I completely forgot to implement it! |
@JamieB-gu correct locale went out in https://github.com/guardian/libs/releases/tag/v7.1.3 |
What does this change?
Adds
@guardian/tsconfig
to the typscript configWhy?
It's stricter (in a good way) and preps the code for import to https://github.com/guardian/csnx