-
Notifications
You must be signed in to change notification settings - Fork 152
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
Feedback from Google C++ date library authors #139
Comments
I don't know much about JavaScript, but I expect that this is much nicer than what exists today :-) I've skimmed most of the markdown files. In my head, I'm comparing the concepts presented here to the concepts we used in https://abseil.io/docs/cpp/guides/time. Some thoughts:
|
I (of course?) agree with what @devjgm had to say. The only specific thing I have to add at the moment concerns, "Negative durations make no sense." I would take the opposite position. Indeed, if "Durations can only be created through the minus method on temporal objects," like |
i prefer going further and restricting datetime-arithmetic to only UTC-time. its unrealistic to expect integrated-systems to perform arithmetic-calculations exclusively in javascript -- some of the logic will inevitably be offloaded to databases and non-javascript systems, creating consistency issues. the only way to mitigate this painpoint is by forcing all these heterogenous systems to do datetime-arithmetic in UTC.
again, if you want it to be consistent with parallel calculation done in databases, you have to restrict arithmetic exclusively to UTC-time. |
lets take real-world example from https://www.google.com/flights/.
|
Perfect; thank you!
Ideally, let departure = ZonedDateTime.fromString('2020-03-08T11:55:00+08:00[Asia/Hong_Kong]');
let arrival = ZonedDateTime.fromString('2020-03-08T09:50:00-07:00[America/Los_Angeles]');
let difference = arrival.difference(departure, 'minutes'); But if that method doesn't make the cut, then
Ideally, |
what if i'm unsure whether or not los-angeles is under daylight-savings? will this work? let departure = ZonedDateTime.fromString('2020-03-08T11:55:00+08:00[Asia/Hong_Kong]');
-let arrival = ZonedDateTime.fromString('2020-03-08T09:50:00-07:00[America/Los_Angeles]');
+let arrival = ZonedDateTime.fromString('2020-03-08T09:50:00[America/Los_Angeles]');
let difference = arrival.difference(departure, 'minutes'); |
No, I don't think so. But you can do let arrival = CivilDateTime.fromString('2020-03-08T09:50:00').withZone('America/Los_Angeles'); |
sorry for being annoying, but you can solve this problem just as well with 2 static-functions that convert between [utc] ISOString <-> [local] ISOString: function getUTCFromLocal (isostringUtc, zone) {...}
function getUTCToLocal (isostringLocal, zone) {...}
var duration;
var arriveLocal;
var arriveUtc;
var departUtc;
/*
* 1. get flight-duration from (arrive - depart)
*/
departUtc = getUTCFromLocal("2020-03-08T11:55:00", "Asia/Hong_Kong");
arriveUtc = getUTCFromLocal("2020-03-08T09:50:50", "America/Los_Angeles");
duration = (
new Date(arriveUtc).getTime() - new Date(departUtc).getTime()
) / (60 * 1000);
// departUtc = "2020-03-08T03:55:00.000Z"
// arriveUtc = "2020-03-08T16:50:00.000Z"
// duration = 775
/*
* 2. get [local] flight-arrive from (depart + duration)
*/
departUtc = getUTCFromLocal("2020-03-08T11:55:00", "Asia/Hong_Kong");
arriveUtc = new Date(
new Date(departUtc).getTime()
+ 775 * 60 * 1000
).toISOString();
arriveLocal = getUTCToLocal(arriveUtc, "America/Los_Angeles");
// departUtc = "2020-03-08T03:55:00.000Z"
// arriveUtc = "2020-03-08T16:50:00.000Z"
// arriveLocal = "2020-03-08T09:50:50.000+07:00" instead of burdening tc39/w3c/mozilla members with tedious-specs dealing with temporal-class-interoperabilities, |
@devjgm thank you so much for taking the time. I've taken a lot of what you've said into the next version of the polyfill.
I hope these conclusions make sense. This has been really valuable. I'll now close this issue and ask for a bit of time. By the end of September the spec-text will have been updated so that I can give an update to TC39 (2019-10-01T09:00:00-04:00[America/New_York] to about 2019-10-01T17:00:00-04:00[America/New_York]) |
Hi @devjgm - re: your feedback above:
What were other confusing things users found confusing with a combined type? I'm asking because I've suggested having a combined {Absolute,TimeZone} type that encodes DST best practices in order to help newbies avoid accidentally committing DST bugs. So I'm interested to learn what the tradeoffs of having such a type might be for JS developers. I realize that Google's C++ engineers might have a higher bar for complexity but a lower bar for inconsistency compared to novice app devs in the JS community. ;-) But I still expect that your experience here is very valuable context. BTW, your library is a great design. It's been decades since I wrote any C++ but I wish I'd had this back in the day! |
I have reached out to @devjgm and @devbww, who have worked extensively on date libraries in C++, to provide feedback on the ergonomics of Temporal. I've asked them to post their feedback here in this thread.
The text was updated successfully, but these errors were encountered: