The idea is to make it easier to use for the general case, and *not* implement a feature complete Date library. We eventually need something like Java's Joda library, but such a library would be way too big for the corelib and would confuse most people (Dates, DateTimes, and TimeZones are unfortunately pretty complicated...).As a first step I want to do the modifications I propose in CL https://chromiumcodereview.appspot.com/10384149
I also propose closing http://dartbug.com/1424 (Split into Date and TimeStamp). This is outside the scope of the corelib.
Hi,The idea is to make it easier to use for the general case, and *not* implement a feature complete Date library. We eventually need something like Java's Joda library, but such a library would be way too big for the corelib and would confuse most people (Dates, DateTimes, and TimeZones are unfortunately pretty complicated...).As a first step I want to do the modifications I propose in CL https://chromiumcodereview.appspot.com/10384149if I understand correctly, your argument and your code is based on the assumption that timezones are hard, make the code complicated and in a vast majority of situations, they aren't even necessary. I completely and wholeheartedly agree. Having the corelib's date/time support as much timezones-free as possible is a goal I can identify with.
From looking at the proposed Date interface, it looks like it can't be completely timezones-free (because even the unix timestamp value refers to UTC), so instead, the date is implicitly in local timezone. Correct? I guess I can live with that.
I also propose closing http://dartbug.com/1424 (Split into Date and TimeStamp). This is outside the scope of the corelib.I still believe that having separate Date and DateTime in the corelib (both of them in local timezone) is extremely valuable, because using date+time value for modeling date value gets inconvenient pretty quickly. I'm obviously not the one to decide what is in corelib's scope and what isn't, but I'd plead for considering this once more.
LT
Something I often need is the equivalent of Date.fromEpoch but with human-readable arguments. Otherwise I keep going to http://www.epochconverter.com/ and I put the human-readable UTC date in a comment next to the timestamp. It doesn't add any expressivity, just readability.
On Mon, May 14, 2012 at 4:41 PM, Florian Loitsch <floi...@google.com> wrote:How should that look like? In the past years I needed access to
> On Mon, May 14, 2012 at 4:31 PM, Ladislav Thon <lad...@gmail.com> wrote:
>>
>> Hi,
>>
>>> The idea is to make it easier to use for the general case, and *not*
>>> implement a feature complete Date library. We eventually need something like
>>> Java's Joda library, but such a library would be way too big for the corelib
>>> and would confuse most people (Dates, DateTimes, and TimeZones are
>>> unfortunately pretty complicated...).
>>>
>>> As a first step I want to do the modifications I propose in
>>> CL https://chromiumcodereview.appspot.com/10384149
>>
>>
>> if I understand correctly, your argument and your code is based on the
>> assumption that timezones are hard, make the code complicated and in a vast
>> majority of situations, they aren't even necessary. I completely and
>> wholeheartedly agree. Having the corelib's date/time support as much
>> timezones-free as possible is a goal I can identify with.
>
> Correct: no (explicit) timezones in the corelib.
perfect timezone support (I am a Joda fan) and really cannot imagine
how it would work without.
Horrible outlook if I can't change the timezone.
>>
>> From looking at the proposed Date interface, it looks like it can't be
>> completely timezones-free (because even the unix timestamp value refers to
>> UTC), so instead, the date is implicitly in local timezone. Correct? I guess
>> I can live with that.
>
> Yes. Dates will always be (implicitly) in the local timezone.
Maybe I miss something, but if not, please reconsider. I constantly
need timezone calculations and would like to avoid writing my own lib.
> Correct: no (explicit) timezones in the corelib.How should that look like? In the past years I needed access to
perfect timezone support (I am a Joda fan) and really cannot imagine
how it would work without.
Like java.util.Date, the Calendar classes and Joda, which now becomes
part of the SDK?
Hope it will not cause more confusion than expected.
Ahmet
Cheers,
Sean
We are discussing moving even the simplified version of Date into its own library (for instance "dart:date").
Wrt the naming. Yes, keeping the names consistent would be a plus, but "Date" seems to be pretty entrenched. Also, because there is just no really good substitute. None of DateTime, Time, Instant or Moment is something that is easily found.
On Wed, May 16, 2012 at 11:41 AM, Florian Loitsch <floi...@google.com> wrote:We are discussing moving even the simplified version of Date into its own library (for instance "dart:date").+1Wrt the naming. Yes, keeping the names consistent would be a plus, but "Date" seems to be pretty entrenched. Also, because there is just no really good substitute. None of DateTime, Time, Instant or Moment is something that is easily found.I think 'Date' is entrenched, but everyone has different expectations of it:
- New developers expect it to be a calendar date with no time attached (as in English)
- People familiar with other languages expect it to have a timezone, defaulting to local
- And Dart is (sensibly) considering making it a UTC timestamp
I think 'Instant' is a better name, because:
- Its plain-English meaning is closer to a timestamp than 'Date'
- It's not misleadingly similar different concepts from other languages
- most won't know it at all
- people familiar with Joda will get the correct idea
- people won't complain about it being different, most Date APIs suck
- There will be less pressure to include formatting methods (and thus timezone logic) in this class if it's called Instant vs Date.
Cheers,Sam
On Wed, May 16, 2012 at 1:00 PM, Sam McCall <samm...@google.com> wrote:On Wed, May 16, 2012 at 11:41 AM, Florian Loitsch <floi...@google.com> wrote:We are discussing moving even the simplified version of Date into its own library (for instance "dart:date").+1Wrt the naming. Yes, keeping the names consistent would be a plus, but "Date" seems to be pretty entrenched. Also, because there is just no really good substitute. None of DateTime, Time, Instant or Moment is something that is easily found.I think 'Date' is entrenched, but everyone has different expectations of it:
- New developers expect it to be a calendar date with no time attached (as in English)
- People familiar with other languages expect it to have a timezone, defaulting to local
- And Dart is (sensibly) considering making it a UTC timestamp
I think 'Instant' is a better name, because:The problem with "Instant" is that it clashes with threeten. There "Instant" is just a wrapper around the epoch-value. The equivalent class would be "ZonedDateTime" and that's a no go for the simplified class name.
On Wed, May 16, 2012 at 5:58 PM, Florian Loitsch <floi...@google.com> wrote:On Wed, May 16, 2012 at 1:00 PM, Sam McCall <samm...@google.com> wrote:On Wed, May 16, 2012 at 11:41 AM, Florian Loitsch <floi...@google.com> wrote:We are discussing moving even the simplified version of Date into its own library (for instance "dart:date").+1Wrt the naming. Yes, keeping the names consistent would be a plus, but "Date" seems to be pretty entrenched. Also, because there is just no really good substitute. None of DateTime, Time, Instant or Moment is something that is easily found.I think 'Date' is entrenched, but everyone has different expectations of it:
- New developers expect it to be a calendar date with no time attached (as in English)
- People familiar with other languages expect it to have a timezone, defaulting to local
- And Dart is (sensibly) considering making it a UTC timestamp
I think 'Instant' is a better name, because:The problem with "Instant" is that it clashes with threeten. There "Instant" is just a wrapper around the epoch-value. The equivalent class would be "ZonedDateTime" and that's a no go for the simplified class name.I'm confused, I thought we were talking about a 'wrapper around an epoch-value' - that's the baseline that I'd expect to be (almost) part of the language.
Once you start including timezones then the complexity comes in, and I agree there's not a great name for that - but it would be one name among several in such a library (c.f. joda/threeten) and so it would be easier to draw distinctions through a naming system.
On May 16, 2012 8:21 PM, "Florian Loitsch" <floi...@google.com> wrote:
>
> On Wed, May 16, 2012 at 6:40 PM, Sam McCall <samm...@google.com> wrote:
>>
>> On Wed, May 16, 2012 at 5:58 PM, Florian Loitsch <floi...@google.com> wrote:
>>>
>>> On Wed, May 16, 2012 at 1:00 PM, Sam McCall <samm...@google.com> wrote:
>>>>
>>>> On Wed, May 16, 2012 at 11:41 AM, Florian Loitsch <floi...@google.com> wrote:
>>>>>
>>>>> We are discussing moving even the simplified version of Date into its own library (for instance "dart:date").
>>>>
>>>> +1
>>>>
>>>>>
>>>>> Wrt the naming. Yes, keeping the names consistent would be a plus, but "Date" seems to be pretty entrenched. Also, because there is just no really good substitute. None of DateTime, Time, Instant or Moment is something that is easily found.
>>>>
>>>>
>>>> I think 'Date' is entrenched, but everyone has different expectations of it:
>>>> New developers expect it to be a calendar date with no time attached (as in English)
>>>> People familiar with other languages expect it to have a timezone, defaulting to local
>>>> And Dart is (sensibly) considering making it a UTC timestamp
>>>> I think 'Instant' is a better name, because:
>>>
>>> The problem with "Instant" is that it clashes with threeten. There "Instant" is just a wrapper around the epoch-value. The equivalent class would be "ZonedDateTime" and that's a no go for the simplified class name.
>>
>> I'm confused, I thought we were talking about a 'wrapper around an epoch-value' - that's the baseline that I'd expect to be (almost) part of the language.
>
> You want year, month, ... getters and a toString method. There will be no explicit timezone since it will always be the local one.
This is a really bad idea, in my (limited) experience. Apps whose date needs are simple need a timestamp that they can trivially compare, increment in seconds, and pass through safely. UTC timestamps a.k.a Instant achieves this.
Apps that need Day, local time, etc need to be timezone aware.
Providing a ZonedDateTime as the 'simple' type will result in lots of broken-by-default behavior and attractive nuisances for apps whose needs are simple.
Java's history is a good demonstration of this...
// florian
--
Give a man a fire and he's warm for the whole day,
but set fire to him and he's warm for the rest of his life. - Terry Pratchett
On Wed, May 16, 2012 at 8:21 PM, Florian Loitsch <floi...@google.com> wrote:On Wed, May 16, 2012 at 6:40 PM, Sam McCall <samm...@google.com> wrote:On Wed, May 16, 2012 at 5:58 PM, Florian Loitsch <floi...@google.com> wrote:On Wed, May 16, 2012 at 1:00 PM, Sam McCall <samm...@google.com> wrote:On Wed, May 16, 2012 at 11:41 AM, Florian Loitsch <floi...@google.com> wrote:We are discussing moving even the simplified version of Date into its own library (for instance "dart:date").+1Wrt the naming. Yes, keeping the names consistent would be a plus, but "Date" seems to be pretty entrenched. Also, because there is just no really good substitute. None of DateTime, Time, Instant or Moment is something that is easily found.I think 'Date' is entrenched, but everyone has different expectations of it:
- New developers expect it to be a calendar date with no time attached (as in English)
- People familiar with other languages expect it to have a timezone, defaulting to local
- And Dart is (sensibly) considering making it a UTC timestamp
I think 'Instant' is a better name, because:The problem with "Instant" is that it clashes with threeten. There "Instant" is just a wrapper around the epoch-value. The equivalent class would be "ZonedDateTime" and that's a no go for the simplified class name.I'm confused, I thought we were talking about a 'wrapper around an epoch-value' - that's the baseline that I'd expect to be (almost) part of the language.You want year, month, ... getters and a toString method. There will be no explicit timezone since it will always be the local one.Once you start including timezones then the complexity comes in, and I agree there's not a great name for that - but it would be one name among several in such a library (c.f. joda/threeten) and so it would be easier to draw distinctions through a naming system.There will be no Timezone class but the Date class will have properties that implicitly make it live in the users timezone. There will be no way to get dates from other timezones (except maybe UTC). As such it resembles the ZonedDateTime class from ThreeTen.
Currently my biggest question is: should we have a way to get to UTC data (like the JS getUTCMonth) or not.If yes we could have:a. an isUtc boolean. This would basically replace the TimeZone class but still keeping exactly the same functionality.b. only a toUtcString (which seems to be the most common use-case for utc dates).c. a UtcDate class.d. utc-getters (like in JavaScript).Personally I'm against d, but a, b and c are all possible, and people here at the office seem to have different opinions.FYI: after some input from other Googlers, option b is off the table.
On 16 May 2012 20:11, Florian Loitsch <floi...@google.com> wrote:On Wed, May 16, 2012 at 8:21 PM, Florian Loitsch <floi...@google.com> wrote:On Wed, May 16, 2012 at 6:40 PM, Sam McCall <samm...@google.com> wrote:On Wed, May 16, 2012 at 5:58 PM, Florian Loitsch <floi...@google.com> wrote:On Wed, May 16, 2012 at 1:00 PM, Sam McCall <samm...@google.com> wrote:On Wed, May 16, 2012 at 11:41 AM, Florian Loitsch <floi...@google.com> wrote:We are discussing moving even the simplified version of Date into its own library (for instance "dart:date").+1Wrt the naming. Yes, keeping the names consistent would be a plus, but "Date" seems to be pretty entrenched. Also, because there is just no really good substitute. None of DateTime, Time, Instant or Moment is something that is easily found.I think 'Date' is entrenched, but everyone has different expectations of it:
- New developers expect it to be a calendar date with no time attached (as in English)
- People familiar with other languages expect it to have a timezone, defaulting to local
- And Dart is (sensibly) considering making it a UTC timestamp
I think 'Instant' is a better name, because:The problem with "Instant" is that it clashes with threeten. There "Instant" is just a wrapper around the epoch-value. The equivalent class would be "ZonedDateTime" and that's a no go for the simplified class name.I'm confused, I thought we were talking about a 'wrapper around an epoch-value' - that's the baseline that I'd expect to be (almost) part of the language.You want year, month, ... getters and a toString method. There will be no explicit timezone since it will always be the local one.Once you start including timezones then the complexity comes in, and I agree there's not a great name for that - but it would be one name among several in such a library (c.f. joda/threeten) and so it would be easier to draw distinctions through a naming system.There will be no Timezone class but the Date class will have properties that implicitly make it live in the users timezone. There will be no way to get dates from other timezones (except maybe UTC). As such it resembles the ZonedDateTime class from ThreeTen.I don't think you can get away with this. Or rather, you can, but you'd be relying on someone else to write a de facto standard date/time library, like Java did.
Consider: my server's on the America/New York time zone (despite being located in Texas). I store my dates in UTC. How do I format these dates for my users, half of whom are in Seattle and half of whom are in New Zealand?
Okay, I do all my date formatting with client-side scripts. And I hope the user visiting an internet cafe while on vacation in Thailand doesn't mind seeing their data in UTC+7 rather than UTC-8 while looking at their work schedule, or think they're reporting in for a shift starting at 4pm rather 1am when they get back in three days. (Not an unreasonable situation with hospital staff scheduling.)
Currently my biggest question is: should we have a way to get to UTC data (like the JS getUTCMonth) or not.If yes we could have:a. an isUtc boolean. This would basically replace the TimeZone class but still keeping exactly the same functionality.b. only a toUtcString (which seems to be the most common use-case for utc dates).c. a UtcDate class.d. utc-getters (like in JavaScript).Personally I'm against d, but a, b and c are all possible, and people here at the office seem to have different opinions.FYI: after some input from other Googlers, option b is off the table.Some thoughts and perhaps silly ideas on the matter:Anything that involves scheduled tasks needs to use UTC internally. (Someone switch my server's timezone? I ain't even mad.)
Anything that ever needs to distinguish or order events by date needs to use UTC internally. (Daylight savings time was a recurring issue at my previous job.)
Anything that involves users in different timezones needs to store dates internally using some single, agreed-on timezone. (For instance, parsing out EXIF metadata to get the date at which a photo was taken, after the user uploads it.) UTC is the default choice.
What needs to deal with timezones other than UTC? Displaying stuff in a user's local timezone. Taking user input.
The only other situation in which it's tempting to use anything but UTC is when your userbase is small enough to be constrained in one timezone, or if time isn't sufficiently important in your system for users to mind seeing everything in your server's timezone (and you don't mind the occasional DST issue).
And now, for the crazy idea:How about UTC being the only way to store dates, and giving formatting and parsing options that are timezone-aware? You still need a notion of a timezone, but it would solve a number of bugs before they're written.
On Wed, May 16, 2012 at 11:47 PM, Florian Loitsch <floi...@google.com> wrote:I can live with not having a wrapper for a ms-since-epoch value. It
> Other than that I don't see why a simplified Date class wouldn't be helpful.
> It would be basically identical to a ZonedDateTime from ThreeTen that is
> instantiated with the current timezone. The main difference would be that
> you just cannot instantiate ZonedDateTime with anything else (except maybe
> UTC which is still under discussion).
really is just a number.
The "Date" wrapper will then provide "calendar" access to such a
moment using a single default calendar (proleptic gregorian) in a
single time zone (default is current local time).
I would still want to be able to:
- Create date objects in any time zone (as minutes delta from UTC,
anything else is too complex)
- read the time zone of a Date object.
This would allow a server to operate on dates in the client's time
zone, if it can get the time zone from the client.
The system must be able to find the current time zone anyway, and the
Date object must be able to handle any current time zone, so this will
not cause any extra complexity by itself (except perhaps in dart2js).
Or, do you plan to let the the Date object handle daylight saving too?
I.e., not just one timezone, but two, and rules for selecting one or
the other?
/L
--
Lasse R.H. Nielsen
l...@google.com
'Faith without judgement merely degrades the spirit divine'
Google Denmark ApS - Frederiksborggade 20B, 1 sal - 1360 København K -
Denmark - CVR nr. 28 86 69 84
On Tue, May 22, 2012 at 10:02 AM, Florian Loitsch <floi...@google.com> wrote:I noticed you also added 'toUtc' and 'toLocal' methods. Will the
> I thought about this for a long time, but eventually decided to just give
> access to a UTC class (the 'isUtc" boolean).
constructors be updated to allow creation of utc Dates, or will it be
required to first create a local Date and then call 'toUtc' on it ?
Also, these methods might be good candidates for being getters, e.g.
'inLocal' and 'inUtc' (similar to the Duration in... getters) or
'asLocal' and 'asUtc'.
I compiled a list of Date refactoring issues that have yet to be
> Note: additional features are lower on my list than refactoring the API. It
> is always easy to add new functionality, but changing names or arguments
> potentially breaks users, and has therefore higher priority.
discussed on the list (that I know of):
http://dartbug.com/2771
Date constructor should allow arguments to overflow/underflow
Inconsistent Date field names
http://dartbug.com/1985
Rename Date.fromString to Date.parse
http://dartbug.com/3068
Date.fromEpoch and Date#value inconsistently named
http://dartbug.com/3172
Any input ?
Cheers,
Sean Eagan