Skip to content
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

DateTimeFormatter.ofPattern('zzz') does not include daylight/standard time indicator #518

Open
mlc opened this issue Jun 29, 2021 · 9 comments
Labels

Comments

@mlc
Copy link

mlc commented Jun 29, 2021

On the JDK, the java.time.formatters for the pattern "zzz" return either EDT or EST if you are in America/New York:

Screen Shot 2021-06-29 at 1 57 22 PM

However, js-joda returns just ET, omitting the D or S indicator:

Screen Shot 2021-06-29 at 2 11 10 PM

I would expect js-joda to be consistent with the JDK and with its own docs, and return EDT here.

@pithu
Copy link
Member

pithu commented Jun 30, 2021

Hi @mlc

Thanks for reporting. It might be a bug or missing functionality, i can reproduce the issue for European timezones as well. Looks like the locale formatter is not aware of daylight savings.

const { LocalDateTime, ZoneId, DateTimeFormatter } = require("@js-joda/core");
require("@js-joda/timezone");
const { Locale } = require("@js-joda/locale_de-de");

const f = DateTimeFormatter.ofPattern("h:ma zzz").withLocale(Locale.GERMAN);
const d = LocalDateTime.parse("2021-06-30T08:06:00").atZone(ZoneId.of("Europe/Berlin"));

f.format(d); 
// -> 8:6AM MEZ
// should be -> 8:6AM MESZ

@phueper any ideas ?

@pithu pithu added the bug label Jun 30, 2021
@phueper
Copy link
Member

phueper commented Jun 30, 2021

Hi,

i don't have an idea... i suppose it is related to locale ... i will try to debug it

@pithu
Copy link
Member

pithu commented Oct 10, 2021

After diving into the locale packages, i figured out that this functionality is simply not yet implemented.
So it would be great if someone could improve on this. Its mainly about fixing the printer parser in the locale package -> https://js-joda.github.io/js-joda/file/packages/locale/src/format/cldr/CldrZoneTextPrinterParser.js.html

@phueper
Copy link
Member

phueper commented Oct 15, 2021

@pithu i looked a little bit into this ... i believe the problem here is missing support for ZoneRules.isDaylightSavings(),
see this TODO comment https://github.com/js-joda/js-joda/blob/master/packages/locale/src/format/cldr/CldrZoneTextPrinterParser.js#L135
and https://github.com/js-joda/js-joda/blob/master/packages/timezone/src/MomentZoneRules.js#L262

not sure how much effort that would be, i remember, that we talked about this in the past and that it is somehow hard to figure out from the moment data? But i might be wrong here...

@pithu
Copy link
Member

pithu commented Oct 16, 2021

Ok, then that would probably mean that we have to fork the moment-timezone grunt tasks and add the daylight saving information to the packed format. I am not sure how much effort that would be, an entry point to understand how its working might be this HowTo i recently added https://github.com/pithu/js-joda/blob/c954cd5991b90ee5e02d4cd92eaddca379de7821/packages/timezone/HowToUpdateTZDB.md

@phueper
Copy link
Member

phueper commented Oct 16, 2021

ok ... i'll give it a try ...

@phueper
Copy link
Member

phueper commented Oct 25, 2021

fwiw ... some first attempts to get DST info into the timezone packed format are here https://github.com/js-joda/moment-timezone in a clone of moment-timezone

@pithu
Copy link
Member

pithu commented Oct 25, 2021

LGTM. What about a PR in js-joda/moment-timezone ?

@phueper
Copy link
Member

phueper commented Nov 5, 2021

first step ... PR in js-joda/moment-timezone js-joda/moment-timezone#2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants