Ron.Buckton at microsoft.com
Mon Mar 4 19:25:31 UTC 2019
Personally, I’d love to see something like this included as part of the temporal proposal (https://github.com/tc39/proposal-temporal), as I’ve been experimenting with something very much like this here: https://github.com/rbuckton/temporal/blob/master/src/Duration.ts.
I think a Duration type that meshes with the proposed `plus` method on temporal objects would be a huge benefit.
From: es-discuss <es-discuss-bounces at mozilla.org> On Behalf Of Alexandre Morgaut
Sent: Monday, March 4, 2019 10:47 AM
To: es-discuss list <es-discuss at mozilla.org>
Subject: Proposal: Duration
Here a proposal to make ECMAScript natively support a Duration Object
I talked about it a long time ago (2011) on the WHATWG mailing list in the context of the Timers API: https://lists.w3.org/Archives/Public/public-whatwg-archive/2011Feb/0533.htm<https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.w3.org%2FArchives%2FPublic%2Fpublic-whatwg-archive%2F2011Feb%2F0533.htm&data=02%7C01%7Cron.buckton%40microsoft.com%7Cb2fcb78ce9714918767e08d6a0d1d84f%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636873220570122388&sdata=bkZ0jPGkuKT3a35let3ZFVXrk2oq%2FeLzKN7xcuR1ym0%3D&reserved=0>
l think that such a proposal would better take place in the core of the language and having worked on a framework date time APIs I tried to give this approach a better look.
ECMAScript natively support Dates since its very first version
It started to support the ISO 8601 string format in edition 5
(184.108.40.206 Date Time String Format )
Durations like Dates can be very tricky, especially with I18n in mind, but the ECMA standard already had to be handled most of the Duration tricky part for the Date Object in EMCA 262 & ECMA 402.
Duration, sometimes called TimeInterval, is a common concept supported by most languages or associated standard libs.
In very short, Duration object would:
- support the ISO syntax in its contructor: new Duration('P6W') // for Period 6 Weeks
- allow to handle Date diff operations
- allow to be interpreted by setTimeout() & setInterval()
Please find below a draft exposing the concept
I'd be very happy if someone from TC39 would be interested to champion it
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss