{"action":"created","issue":{"url":"https://api.github.com/repos/CounterMarch/moment.cfc/issues/5","labels_url":"https://api.github.com/repos/CounterMarch/moment.cfc/issues/5/labels{/name}","comments_url":"https://api.github.com/repos/CounterMarch/moment.cfc/issues/5/comments","events_url":"https://api.github.com/repos/CounterMarch/moment.cfc/issues/5/events","html_url":"https://github.com/CounterMarch/moment.cfc/issues/5","id":63831819,"number":5,"title":"DST issue in UTCtoTZ() and TZtoUTC()","user":{"login":"dswitzer","id":900497,"avatar_url":"https://avatars.githubusercontent.com/u/900497?v=3","gravatar_id":"","url":"https://api.github.com/users/dswitzer","html_url":"https://github.com/dswitzer","followers_url":"https://api.github.com/users/dswitzer/followers","following_url":"https://api.github.com/users/dswitzer/following{/other_user}","gists_url":"https://api.github.com/users/dswitzer/gists{/gist_id}","starred_url":"https://api.github.com/users/dswitzer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dswitzer/subscriptions","organizations_url":"https://api.github.com/users/dswitzer/orgs","repos_url":"https://api.github.com/users/dswitzer/repos","events_url":"https://api.github.com/users/dswitzer/events{/privacy}","received_events_url":"https://api.github.com/users/dswitzer/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-03-23T21:03:23Z","updated_at":"2015-03-23T21:27:56Z","closed_at":null,"body":"There's an issue when converting times from local to UTC and vice versa. The issue is when you get the offset, you get the offset based upon the current time stamp. \r\n\r\nFor example, if you were to UTCtoTZ(\"2015-02-01 05:00:00\", \"America/New_York\"), you should get midnight. However, if you run the code today, the offset is going to be -4, instead of -5. This is because you're getting the current timestamp for the offset.\r\n\r\nTo resolve the problem, you need to feed the offset in the date/time of what you're converting.\r\n\r\nHere's a sample of the logic I've used in the past when converting local to UTC:\r\n\r\n```\r\n// get the milliseconds from epoch of the supplied date/time\r\nvar ms = timezone.getOffset( javacast(\"long\", dateDiff(\"s\", createDateTime(1970, 1, 1, 0, 0, 0), arguments.time)) )*1000;\r\n```\r\nThis would get the seconds from Epoch of the time that you supplied, so you're getting the correct offset based on the time you supplied."},"comment":{"url":"https://api.github.com/repos/CounterMarch/moment.cfc/issues/comments/85205394","html_url":"https://github.com/CounterMarch/moment.cfc/issues/5#issuecomment-85205394","issue_url":"https://api.github.com/repos/CounterMarch/moment.cfc/issues/5","id":85205394,"user":{"login":"atuttle","id":46990,"avatar_url":"https://avatars.githubusercontent.com/u/46990?v=3","gravatar_id":"","url":"https://api.github.com/users/atuttle","html_url":"https://github.com/atuttle","followers_url":"https://api.github.com/users/atuttle/followers","following_url":"https://api.github.com/users/atuttle/following{/other_user}","gists_url":"https://api.github.com/users/atuttle/gists{/gist_id}","starred_url":"https://api.github.com/users/atuttle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/atuttle/subscriptions","organizations_url":"https://api.github.com/users/atuttle/orgs","repos_url":"https://api.github.com/users/atuttle/repos","events_url":"https://api.github.com/users/atuttle/events{/privacy}","received_events_url":"https://api.github.com/users/atuttle/received_events","type":"User","site_admin":false},"created_at":"2015-03-23T21:27:56Z","updated_at":"2015-03-23T21:27:56Z","body":"I have what I think is a good test. Validate it for me?\r\n\r\n\tit(\"returns the offset in seconds (considering DST) of the specified zone\", function(){\r\n\t\tvar offset4h = -4*60*60;\r\n\t\tvar offset5h = -5*60*60;\r\n\r\n\t\t// America/New_York is either -5 or -4 depending on DST (at time of writing :P)\r\n\t\tvar m = moment( now(), 'America/New_York' );\r\n\t\tvar expectedOffset = m.isDST() ? offset4h : offset5h;\r\n\r\n\t\texpect( m.getZoneOffset( 'America/New_York' ) ).toBe( expectedOffset );\r\n\r\n\t\tdebug( expectedOffset, 'expected' );\r\n\t\tdebug( m.getZoneOffset( 'America/New_York' ), 'actual' );\r\n\r\n\t\tdebug( m.getDateTime(), 'before-convert' );\r\n\t\tdebug( m.utc().getDateTime(), 'after-convert' );\r\n\t});\r\n\r\nNotice that I'm also debug-logging the before/after of a conversion to UTC. Based on that logging, I believe it's currently working as intended. I'm getting 3/23 17:25 local, 3/23 21:25 UTC, which matches http://www.worldtimeserver.com/current_time_in_UTC.aspx"}}