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

Implement DateFormat time zone formatting #386

Closed
kevmoo opened this issue Jul 23, 2015 · 13 comments
Closed

Implement DateFormat time zone formatting #386

kevmoo opened this issue Jul 23, 2015 · 13 comments

Comments

@kevmoo
Copy link
Member

kevmoo commented Jul 23, 2015

From @ajsergeev on July 21, 2015 8:28

v,z patterns don't work because:

String formatTimeZoneId(DateTime date) {
// TODO(alanknight): implement time zone support
throw new UnimplementedError();
}

String formatTimeZone(DateTime date) {
throw new UnimplementedError();
}

String formatTimeZoneRFC(DateTime date) {
throw new UnimplementedError();
}

Copied from original issue: dart-lang/sdk#23879

@alan-knight
Copy link
Contributor

Duplicate of #330

We don't expect to implement those until Dart DateTime's have time zone information, and that's not planned. I wouldn't expect it unless/until JavaScript DateTime's have them. Including localized TimeZone names is a lot of data. We should probably just remove those APIs until such time as we actually provide them.

@pedzed
Copy link

pedzed commented Aug 15, 2018

@alan-knight Any updates on this? I am using Flutter and I cannot find any information about timezone formatting. I can only find information for localization.

This is a blocker for my app. Perhaps I can temporarily hardcode +2 hours (CEST), but that's far from ideal for obvious reasons.

@alan-knight
Copy link
Contributor

Dart DateTime's do not have time zone information, so no, there isn't much you can do with that. I saw a reference recently to a "Time machine" package which was a port of Joda time to Dart and did include times with time zones. It's possible that would work for you. The only other obvious thing is to get time zone information from the operating system directly.

@pedzed
Copy link

pedzed commented Aug 15, 2018

Thanks for the pointer to https://pub.dartlang.org/packages/time_machine. I will check it out.

Dart DateTime's do not have time zone information

I am adding the offset when parsing:

DateTime.parse('2018-01-01 12:00:00 +0200')

Can't it be read with DateFormat or something?

I'm sorry. I know that dates are extremely complex, but at the moment this is feels like half work. Dart 2 is released (:tada:), but DateTime still gives some unimplemented exceptions (Never mind, I am probably confusing it with DateFormat).

@pedzed
Copy link

pedzed commented Aug 18, 2018

I have tried Time Machine, but it is really frustrating that it is lacking (good) documentation.

Either way, I think such an important feature should be supported by the Dart team. What is the reason it is not? Lack of resources or something technical?

The only other obvious thing is to get time zone information from the operating system directly.

I don't mind trying that. Do you have any pointers for me?

@duzenko
Copy link

duzenko commented May 24, 2019

Dart DateTime's do not have time zone information, so no, there isn't much you can do with that. I saw a reference recently to a "Time machine" package which was a port of Joda time to Dart and did include times with time zones. It's possible that would work for you. The only other obvious thing is to get time zone information from the operating system directly.

https://api.dartlang.org/stable/2.3.1/dart-core/DateTime/timeZoneOffset.html

    final formatter = DateFormat('dd.MM.yyyy-HH:mm:ss.ZZ');
    final ytd = DateTime.now().add(Duration(days: -365));
    print(ytd.timeZoneOffset);
    final startDate = formatter.format(ytd); 
I/flutter (26245): 3:00:00.000000
I/flutter (26245): UnimplementedError

@alan-knight
Copy link
Contributor

There is a time zone offset, it is effectively global. So DateTime instances can be either in UTC or in the local time. We can get the offset from UTC, but that does not uniquely determine the time zone, and we do not have data included for time zone names. That could be included, but it increases the data size and is not currently planned. We are more likely to delegate this to JS Intl (on web) or to ICU/operating system facilities (on mobile) going forward, rather than adding more subsets of data.

@duzenko
Copy link

duzenko commented May 25, 2019

You can still format the timezone, regardless if it's local or global.
If the DT instance is 'local time' then use its time zone.
If it's 'UTC time', use the GMT zone.
Sorry, I don't see the problem. What data exactly do you need for this?

@amugofjava
Copy link

amugofjava commented Jun 10, 2019

DateTime will parse standard ISO dates. If you need custom formatting, there is DateFormat (as highlighted above). The documentation suggests that you can use timezone fields when parsing - such as 'z', but in fact the timezone handling methods within date_format_field.dart throws an UnimplementedError() exception. This means parsing dates in RFC2822 format is not possible.

@duzenko
Copy link

duzenko commented Jun 10, 2019

DateTime will parse standard ISO dates. If you need custom formatting, there is DateFormat (as highlighted above). The documentation suggests that you can use timezone fields when parsing - such as 'z', but in fact the timezone handling methods within date_format_field.dart throws an UnimplementedError() exception. This means parsing dates in RFC2822 format is not possible.

This issue is about formatting, not parsing.
It's still possible to parse any zone date, it just will need conversion to local/utc zone.

@jamesderlin
Copy link
Contributor

Is this different from #330?

@duzenko
Copy link

duzenko commented Aug 11, 2020

Is this different from #330?

Not unless formatting and parsing are the same thing

@mosuem
Copy link
Member

mosuem commented Oct 21, 2022

Closing in favor of #330 .

@mosuem mosuem closed this as not planned Won't fix, can't repro, duplicate, stale Oct 21, 2022
@mosuem mosuem transferred this issue from dart-archive/intl Apr 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants