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

parseDate fails on Turkish full datetime with Monday or Saturday #690

Closed
dwbruhn opened this Issue Feb 16, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@dwbruhn

dwbruhn commented Feb 16, 2017

Hi @rxaviers, parseDate appears to have a bug in parsing Turkish full datetime strings when it's a Monday ('"Pazartesi") or Saturday ("Cumartesi").

My environment:

  • OS X El Capitan
  • Node 4.7.0
  • America/Los_Angeles

Here's a Node script demonstrating the problem:

"use strict";

let Globalize = require("globalize");

Globalize.load(
    require("cldr-data/main/tr/ca-gregorian"),
    require("cldr-data/main/tr/dateFields"),
    require("cldr-data/main/tr/timeZoneNames"),
    require("cldr-data/main/tr/numbers"),
    require("cldr-data/supplemental/likelySubtags"),
    require("cldr-data/supplemental/timeData"),
    require("cldr-data/supplemental/weekData"));

Globalize.locale("tr");

let options = { datetime: "full" };

for (var i = 0; i < 366; i++) {
    let date = new Date(2015, 0, i); // loop over all dates in the year

    let dateFormatted = Globalize.formatDate(date, options);

    let dateParsed = Globalize.parseDate(dateFormatted, options);

    // if parse result is null, log the date and the formatted output
    if (!dateParsed) {
        console.log(date, dateFormatted);
    }
}

Output:

Sat Jan 03 2015 00:00:00 GMT-0800 (PST) '3 Ocak 2015 Cumartesi 00:00:00 GMT-08:00'
Mon Jan 05 2015 00:00:00 GMT-0800 (PST) '5 Ocak 2015 Pazartesi 00:00:00 GMT-08:00'
Sat Jan 10 2015 00:00:00 GMT-0800 (PST) '10 Ocak 2015 Cumartesi 00:00:00 GMT-08:00'
Mon Jan 12 2015 00:00:00 GMT-0800 (PST) '12 Ocak 2015 Pazartesi 00:00:00 GMT-08:00'
Sat Jan 17 2015 00:00:00 GMT-0800 (PST) '17 Ocak 2015 Cumartesi 00:00:00 GMT-08:00'
Mon Jan 19 2015 00:00:00 GMT-0800 (PST) '19 Ocak 2015 Pazartesi 00:00:00 GMT-08:00'
Sat Jan 24 2015 00:00:00 GMT-0800 (PST) '24 Ocak 2015 Cumartesi 00:00:00 GMT-08:00'
Mon Jan 26 2015 00:00:00 GMT-0800 (PST) '26 Ocak 2015 Pazartesi 00:00:00 GMT-08:00'
Sat Jan 31 2015 00:00:00 GMT-0800 (PST) '31 Ocak 2015 Cumartesi 00:00:00 GMT-08:00'
Mon Feb 02 2015 00:00:00 GMT-0800 (PST) '2 Şubat 2015 Pazartesi 00:00:00 GMT-08:00'
Sat Feb 07 2015 00:00:00 GMT-0800 (PST) '7 Şubat 2015 Cumartesi 00:00:00 GMT-08:00'
Mon Feb 09 2015 00:00:00 GMT-0800 (PST) '9 Şubat 2015 Pazartesi 00:00:00 GMT-08:00'
Sat Feb 14 2015 00:00:00 GMT-0800 (PST) '14 Şubat 2015 Cumartesi 00:00:00 GMT-08:00'
Mon Feb 16 2015 00:00:00 GMT-0800 (PST) '16 Şubat 2015 Pazartesi 00:00:00 GMT-08:00'
Sat Feb 21 2015 00:00:00 GMT-0800 (PST) '21 Şubat 2015 Cumartesi 00:00:00 GMT-08:00'
Mon Feb 23 2015 00:00:00 GMT-0800 (PST) '23 Şubat 2015 Pazartesi 00:00:00 GMT-08:00'
Sat Feb 28 2015 00:00:00 GMT-0800 (PST) '28 Şubat 2015 Cumartesi 00:00:00 GMT-08:00'
Mon Mar 02 2015 00:00:00 GMT-0800 (PST) '2 Mart 2015 Pazartesi 00:00:00 GMT-08:00'
Sat Mar 07 2015 00:00:00 GMT-0800 (PST) '7 Mart 2015 Cumartesi 00:00:00 GMT-08:00'
Mon Mar 09 2015 00:00:00 GMT-0700 (PDT) '9 Mart 2015 Pazartesi 00:00:00 GMT-07:00'
Sat Mar 14 2015 00:00:00 GMT-0700 (PDT) '14 Mart 2015 Cumartesi 00:00:00 GMT-07:00'
Mon Mar 16 2015 00:00:00 GMT-0700 (PDT) '16 Mart 2015 Pazartesi 00:00:00 GMT-07:00'
Sat Mar 21 2015 00:00:00 GMT-0700 (PDT) '21 Mart 2015 Cumartesi 00:00:00 GMT-07:00'
Mon Mar 23 2015 00:00:00 GMT-0700 (PDT) '23 Mart 2015 Pazartesi 00:00:00 GMT-07:00'
Sat Mar 28 2015 00:00:00 GMT-0700 (PDT) '28 Mart 2015 Cumartesi 00:00:00 GMT-07:00'
Mon Mar 30 2015 00:00:00 GMT-0700 (PDT) '30 Mart 2015 Pazartesi 00:00:00 GMT-07:00'
Sat Apr 04 2015 00:00:00 GMT-0700 (PDT) '4 Nisan 2015 Cumartesi 00:00:00 GMT-07:00'
Mon Apr 06 2015 00:00:00 GMT-0700 (PDT) '6 Nisan 2015 Pazartesi 00:00:00 GMT-07:00'
Sat Apr 11 2015 00:00:00 GMT-0700 (PDT) '11 Nisan 2015 Cumartesi 00:00:00 GMT-07:00'
Mon Apr 13 2015 00:00:00 GMT-0700 (PDT) '13 Nisan 2015 Pazartesi 00:00:00 GMT-07:00'
Sat Apr 18 2015 00:00:00 GMT-0700 (PDT) '18 Nisan 2015 Cumartesi 00:00:00 GMT-07:00'
Mon Apr 20 2015 00:00:00 GMT-0700 (PDT) '20 Nisan 2015 Pazartesi 00:00:00 GMT-07:00'
Sat Apr 25 2015 00:00:00 GMT-0700 (PDT) '25 Nisan 2015 Cumartesi 00:00:00 GMT-07:00'
Mon Apr 27 2015 00:00:00 GMT-0700 (PDT) '27 Nisan 2015 Pazartesi 00:00:00 GMT-07:00'
Sat May 02 2015 00:00:00 GMT-0700 (PDT) '2 Mayıs 2015 Cumartesi 00:00:00 GMT-07:00'
Mon May 04 2015 00:00:00 GMT-0700 (PDT) '4 Mayıs 2015 Pazartesi 00:00:00 GMT-07:00'
Sat May 09 2015 00:00:00 GMT-0700 (PDT) '9 Mayıs 2015 Cumartesi 00:00:00 GMT-07:00'
Mon May 11 2015 00:00:00 GMT-0700 (PDT) '11 Mayıs 2015 Pazartesi 00:00:00 GMT-07:00'
Sat May 16 2015 00:00:00 GMT-0700 (PDT) '16 Mayıs 2015 Cumartesi 00:00:00 GMT-07:00'
Mon May 18 2015 00:00:00 GMT-0700 (PDT) '18 Mayıs 2015 Pazartesi 00:00:00 GMT-07:00'
Sat May 23 2015 00:00:00 GMT-0700 (PDT) '23 Mayıs 2015 Cumartesi 00:00:00 GMT-07:00'
Mon May 25 2015 00:00:00 GMT-0700 (PDT) '25 Mayıs 2015 Pazartesi 00:00:00 GMT-07:00'
Sat May 30 2015 00:00:00 GMT-0700 (PDT) '30 Mayıs 2015 Cumartesi 00:00:00 GMT-07:00'
Mon Jun 01 2015 00:00:00 GMT-0700 (PDT) '1 Haziran 2015 Pazartesi 00:00:00 GMT-07:00'
Sat Jun 06 2015 00:00:00 GMT-0700 (PDT) '6 Haziran 2015 Cumartesi 00:00:00 GMT-07:00'
Mon Jun 08 2015 00:00:00 GMT-0700 (PDT) '8 Haziran 2015 Pazartesi 00:00:00 GMT-07:00'
Sat Jun 13 2015 00:00:00 GMT-0700 (PDT) '13 Haziran 2015 Cumartesi 00:00:00 GMT-07:00'
Mon Jun 15 2015 00:00:00 GMT-0700 (PDT) '15 Haziran 2015 Pazartesi 00:00:00 GMT-07:00'
Sat Jun 20 2015 00:00:00 GMT-0700 (PDT) '20 Haziran 2015 Cumartesi 00:00:00 GMT-07:00'
Mon Jun 22 2015 00:00:00 GMT-0700 (PDT) '22 Haziran 2015 Pazartesi 00:00:00 GMT-07:00'
Sat Jun 27 2015 00:00:00 GMT-0700 (PDT) '27 Haziran 2015 Cumartesi 00:00:00 GMT-07:00'
Mon Jun 29 2015 00:00:00 GMT-0700 (PDT) '29 Haziran 2015 Pazartesi 00:00:00 GMT-07:00'
Sat Jul 04 2015 00:00:00 GMT-0700 (PDT) '4 Temmuz 2015 Cumartesi 00:00:00 GMT-07:00'
Mon Jul 06 2015 00:00:00 GMT-0700 (PDT) '6 Temmuz 2015 Pazartesi 00:00:00 GMT-07:00'
Sat Jul 11 2015 00:00:00 GMT-0700 (PDT) '11 Temmuz 2015 Cumartesi 00:00:00 GMT-07:00'
Mon Jul 13 2015 00:00:00 GMT-0700 (PDT) '13 Temmuz 2015 Pazartesi 00:00:00 GMT-07:00'
Sat Jul 18 2015 00:00:00 GMT-0700 (PDT) '18 Temmuz 2015 Cumartesi 00:00:00 GMT-07:00'
Mon Jul 20 2015 00:00:00 GMT-0700 (PDT) '20 Temmuz 2015 Pazartesi 00:00:00 GMT-07:00'
Sat Jul 25 2015 00:00:00 GMT-0700 (PDT) '25 Temmuz 2015 Cumartesi 00:00:00 GMT-07:00'
Mon Jul 27 2015 00:00:00 GMT-0700 (PDT) '27 Temmuz 2015 Pazartesi 00:00:00 GMT-07:00'
Sat Aug 01 2015 00:00:00 GMT-0700 (PDT) '1 Ağustos 2015 Cumartesi 00:00:00 GMT-07:00'
Mon Aug 03 2015 00:00:00 GMT-0700 (PDT) '3 Ağustos 2015 Pazartesi 00:00:00 GMT-07:00'
Sat Aug 08 2015 00:00:00 GMT-0700 (PDT) '8 Ağustos 2015 Cumartesi 00:00:00 GMT-07:00'
Mon Aug 10 2015 00:00:00 GMT-0700 (PDT) '10 Ağustos 2015 Pazartesi 00:00:00 GMT-07:00'
Sat Aug 15 2015 00:00:00 GMT-0700 (PDT) '15 Ağustos 2015 Cumartesi 00:00:00 GMT-07:00'
Mon Aug 17 2015 00:00:00 GMT-0700 (PDT) '17 Ağustos 2015 Pazartesi 00:00:00 GMT-07:00'
Sat Aug 22 2015 00:00:00 GMT-0700 (PDT) '22 Ağustos 2015 Cumartesi 00:00:00 GMT-07:00'
Mon Aug 24 2015 00:00:00 GMT-0700 (PDT) '24 Ağustos 2015 Pazartesi 00:00:00 GMT-07:00'
Sat Aug 29 2015 00:00:00 GMT-0700 (PDT) '29 Ağustos 2015 Cumartesi 00:00:00 GMT-07:00'
Mon Aug 31 2015 00:00:00 GMT-0700 (PDT) '31 Ağustos 2015 Pazartesi 00:00:00 GMT-07:00'
Sat Sep 05 2015 00:00:00 GMT-0700 (PDT) '5 Eylül 2015 Cumartesi 00:00:00 GMT-07:00'
Mon Sep 07 2015 00:00:00 GMT-0700 (PDT) '7 Eylül 2015 Pazartesi 00:00:00 GMT-07:00'
Sat Sep 12 2015 00:00:00 GMT-0700 (PDT) '12 Eylül 2015 Cumartesi 00:00:00 GMT-07:00'
Mon Sep 14 2015 00:00:00 GMT-0700 (PDT) '14 Eylül 2015 Pazartesi 00:00:00 GMT-07:00'
Sat Sep 19 2015 00:00:00 GMT-0700 (PDT) '19 Eylül 2015 Cumartesi 00:00:00 GMT-07:00'
Mon Sep 21 2015 00:00:00 GMT-0700 (PDT) '21 Eylül 2015 Pazartesi 00:00:00 GMT-07:00'
Sat Sep 26 2015 00:00:00 GMT-0700 (PDT) '26 Eylül 2015 Cumartesi 00:00:00 GMT-07:00'
Mon Sep 28 2015 00:00:00 GMT-0700 (PDT) '28 Eylül 2015 Pazartesi 00:00:00 GMT-07:00'
Sat Oct 03 2015 00:00:00 GMT-0700 (PDT) '3 Ekim 2015 Cumartesi 00:00:00 GMT-07:00'
Mon Oct 05 2015 00:00:00 GMT-0700 (PDT) '5 Ekim 2015 Pazartesi 00:00:00 GMT-07:00'
Sat Oct 10 2015 00:00:00 GMT-0700 (PDT) '10 Ekim 2015 Cumartesi 00:00:00 GMT-07:00'
Mon Oct 12 2015 00:00:00 GMT-0700 (PDT) '12 Ekim 2015 Pazartesi 00:00:00 GMT-07:00'
Sat Oct 17 2015 00:00:00 GMT-0700 (PDT) '17 Ekim 2015 Cumartesi 00:00:00 GMT-07:00'
Mon Oct 19 2015 00:00:00 GMT-0700 (PDT) '19 Ekim 2015 Pazartesi 00:00:00 GMT-07:00'
Sat Oct 24 2015 00:00:00 GMT-0700 (PDT) '24 Ekim 2015 Cumartesi 00:00:00 GMT-07:00'
Mon Oct 26 2015 00:00:00 GMT-0700 (PDT) '26 Ekim 2015 Pazartesi 00:00:00 GMT-07:00'
Sat Oct 31 2015 00:00:00 GMT-0700 (PDT) '31 Ekim 2015 Cumartesi 00:00:00 GMT-07:00'
Mon Nov 02 2015 00:00:00 GMT-0800 (PST) '2 Kasım 2015 Pazartesi 00:00:00 GMT-08:00'
Sat Nov 07 2015 00:00:00 GMT-0800 (PST) '7 Kasım 2015 Cumartesi 00:00:00 GMT-08:00'
Mon Nov 09 2015 00:00:00 GMT-0800 (PST) '9 Kasım 2015 Pazartesi 00:00:00 GMT-08:00'
Sat Nov 14 2015 00:00:00 GMT-0800 (PST) '14 Kasım 2015 Cumartesi 00:00:00 GMT-08:00'
Mon Nov 16 2015 00:00:00 GMT-0800 (PST) '16 Kasım 2015 Pazartesi 00:00:00 GMT-08:00'
Sat Nov 21 2015 00:00:00 GMT-0800 (PST) '21 Kasım 2015 Cumartesi 00:00:00 GMT-08:00'
Mon Nov 23 2015 00:00:00 GMT-0800 (PST) '23 Kasım 2015 Pazartesi 00:00:00 GMT-08:00'
Sat Nov 28 2015 00:00:00 GMT-0800 (PST) '28 Kasım 2015 Cumartesi 00:00:00 GMT-08:00'
Mon Nov 30 2015 00:00:00 GMT-0800 (PST) '30 Kasım 2015 Pazartesi 00:00:00 GMT-08:00'
Sat Dec 05 2015 00:00:00 GMT-0800 (PST) '5 Aralık 2015 Cumartesi 00:00:00 GMT-08:00'
Mon Dec 07 2015 00:00:00 GMT-0800 (PST) '7 Aralık 2015 Pazartesi 00:00:00 GMT-08:00'
Sat Dec 12 2015 00:00:00 GMT-0800 (PST) '12 Aralık 2015 Cumartesi 00:00:00 GMT-08:00'
Mon Dec 14 2015 00:00:00 GMT-0800 (PST) '14 Aralık 2015 Pazartesi 00:00:00 GMT-08:00'
Sat Dec 19 2015 00:00:00 GMT-0800 (PST) '19 Aralık 2015 Cumartesi 00:00:00 GMT-08:00'
Mon Dec 21 2015 00:00:00 GMT-0800 (PST) '21 Aralık 2015 Pazartesi 00:00:00 GMT-08:00'
Sat Dec 26 2015 00:00:00 GMT-0800 (PST) '26 Aralık 2015 Cumartesi 00:00:00 GMT-08:00'
Mon Dec 28 2015 00:00:00 GMT-0800 (PST) '28 Aralık 2015 Pazartesi 00:00:00 GMT-08:00'

Just a hunch: Turkish "Monday" and "Saturday" are the only days of the week with dotted i. I know the Turkish i casing issues can be tricky, so that may be a potential lead.

@rxaviers

This comment has been minimized.

Show comment
Hide comment
@rxaviers

rxaviers Feb 16, 2017

Member

Interesting... Thanks!

Member

rxaviers commented Feb 16, 2017

Interesting... Thanks!

@rxaviers

This comment has been minimized.

Show comment
Hide comment
@rxaviers

rxaviers Feb 21, 2017

Member

The root cause is that the parser lookup finds Cuma (Fri) before it finds Cumartesi (Sat), similarly it finds Pazar (Sun) before it finds Pazartesi (Mon), and therefore the token doesn't entirely consume the input.

Member

rxaviers commented Feb 21, 2017

The root cause is that the parser lookup finds Cuma (Fri) before it finds Cumartesi (Sat), similarly it finds Pazar (Sun) before it finds Pazartesi (Mon), and therefore the token doesn't entirely consume the input.

@rxaviers rxaviers added the patch label Feb 24, 2017

@rxaviers rxaviers removed the patch label Mar 13, 2017

@rxaviers rxaviers added this to the 1.3.0 milestone Mar 17, 2017

rxaviers added a commit to rxaviers/globalize that referenced this issue May 23, 2017

Date: Fix parser lookup (use descending order)
parseDate fails on Turkish full datetime with Monday or Saturday.

The root cause is that the parser lookup finds Cuma (Fri) before it
finds Cumartesi (Sat), similarly it finds Pazar (Sun) before it finds
Pazartesi (Mon), and therefore the token doesn't entirely consume the
input.

The fix approach is to start the lookup with longer names, then the
shorter ones.

Fixes #690

rxaviers added a commit to rxaviers/globalize that referenced this issue May 23, 2017

Date: Fix parser lookup (use descending order)
parseDate fails on Turkish full datetime with Monday or Saturday.

The root cause is that the parser lookup finds Cuma (Fri) before it
finds Cumartesi (Sat), similarly it finds Pazar (Sun) before it finds
Pazartesi (Mon), and therefore the token doesn't entirely consume the
input.

The fix approach is to start the lookup with longer names, then the
shorter ones.

Fixes #690

@rxaviers rxaviers closed this in #732 May 23, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment