{"action":"created","issue":{"url":"https://api.github.com/repos/moment/moment/issues/2372","labels_url":"https://api.github.com/repos/moment/moment/issues/2372/labels{/name}","comments_url":"https://api.github.com/repos/moment/moment/issues/2372/comments","events_url":"https://api.github.com/repos/moment/moment/issues/2372/events","html_url":"https://github.com/moment/moment/issues/2372","id":75901457,"number":2372,"title":"toJSON() and toISOString() does not handle weeks","user":{"login":"martindanielson","id":4882233,"avatar_url":"https://avatars.githubusercontent.com/u/4882233?v=3","gravatar_id":"","url":"https://api.github.com/users/martindanielson","html_url":"https://github.com/martindanielson","followers_url":"https://api.github.com/users/martindanielson/followers","following_url":"https://api.github.com/users/martindanielson/following{/other_user}","gists_url":"https://api.github.com/users/martindanielson/gists{/gist_id}","starred_url":"https://api.github.com/users/martindanielson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/martindanielson/subscriptions","organizations_url":"https://api.github.com/users/martindanielson/orgs","repos_url":"https://api.github.com/users/martindanielson/repos","events_url":"https://api.github.com/users/martindanielson/events{/privacy}","received_events_url":"https://api.github.com/users/martindanielson/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-05-13T08:34:20Z","updated_at":"2015-05-18T10:52:36Z","closed_at":null,"body":"`moment.duration('P1W').toJSON()` returns `P7D` and I would like it to return `P1W` instead. This shold be according to the ISO spec, even if I could understand that we need to set a specific setting for this.\r\n\r\nIs there a way to do this or will I have to add a rather ugly hack to accomplish this myself?"},"comment":{"url":"https://api.github.com/repos/moment/moment/issues/comments/103014868","html_url":"https://github.com/moment/moment/issues/2372#issuecomment-103014868","issue_url":"https://api.github.com/repos/moment/moment/issues/2372","id":103014868,"user":{"login":"martindanielson","id":4882233,"avatar_url":"https://avatars.githubusercontent.com/u/4882233?v=3","gravatar_id":"","url":"https://api.github.com/users/martindanielson","html_url":"https://github.com/martindanielson","followers_url":"https://api.github.com/users/martindanielson/followers","following_url":"https://api.github.com/users/martindanielson/following{/other_user}","gists_url":"https://api.github.com/users/martindanielson/gists{/gist_id}","starred_url":"https://api.github.com/users/martindanielson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/martindanielson/subscriptions","organizations_url":"https://api.github.com/users/martindanielson/orgs","repos_url":"https://api.github.com/users/martindanielson/repos","events_url":"https://api.github.com/users/martindanielson/events{/privacy}","received_events_url":"https://api.github.com/users/martindanielson/received_events","type":"User","site_admin":false},"created_at":"2015-05-18T10:52:36Z","updated_at":"2015-05-18T10:52:36Z","body":"Perhaps something like this:\r\n\r\nNeed someone who is better used to the code to verify though. I.e. I do not know if this is used for something else than durations. `weeks()` and `asWeeks()` gives me an int vs a float, which I use to determine if I should display weeks instead of days. Also, I am not really sure if you can have both W and D in there. \r\n\r\n```\r\nvar abs = Math.abs;\r\n\r\nexport function toISOString() {\r\n    // inspired by https://github.com/dordille/moment-isoduration/blob/master/moment.isoduration.js\r\n    var Y = abs(this.years());\r\n    var M = abs(this.months());\r\n    var W = (!(this.asDays() % 7) ? abs(this.asWeeks()) : 0);\r\n    var D = abs(this.days());\r\n    var h = abs(this.hours());\r\n    var m = abs(this.minutes());\r\n    var s = abs(this.seconds() + this.milliseconds() / 1000);\r\n    var total = this.asSeconds();\r\n\r\n    if (!total) {\r\n        // this is the same as C#'s (Noda) and python (isodate)...\r\n        // but not other JS (goog.date)\r\n        return 'P0D';\r\n    }\r\n\r\n    return (total < 0 ? '-' : '') +\r\n        'P' +\r\n        (Y ? Y + 'Y' : '') +\r\n        (M ? M + 'M' : '') +\r\n        (W ? W + 'W' : (D ? D + 'D' : '')) +\r\n        ((h || m || s) ? 'T' : '') +\r\n        (h ? h + 'H' : '') +\r\n        (m ? m + 'M' : '') +\r\n        (s ? s + 'S' : '');\r\n}\r\n```"}}