moment / luxon

⏱ A library for working with dates and times in JS
https://moment.github.io/luxon
MIT License
15.23k stars 730 forks source link

U+20 vs U+202f space between time and meridian when using 'DATETIME_SHORT' #1439

Closed JasonFoglia closed 1 year ago

JasonFoglia commented 1 year ago

With code below the format of the output toLocalString has a Unicode Character white space between the time and meridian which is not consistent with the white space between the date and time.

`

static formatDate(value: DateTime | Date, format: string): string {

    let dateTimeToUse: DateTime;

    if (value instanceof Date) {
      dateTimeToUse = DateTime.fromJSDate(value);
    } else {
      dateTimeToUse = value;
    }

    return dateTimeToUse.toLocaleString((<any>DateTime)[format]);
}

`

Using these dates: const dateToFormat = '2023-05-22T12:00:00Z'; const expectedDate = '5/22/2023, 12:00 PM'; const actualDate = '5/22/2023, 12:00 PM';

This breaks tests using Jasmine.

I've only tested with 'DATETIME_SHORT' formatter and no others.

diesieben07 commented 1 year ago

The output of toLocaleString depends on the underlying platform as it uses Intl.DateTimeFormat. The output is not guaranteed to be the same or consistent.