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

Parsing ISO week date incorrect for some years #1626

Closed
mrkjhnstn opened this issue Apr 27, 2014 · 1 comment
Closed

Parsing ISO week date incorrect for some years #1626

mrkjhnstn opened this issue Apr 27, 2014 · 1 comment

Comments

@mrkjhnstn
Copy link

There appears to be a bug in ISO year-week parsing for some years: 2012 is an example:

var x = moment.utc('2012-W01');

This parses 1 week earlier than it should, and formats as follows:

x.format("GGGG-[W]WW")  -> '2011-W52'

but the correct string should be '2012-W01', same as input.

Here is the moment object:

{ _isAMomentObject: true,
  _useUTC: true,
  _isUTC: true,
  _l: undefined,
  _i: '2012-W01',
  _f: 'GGGG-[W]WW ',
  _strict: undefined,
  _pf: 
   { empty: false,
     unusedTokens: [],
     unusedInput: [],
     overflow: -1,
     charsLeftOver: 0,
     nullInput: false,
     invalidMonth: null,
     invalidFormat: false,
     userInvalidated: false,
     iso: true },
  _a: 
   [ 2011, 11, 26, 0, 0, 0, 0 ],
  _w: { GG: '2012', W: '01' },
  _dayOfYear: 360,
  _d: Sun Dec 25 2011 16:00:00 GMT-0800 (PST),
  _offset: 0 }

Looking over a range of years 2000 to 2020, this happens only for 3 years:

var yr;
for (yr = 2000; yr < 2021; ++yr) {
    var strIn = yr.toString() + '-W01';
    var strOut = moment.utc(strIn).format('GGGG-[W]WW');
    var same = (strIn == strOut);
    if (!same) {
        console.log(strIn + ' differs from formatted version ' + strOut);
    }
}

produces:

2006-W01 differs from formatted version 2005-W52
2012-W01 differs from formatted version 2011-W52
2017-W01 differs from formatted version 2016-W52
@ichernev
Copy link
Contributor

ichernev commented May 7, 2014

@mrkjhnstn thank you for the report. It was really helpful in finding and fixing the bug.

@ichernev ichernev closed this as completed May 7, 2014
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

2 participants