{"action":"created","issue":{"url":"https://api.github.com/repos/moment/moment/issues/4584","repository_url":"https://api.github.com/repos/moment/moment","labels_url":"https://api.github.com/repos/moment/moment/issues/4584/labels{/name}","comments_url":"https://api.github.com/repos/moment/moment/issues/4584/comments","events_url":"https://api.github.com/repos/moment/moment/issues/4584/events","html_url":"https://github.com/moment/moment/issues/4584","id":316755362,"number":4584,"title":"Facing issues while using duration and diff methods","user":{"login":"GopiKrishna87","id":19469733,"avatar_url":"https://avatars1.githubusercontent.com/u/19469733?v=4","gravatar_id":"","url":"https://api.github.com/users/GopiKrishna87","html_url":"https://github.com/GopiKrishna87","followers_url":"https://api.github.com/users/GopiKrishna87/followers","following_url":"https://api.github.com/users/GopiKrishna87/following{/other_user}","gists_url":"https://api.github.com/users/GopiKrishna87/gists{/gist_id}","starred_url":"https://api.github.com/users/GopiKrishna87/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GopiKrishna87/subscriptions","organizations_url":"https://api.github.com/users/GopiKrishna87/orgs","repos_url":"https://api.github.com/users/GopiKrishna87/repos","events_url":"https://api.github.com/users/GopiKrishna87/events{/privacy}","received_events_url":"https://api.github.com/users/GopiKrishna87/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2018-04-23T10:38:06Z","updated_at":"2018-04-26T19:50:28Z","closed_at":"2018-04-26T19:50:28Z","author_association":"NONE","body":"Dear Respectives,\r\n\r\nI am new to using moment js, I have a requirement where the user gives input in terms of days or months or years, and I have to convert them into years, months and days.\r\nExample:\r\nCase -1 : User inputs 1 month, and I have to calculate and show him as 0 Years 1 month 0 days, but I seeing different result with below code\r\nOR\r\nCase - 2: User input 30days and expects to convert it to 1 month because he is in the month of 30 days but I see 30 days as out put\r\n\r\nSample for Case -1\r\n```\r\nm1 = moment();\r\nm2 = moment(m1);\r\nm2.add(0, 'years').add(1, 'months').add(0, 'days');\r\nduration = moment.duration(m2.diff(m1));\r\nconsole.log(duration.years() + ', ' + duration.months() + ', '+ duration.days());\r\n```\r\n**Result -** _0, 0, 30_\r\n\r\nSample for Case - 2\r\n```\r\nm1 = moment();\r\nm2 = moment(m1);\r\nm2.add(0, 'years').add(0, 'months').add(30, 'days');\r\nduration = moment.duration(m2.diff(m1));\r\nconsole.log(duration.years() + ', ' + duration.months() + ', '+ duration.days());\r\n```\r\n**Result -** _0, 0, 30_\r\n\r\nThis I am trying in my local, even I tried executing this snippet in console of momentJs web page(where I have moment reference).\r\n\r\nAlso another case:\r\n1. If I give 365 days it is converting to 11 months 30 days, if I give 366 days it converts to 1 year, if I give 731 days it is converting to 2 years, if I give 732 days it is converting to 2 years 1 day, with these results if I give 1 year 365 days and expects 2 years as output it is giving 1 year 11 months 29/30 days.\r\n```\r\nm1 = moment();\r\nm2 = moment(m1);\r\nm2.add(1, 'years').add(0, 'months').add(365, 'days');\r\nduration = moment.duration(m2.diff(m1));\r\nconsole.log(duration.years() + ', ' + duration.months() + ', '+ duration.days());\r\n```\r\n**Result -** _1, 11, 29_\r\n\r\nHelp me, whether my understanding is not correct about moment js OR something am I missing.\r\n\r\nI am working on firefox 59.0.2, windows 10.\r\n\r\n**Environment info**\r\n\r\n_Mon Apr 23 2018 15:54:57 GMT+0530 (India Standard Time) debugger eval code:1:1\r\n4/23/2018, 3:54:57 PM debugger eval code:2:1\r\n-330 debugger eval code:3:1\r\nMozilla/5.0 (Windows NT 10.0; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0 debugger eval code:4:1\r\n2.22.1_\r\n\r\nThanks\r\nGopi Krishna."},"comment":{"url":"https://api.github.com/repos/moment/moment/issues/comments/384768112","html_url":"https://github.com/moment/moment/issues/4584#issuecomment-384768112","issue_url":"https://api.github.com/repos/moment/moment/issues/4584","id":384768112,"user":{"login":"icambron","id":244988,"avatar_url":"https://avatars3.githubusercontent.com/u/244988?v=4","gravatar_id":"","url":"https://api.github.com/users/icambron","html_url":"https://github.com/icambron","followers_url":"https://api.github.com/users/icambron/followers","following_url":"https://api.github.com/users/icambron/following{/other_user}","gists_url":"https://api.github.com/users/icambron/gists{/gist_id}","starred_url":"https://api.github.com/users/icambron/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/icambron/subscriptions","organizations_url":"https://api.github.com/users/icambron/orgs","repos_url":"https://api.github.com/users/icambron/repos","events_url":"https://api.github.com/users/icambron/events{/privacy}","received_events_url":"https://api.github.com/users/icambron/received_events","type":"User","site_admin":false},"created_at":"2018-04-26T19:50:28Z","updated_at":"2018-04-26T19:50:28Z","author_association":"OWNER","body":"Luxon durations can do this. I suggest looking there."}}
{"actor":{"display_login":"icambron"}}