Replies: 10 comments 1 reply
-
This is great! 🕰📆🚀 Here are some questions that occurred to me.
How do we handle timezones? Dotcom currently switches timezone based on edition and time of year (BST/GMT for the UK, AEST for AU, EDT for US and BST/GMT again for International). I think Apps may use device settings to select a timezone (@SLambrakis @maxspencer should be able to confirm).
👍
So the design system does two things?
What does typing usage mean?
Or we could display UNIX time? |
Beta Was this translation helpful? Give feedback.
-
e.g. closer to:
|
Beta Was this translation helpful? Give feedback.
-
On the iOS live app timezones do indeed come from the system. Ideally the date format also would, but we've ended up with a bunch of custom formats all over the place (which I'd love to standardise/lose eventually). Speaking of enums, iOS actually provides one (useable for formatting dates and times) that looks pretty similar to Nic's suggestion... https://developer.apple.com/documentation/foundation/dateformatter/style |
Beta Was this translation helpful? Give feedback.
-
+1 this is nicer @nicl Maybe the API could take the 'hours' to switch between relative and absolute date formats too so that's abstracted away from the platform complexity but I definitely think we'll be able to distill all the date formats into a more defined type.
Maybe this is an optional param then, I think the 'design' of the time-zoned date is still DS responsibility.
So you can define that a component takes a DateString that is returned from the formatting function?
Interesting! Maybe this is worth aligning to then? |
Beta Was this translation helpful? Give feedback.
-
Given the above, maybe the API then looks like. // Aligned to https://developer.apple.com/documentation/foundation/dateformatter/style ?
const enum DateFormat = {
none,
short,
medium,
long,
full
}
const enum Timezone = {
BST,
GMT, // How do you handle that BST vs GMT?
AEST,
EST
}
type DateString = string; formatDate(
timestamp: number,
dateFormat: DateFormat,
timeUntilAbsolute?: seconds,
timeZone?: Timezone
): DateString That feels to me like giving the DS enough info to 'design' the date, without being overly contextually specific? |
Beta Was this translation helpful? Give feedback.
-
We could instead define it as the TZ locations that correspond to the time zones we display:
then use the current date to figure out whether that should be the Daylight Saving variant or not?
Fair - I think this makes sense if type DateString = string;
function foo(s: DateString): string {
return s;
}
const bar = foo('hello'); We might want to do this for readability even if it doesn't provide us with any additional type safety? |
Beta Was this translation helpful? Give feedback.
-
Thanks @gtrufitt for starting this conversation and to everyone else for getting involved. It's started to identify some of the intracacies of this problem. There are a lot of angles we'd need to consider.
It would be really useful if we could continue to pick apart these kind of issues before we nail an API, although thinking in terms of API is a good way to help identify issues 🙂 I've started a doc to try to capture some of these considerations in a structured way. If anyone can think of any aspects of datetime that are not captured here, please add a comment here, or to the document. The design side of this conversation might have to wait until Akemi is back from sabbatical in mid-September. |
Beta Was this translation helpful? Give feedback.
-
This sounds sensible 🚀. So perhaps the Core Source function looks something like this: const format = (dateTime: string, dateFormat: DateFormat): string; And if we want, Editorial Source could provide a wrapper that also takes the Edition: const editorialFormat = (utcTime: string, dateFormat: DateFormat, edition: Edition): string => {
switch (edition) {
case Edition.AU:
return format(`${utcTime}+10:00`, dateFormat);
case Edition.US:
return format(`${utcTime}-04:00`, dateFormat);
case Edition.UK:
case Edition.INT:
default:
return format(utcTime, dateFormat);
}
}
Coming back to this again, I think it solves the timezone problem in general but pushes the handling of Daylight Saving shifts onto the caller? Because if the caller has to provide the offset (e.g. Perhaps we can, again, provide a wrapper function in Core Source that is able to handle Daylight Saving for a pre-defined shortlist of supported areas? const enum City {
London,
NewYork,
Sydney,
}
const formatWithDaylightSaving = (utcTime: string, dateFormat: DateFormat, city: City): string;
👍 for this. We could start with dotcom and apps, as I think they contain the most prominent and varied examples? |
Beta Was this translation helpful? Give feedback.
-
Cool topic and lots of good points raised. In Android we have access to an API provided by the Java standard library called It's not quite this simple, but at a high level the
where
val now = Date()
val longDateFormat = DateFormat.getDateInstance(DateFormat.LONG, Locale.UK)
println(longDateFormat.format(now)) Prints:
I wrote a little program to do some different combinations of val now = Date()
val styles = mapOf(
"short" to DateFormat.SHORT,
"medium" to DateFormat.MEDIUM,
"long" to DateFormat.LONG
)
val locales = listOf(Locale.UK, Locale.US, Locale.FRANCE, Locale.CHINA)
locales.forEach { locale ->
styles.forEach { (styleName, style) ->
val dateFormat = DateFormat.getDateTimeInstance(style, style, locale)
println("$locale, $styleName:\t${dateFormat.format(now)}")
}
println()
} Prints:
I think to some extent the philosophy of this class/API challenges the idea of date formats being purely a design decision, instead it asserts: "There are certain ways dates and times should be formatted and I |
Beta Was this translation helpful? Give feedback.
-
Is your feature request related to a problem? Please describe.
There are certain formatted dates across platforms used in the context of articles and cards. These date formats can get out of sync across platforms. Date formatting is performed in different ways across platforms (and modules used in platforms).
Describe the solution you'd like
The solution is not to request the date format in the YYY-DD-M type format (a la Moment).
The solution I think makes sense is to leave the Design System to format a timestamp given a context and the current time.
The function should take an argument prescriptive of the context of the date (dateline, card, discussion, liveblog dates etc) and a timestamp.
The decision when to switch from a 'Relative' (x hours ago) date to an 'Absolute' date (4th August 2020) is handled at the design system level (as it is a design decision). The formatter can decide for each context given a timestamp whether it returns relative or absolute dates.
I imagine the API to look something like:
Then the platforms can be aligned with display in all situations that timestamps need formatting.
It may be that multiple contexts have the same date format but, like the colour palettes, the formats should be distinct to the usage to allow them to be updated across platforms.
Describe alternatives you've considered
Additional context
Beta Was this translation helpful? Give feedback.
All reactions