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

Add lowercase am/pm marker #188

Open
abhishekamit opened this issue Aug 21, 2018 · 9 comments
Open

Add lowercase am/pm marker #188

abhishekamit opened this issue Aug 21, 2018 · 9 comments
Labels
P4 A feature or bug we're unlikely to address package:intl type-enhancement A request for a change that isn't a bug

Comments

@abhishekamit
Copy link

It'd be helpful to have a character that will print "am" or "pm" instead of "AM" or "PM".

libc seems to support this with %p vs %P: http://www.gnu.org/software/libc/manual/html_node/Formatting-Calendar-Time.html.

Currently I'm doing DateFormat('h:mm a').format(eventTime).toLowerCase() to get this result, but that's not ideal.

@SteveAlexander
Copy link

I'm seeing the same thing.

I have a proposal for a syntax for this, however I realize that this would be a breaking change.

The proposal is to make the case of 'am/pm' follow the case of the DateFormat syntax used. So, 'a' would indicate 'am' or 'pm' and 'A' would indicate 'AM' or 'PM'. Right now, 'a' indicates 'AM' or 'PM', which is not so intuitive.

DateFormat('h:mm a').format(eventTime) format as "12:34 am"
DateFormat('h:mm A').format(eventTime) format as "12:34 AM"

As of now, only the lower-case 'a' DateFormat('h:mm a').format(eventTime) works, and formats (in my experience, counterintuitively) as upper case 'AM' or 'PM'.

@alan-knight
Copy link
Contributor

We're following the ICU patterns - http://userguide.icu-project.org/formatparse/datetime#TOC-Date-Time-Format-Syntax so I'd be reluctant to deviate from that. And they use 'A' already for something else. But also, it's hard to know how to interpret that in other locales. If you ask for upper, do you want e.g. DOP. and ODP. in Czech?

@vallamost
Copy link

What if you added an alias of 'aa' for lowercase, and AA for uppercase?

@sajadj313
Copy link

Any update on this issue? Its still existing to date.

As a workaround, I replace all the "am/pm" with "AM/PM" and do the parsing but a dedicated time format for this would come in handy.

Thanks.

@apparaopapi88
Copy link

We're following the ICU patterns - http://userguide.icu-project.org/formatparse/datetime#TOC-Date-Time-Format-Syntax so I'd be reluctant to deviate from that. And they use 'A' already for something else. But also, it's hard to know how to interpret that in other locales. If you ask for upper, do you want e.g. DOP. and ODP. in Czech?

How about format symbols for entire application?
Like in Java?
DateFormatSymbols.amPmStrings
SimpleDateFormat.dateFormatSymbols

@syntheticgoo
Copy link

@mosuem
Copy link
Member

mosuem commented Oct 19, 2022

I agree that adding a character for lowercase/uppercase does not sound great - being able to override the am/pm strings for a given locale sounds like a better solution at first thought at least.

@mosuem mosuem added type-enhancement A request for a change that isn't a bug P3 A lower priority bug or feature request labels Oct 19, 2022
@mosuem
Copy link
Member

mosuem commented Oct 19, 2022

Currently, this is possible but a bit contrived:

import 'package:intl/date_symbol_data_custom.dart';
import 'package:intl/date_symbol_data_local.dart';
import 'package:intl/date_symbols.dart';
import 'package:intl/date_time_patterns.dart';
import 'package:intl/intl.dart';

void main(List<String> arguments) {
  var symbols = dateTimeSymbolMap()["en_US"] as DateSymbols;
  var symbolsAsMap = symbols.serializeToMap();
  symbolsAsMap['AMPMS'] = ['am', 'pm'];
  var customSymbols = DateSymbols.deserializeFromMap(symbolsAsMap);
  var patterns = dateTimePatternMap()["en_US"];

  initializeDateFormattingCustom(
    locale: 'en_US',
    symbols: customSymbols,
    patterns: patterns,
  );

  print(DateFormat('h:mm a').format(DateTime.now()));
}

It may be worth investigating how to simplify this.

@mosuem mosuem added P4 A feature or bug we're unlikely to address and removed P3 A lower priority bug or feature request labels Oct 19, 2022
@mosuem mosuem transferred this issue from dart-archive/intl Apr 18, 2023
@stefan-sherwood
Copy link

stefan-sherwood commented Jul 13, 2023

DateFormat('h:mm a').format(eventTime)

DateFormat('h:mm a').format(eventTime).toLowerCase()

does what's being requested. It's not ideal but it works in cases where the format string doesn't include Month or Day of Week, such as the given example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P4 A feature or bug we're unlikely to address package:intl type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

9 participants