Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upPurpose of Locale? #61
Comments
This comment has been minimized.
This comment has been minimized.
|
I don't personally have any plans to do anything with it; for the purpose I designed it for it works exactly as intended - working with date/time values that are in a locale seems like a fundamentally bad idea to me, so I convert to UTC, and then covert back if necessary afterwards, for presentation purposes. The inner value is supposed to be a value in UTC, the offset is supposed to be how much to alter that by when printing a localised date/time. That doesn't mean it's good though, it's primitive by design. I'm not sure I understand your point about GMT / BST though. They are different, yes, but you can "look" at a date in BST at any time of year, regardless of the time zone being observed. Knowing that some The library has no opinion about where you get your locale information from, so there's no reason you can't have something like a representative city -> locale function defined, as far as I can see? Likewise you can provide locale conversions easily enough. |
This comment has been minimized.
This comment has been minimized.
That doesn't mean I'm not open to changing it by the way, just saying that it's dumb by design currently. |
This comment has been minimized.
This comment has been minimized.
|
My main concern with the current Alternatively, if the timezone is associated with a representative-city, the offset doesn't need to be recalculated on every operation, and only needs to be calculated when "rendering" the We could make newtype LocaleName = LocaleName String -- "America/Chicago"
-- or --
newtype LocaleName = AmericaChicago | EuropeParis | ... | ...
data Locale = Locale LocaleName
data LocalValue a = LocalValue Locale a
type LocalDateTime = LocalValue DateTime
-- Apply the timezone offset
-- Might need second argument - the representative-city to offset map/data structure
unLocalDateTime :: LocalDateTime -> DateTime |
This comment has been minimized.
This comment has been minimized.
|
I'm curious what you think of a solution like the one I proposed the previous comment, as it seems to be philosophically quite different than the current design. Your design says an offset should be part of the LocalDateTime and my proposed design says the location of the DateTime should be part of the LocalDateTime. This isn't a high priority for me right now, so I wouldn't send a PR soon, but it's been an interest of mine for awhile. Also, it would be nice to know where this design would fit in this library - as a redesign of the current LocalDateTime or as a new module. |
This comment has been minimized.
This comment has been minimized.
|
It sounds like a nice idea, but I think it would be a lot of work to maintain. It seems like you'd need a lookup table for daylight savings changes for every location supported, for each year, and would have to keep updating that over time too? |
This comment has been minimized.
This comment has been minimized.
|
I believe ThreeTen would need to maintain such a data structure, yeah. |
This comment has been minimized.
This comment has been minimized.
|
Actually, looks like moment-timezone's data structures are a processed form of the data maintained by iana.org/time-zones. |
This comment has been minimized.
This comment has been minimized.
|
Looks like there are opportunities to minify the timezone rules by filtering the JSON-friendly format of the IANA files to contain only the 4 or 8 of timezones you expect the application's users to use, and to contain only the most current rules (the IANA has 60 years of rules due to to political bodies changing their timezones and offsets). |
This comment has been minimized.
This comment has been minimized.
|
I would suggest maybe we do this in a I suggest |
This comment has been minimized.
This comment has been minimized.
|
Sounds good. Do you want to leave this issue open until a separate locale/timezone solution becomes available? |
This comment has been minimized.
This comment has been minimized.
|
Sure thing, it'll be useful for anyone who has similar queries and drops by. If you have any interest in doing that library I can set up a contrib thing and give you access if you like? |
This comment has been minimized.
This comment has been minimized.
|
I'm quite busy for a bit, but will update here when I've got something worth sharing. |
This comment has been minimized.
This comment has been minimized.
|
Locale will be removed in the 0.12 release, so closing this. I hope to revisit some of the many issues this library has properly one day still, but for now I'm just going to remove all the problematic stuff and just keep the basics. |
chexxor commentedJul 14, 2017
•
edited
I can't find the explanation of
Locale. Am I missing it? Based on my interpretation from reading code, it seems to be fundamentally flawed. Is there plans to move this towards the ThreeTen model of "Locale"?Current explanation of
Locale:My problem with this is that timezone names (e.g. "GMT", "MDT", "CET") are a poor way of assigning timzone-offsets to a DateTime value. If the DateTime in England is in Summer, then "BST" offset applies, but if it's in Winter, then "GMT" offset applies. So, it makes more sense to join a DateTime with a representative-city than with a timezone. Actually rendering the DateTime with the offset considered, then, requires a map from representative-city to time-offset for that DateTime's specific value. (This map can be quite large, as seen in MomentJS's timezone file.)
The ThreeTen library follows this concept of using representative-city to specify a DateTime's offset, but it calls it "ZoneId". The ZonedDateTime explains a bit further.