{"action":"created","issue":{"url":"https://api.github.com/repos/moment/luxon/issues/371","repository_url":"https://api.github.com/repos/moment/luxon","labels_url":"https://api.github.com/repos/moment/luxon/issues/371/labels{/name}","comments_url":"https://api.github.com/repos/moment/luxon/issues/371/comments","events_url":"https://api.github.com/repos/moment/luxon/issues/371/events","html_url":"https://github.com/moment/luxon/pull/371","id":382460515,"node_id":"MDExOlB1bGxSZXF1ZXN0MjMyMTY0MTUz","number":371,"title":"Add support for Unix timestamps in seconds.","user":{"login":"peterkhayes","id":3714569,"node_id":"MDQ6VXNlcjM3MTQ1Njk=","avatar_url":"https://avatars1.githubusercontent.com/u/3714569?v=4","gravatar_id":"","url":"https://api.github.com/users/peterkhayes","html_url":"https://github.com/peterkhayes","followers_url":"https://api.github.com/users/peterkhayes/followers","following_url":"https://api.github.com/users/peterkhayes/following{/other_user}","gists_url":"https://api.github.com/users/peterkhayes/gists{/gist_id}","starred_url":"https://api.github.com/users/peterkhayes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peterkhayes/subscriptions","organizations_url":"https://api.github.com/users/peterkhayes/orgs","repos_url":"https://api.github.com/users/peterkhayes/repos","events_url":"https://api.github.com/users/peterkhayes/events{/privacy}","received_events_url":"https://api.github.com/users/peterkhayes/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-11-20T01:27:46Z","updated_at":"2018-11-20T08:48:01Z","closed_at":null,"author_association":"NONE","pull_request":{"url":"https://api.github.com/repos/moment/luxon/pulls/371","html_url":"https://github.com/moment/luxon/pull/371","diff_url":"https://github.com/moment/luxon/pull/371.diff","patch_url":"https://github.com/moment/luxon/pull/371.patch"},"body":"This pull request adds `toSeconds` and `fromSeconds` methods for working with Unix timestamps. \r\n\r\nNow, I saw that https://github.com/moment/luxon/pull/319 added support for timestamps inside the `.toFormat` function, but didn't add explicit timestamp support. And, I've read the contribution guidelines, which state that:\r\n\r\n> Luxon shouldn't contain simple conveniences that bloat the library to save callers a couple lines of code. Write those lines in your own code.\r\n\r\nHowever, I think supporting Unix timestamps is an important use case. This is because many other systems and specifications use Unix timestamps in seconds as their primary date format. For example:\r\n\r\n- Python's `time()`\r\n- Ruby's `Time.now.to_i`\r\n- Bash's `date +%s`\r\n- C's `time(null)`\r\n\r\nBecause of this, many APIs specify timestamps in seconds. Currently, working with these times is a bit cumbersome, and prone to errors.\r\n\r\n```js\r\nconst inputSeconds = 1542674993;\r\nconst inputDT = DateTime.fromMillis(inputSeconds * 1000);\r\n\r\nconst outputDT = dt.plus({days: 1});\r\nconst outputSeconds = Math.floor(dt.toMillis() / 1000);\r\n// or\r\nconst outputSeconds = Number(dt.toFormat(\"X\"));\r\n```\r\n\r\nIt's easy to forget to multiply or divide by 1000, or to cast the `toFormat` result as a string, and this can lead to subtle bugs. I think having built-in support for seconds is pretty light-weight and makes working with timestamps much easier. An example use case is comparing a Luxon DateTime object to an array of GeoJSON features, each of which has numeric `timestamp` property.\r\n\r\nWe're currently migrating from Moment to Luxon, which has been really nice, except for this. Moment supports unix timestamps directly with `.unix()`, and adding multiplications/divisions everywhere where we used `.unix()` feels less than elegant.\r\n\r\nAnyway, I understand your concerns about bloating the library, but it'd be really nice to see this get in."},"comment":{"url":"https://api.github.com/repos/moment/luxon/issues/comments/440191096","html_url":"https://github.com/moment/luxon/pull/371#issuecomment-440191096","issue_url":"https://api.github.com/repos/moment/luxon/issues/371","id":440191096,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0MDE5MTA5Ng==","user":{"login":"icambron","id":244988,"node_id":"MDQ6VXNlcjI0NDk4OA==","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-11-20T08:48:01Z","updated_at":"2018-11-20T08:48:01Z","author_association":"MEMBER","body":"I had been hoping to avoid adding this one, but it's been asked for a bunch of times now, so I'm going to say yes."}}
{"actor":{"display_login":"icambron"}}