{"id":13464999,"url":"https://github.com/spencermountain/spacetime","last_synced_at":"2025-05-14T09:06:21.297Z","repository":{"id":40560154,"uuid":"82820698","full_name":"spencermountain/spacetime","owner":"spencermountain","description":"A lightweight javascript timezone library","archived":false,"fork":false,"pushed_at":"2025-05-12T13:13:08.000Z","size":7213,"stargazers_count":4066,"open_issues_count":21,"forks_count":190,"subscribers_count":27,"default_branch":"master","last_synced_at":"2025-05-14T09:03:50.707Z","etag":null,"topics":["date-formatting","daylight-savings","time-formatting","timezone","timezone-conversion","timezones"],"latest_commit_sha":null,"homepage":"http://spacetime.how/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/spencermountain.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","contributing":"contributing.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-02-22T15:31:34.000Z","updated_at":"2025-05-12T13:13:13.000Z","dependencies_parsed_at":"2022-07-13T15:59:23.313Z","dependency_job_id":"a19bc187-8302-45c1-96c8-d09f5347ee19","html_url":"https://github.com/spencermountain/spacetime","commit_stats":{"total_commits":993,"total_committers":52,"mean_commits":"19.096153846153847","dds":"0.28197381671701915","last_synced_commit":"53f68cac488115ad68ab9e7f24e6bb75bd29bb4b"},"previous_names":[],"tags_count":57,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spencermountain%2Fspacetime","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spencermountain%2Fspacetime/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spencermountain%2Fspacetime/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spencermountain%2Fspacetime/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spencermountain","download_url":"https://codeload.github.com/spencermountain/spacetime/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254110374,"owners_count":22016391,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["date-formatting","daylight-savings","time-formatting","timezone","timezone-conversion","timezones"],"created_at":"2024-07-31T14:00:54.635Z","updated_at":"2025-05-14T09:06:21.264Z","avatar_url":"https://github.com/spencermountain.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","JS","*.js","others"],"sub_categories":["Time","Browser"],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003cdiv\u003e\n    \u003cimg width=\"277\" alt=\"spacetime logo\" src=\"https://user-images.githubusercontent.com/399657/31140478-80a4269a-a842-11e7-8dbf-b541fe3e87a7.png\"\u003e\n  \u003c/div\u003e\n\n  \u003ca href=\"https://npmjs.org/package/spacetime\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/v/spacetime.svg?style=flat-square\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://bundlephobia.com/result?p=spacetime@latest\"\u003e\n    \u003cimg src=\"https://badgen.net/bundlephobia/min/spacetime\" /\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\n\u003c!-- spacer --\u003e\n\u003cimg height=\"50px\" src=\"https://user-images.githubusercontent.com/399657/68221862-17ceb980-ffb8-11e9-87d4-7b30b6488f16.png\"/\u003e\n\nIsn't it weird how we can do \u003ci\u003emath\u003c/i\u003e in our head, but not \u003cb\u003e\u003ci\u003edate math\u003c/i\u003e\u003c/b\u003e?\n\n\u003cdiv align=\"left\"\u003e\n\u003cdiv \u003e\n  \u003cimg height=\"30px\" src=\"https://user-images.githubusercontent.com/399657/68221862-17ceb980-ffb8-11e9-87d4-7b30b6488f16.png\"/\u003e\u003ci\u003e- how many days until the end of the year?\u003c/i\u003e\n\u003c/div\u003e\n\u003cdiv \u003e\n  \u003cimg height=\"30px\" src=\"https://user-images.githubusercontent.com/399657/68221862-17ceb980-ffb8-11e9-87d4-7b30b6488f16.png\"/\u003e\u003ci\u003e-what time was it, 11 hours ago?\u003c/i\u003e\n\u003c/div\u003e\n\u003cdiv \u003e\n  \u003cimg height=\"30px\" src=\"https://user-images.githubusercontent.com/399657/68221862-17ceb980-ffb8-11e9-87d4-7b30b6488f16.png\"/\u003e\u003ci\u003e-is it lunchtime in france?\u003c/i\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\u003cimg height=\"50px\" src=\"https://user-images.githubusercontent.com/399657/68221862-17ceb980-ffb8-11e9-87d4-7b30b6488f16.png\"/\u003e\n\nand worse - there is no real **_date calculator_**.\n\n\u003cdiv align=\"center\"\u003e\n  \u003csub\u003epeople end up asking google, and going to weird websites.\u003c/sub\u003e\n\u003c/div\u003e\n\n\u003cimg height=\"10px\" src=\"https://user-images.githubusercontent.com/399657/68221862-17ceb980-ffb8-11e9-87d4-7b30b6488f16.png\"/\u003e\n\n\u003cdiv align=\"center\"\u003e\u003csub\u003ethat's bad.\u003c/sub\u003e\u003c/div\u003e\n\n\u003cimg height=\"25px\" src=\"https://user-images.githubusercontent.com/399657/68221862-17ceb980-ffb8-11e9-87d4-7b30b6488f16.png\"/\u003e\n\n\u003cb\u003espacetime\u003c/b\u003e is a date-calculator,\n\n\u003cdiv \u003e\n  \u003cimg height=\"25px\" src=\"https://user-images.githubusercontent.com/399657/68221862-17ceb980-ffb8-11e9-87d4-7b30b6488f16.png\"/\u003e\u003csub\u003eIt's very small, and very handy.\u003c/sub\u003e\n\u003c/div\u003e\n\n```js\nlet s = spacetime.now()\n\ns.diff(s.endOf('year'), 'days')\n// 292\n\ns.substract(11, 'hours').time()\n// 6:50am\n\ns = s.goto('Europe/Paris')\ns.isAfter(s.time('11:00am'))\n// true 🥐\n```\n\n\u003cimg height=\"30px\" src=\"https://user-images.githubusercontent.com/399657/68221862-17ceb980-ffb8-11e9-87d4-7b30b6488f16.png\"/\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg height=\"50px\" src=\"https://user-images.githubusercontent.com/399657/68221814-05ed1680-ffb8-11e9-8b6b-c7528d163871.png\"/\u003e\n\u003c/div\u003e\n\u003cimg height=\"30px\" src=\"https://user-images.githubusercontent.com/399657/68221862-17ceb980-ffb8-11e9-87d4-7b30b6488f16.png\"/\u003e\n\n- calculate time in remote timezones\n- support **daylight savings**, **leap years**, and **hemispheres**\n- [Moment-like API](https://beta.observablehq.com/@spencermountain/spacetime-api) _(but immutable)_\n- Orient time by quarter, season, month, week..\n- _Zero Dependencies_ - (no _[Intl API](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl)_)\n- weighs about 40kb.\n- has a cool _[plugin thing](https://observablehq.com/@spencermountain/spacetime)_.\n- frequent updates for approaching DST changes\n- support for upcoming [Temporal](https://tc39.es/proposal-temporal/docs/) standards\n\n\n\u003c!-- spacer --\u003e\n\u003cimg height=\"30px\" src=\"https://user-images.githubusercontent.com/399657/68221862-17ceb980-ffb8-11e9-87d4-7b30b6488f16.png\"/\u003e\n\n```html\n\u003cscript src=\"https://unpkg.com/spacetime\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n  var d = spacetime('March 1 2012', 'America/New_York')\n  //set the time\n  d = d.time('4:20pm')\n\n  d = d.goto('America/Los_Angeles')\n  d.time()\n  //'1:20pm'\n\u003c/script\u003e\n```\n\n\u003c!-- spacer --\u003e\n\u003cimg height=\"30px\" src=\"https://user-images.githubusercontent.com/399657/68221862-17ceb980-ffb8-11e9-87d4-7b30b6488f16.png\"/\u003e\n\n`npm install spacetime`\n\n```js\nconst spacetime = require('spacetime')\nlet d = spacetime.now('Europe/Paris')\nd.dayName()\n//'Wednesday'\nd.isAsleep()\n//true\n```\n\n\u003csub\u003e\u003ci\u003etypescript / babel / deno:\u003c/i\u003e\u003c/sub\u003e\n\n```ts\nimport spacetime from 'spacetime'\nlet d = spacetime.now()\nd.format('nice')\n//'Apr 1st, 4:32pm'\n```\n\n\u003cdiv align=\"right\"\u003e\n  \u003ca href=\"https://github.com/spencermountain/spacetime/wiki/Typescript\"\u003ets docs\u003c/a\u003e\n\u003c/div\u003e\n\n\u003cimg height=\"50px\" src=\"https://user-images.githubusercontent.com/399657/68221862-17ceb980-ffb8-11e9-87d4-7b30b6488f16.png\"/\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003ch3\u003e\n    \u003ca href=\"https://beta.observablehq.com/@spencermountain/spacetime\"\u003e\n      Demo\n    \u003c/a\u003e\n    \u0026nbsp; \u0026nbsp; • \u0026nbsp; \u0026nbsp;\n    \u003ca href=\"https://beta.observablehq.com/@spencermountain/spacetime-api\"\u003e\n      Full API\n    \u003c/a\u003e\n  \u003c/h3\u003e\n  \u003cimg height=\"30px\" src=\"https://user-images.githubusercontent.com/399657/68221862-17ceb980-ffb8-11e9-87d4-7b30b6488f16.png\"/\u003e\n\n  \u003cdiv\u003e\n    \u003cimg width=\"550\" src=\"https://user-images.githubusercontent.com/399657/50862221-1d904a00-1369-11e9-891c-5f4e9fbb9ec0.gif\" /\u003e\n  \u003c/div\u003e\n\n  \u003cimg height=\"40px\" src=\"https://user-images.githubusercontent.com/399657/68221862-17ceb980-ffb8-11e9-87d4-7b30b6488f16.png\"/\u003e\n\n \u003c/div\u003e\n\n\u003cimg height=\"30px\" src=\"https://user-images.githubusercontent.com/399657/68221862-17ceb980-ffb8-11e9-87d4-7b30b6488f16.png\"/\u003e\n\nplugins:\n\n \u003cdiv align=\"center\"\u003e\n    \u003ca href=\"https://github.com/spencermountain/spacetime/tree/master/plugins/geo\"\u003espacetime-geo\u003c/a\u003e\n    • \u003ca href=\"https://github.com/spencermountain/spacetime/tree/master/plugins/daylight\"\u003espacetime-daylight\u003c/a\u003e\n    • \u003ca href=\"https://github.com/spencermountain/spacetime/tree/master/plugins/age\"\u003espacetime-age\u003c/a\u003e\n  \u003c/div\u003e\n  \u003cdiv align=\"center\"\u003e\n    \u003ca href=\"https://github.com/spencermountain/scal\"\u003espacetime-calendar\u003c/a\u003e\n    • \u003ca href=\"https://github.com/spencermountain/spacetime/tree/master/plugins/week-of-month\"\u003eweek-of-month\u003c/a\u003e\n    • \u003ca href=\"https://github.com/spencermountain/spacetime/tree/master/plugins/week-start\"\u003eweek-start\u003c/a\u003e\n  \u003c/div\u003e\n\n\u003cimg height=\"50px\" src=\"https://user-images.githubusercontent.com/399657/68221862-17ceb980-ffb8-11e9-87d4-7b30b6488f16.png\"/\u003e\n\n### Date Inputs:\n\nwe can parse _[all the normal stuff](https://github.com/spencermountain/spacetime/wiki/Input)_, and some fancy stuff:\n\n```js\n//epoch\ns = spacetime(1489520157124)\n\n//array [yyyy, m, d] (zero-based months, 1-based days)\ns = spacetime([2017, 5, 2])\n\n//iso\ns = spacetime('July 2, 2017 5:01:00')\n\n// All inputs accept a timezone, as 2nd param:\ns = spacetime(1489520157124, 'Canada/Pacific')\ns = spacetime('2019/05/15', 'Canada/Pacific')\n\n// or set the offset right in the date-string (ISO-8601)\ns = spacetime('2017-04-03T08:00:00-0700')\n// 'Etc/GMT-7'\n\n// Some helpers\ns = spacetime.now()\ns = spacetime.today() // This morning\ns = spacetime.tomorrow() // Tomorrow morning\ns = spacetime.min() // the earliest-possible date (271,821 bc)\ns = spacetime.max() // the furthest-possible future date (27k years from now)\n\n// To get the native Date object back\n// (this bails back to the local timezone)\njsDate = spacetimeDate.toNativeDate()\n```\n\nfor fancier natural-language inputs, use [compromise-dates](https://github.com/spencermountain/compromise/tree/master/plugins/dates).\n\n\u003cimg height=\"20px\" src=\"https://user-images.githubusercontent.com/399657/68221862-17ceb980-ffb8-11e9-87d4-7b30b6488f16.png\"/\u003e\n\n### Get \u0026 Set dates:\n\nyou can whip things around, but stay intuitive\n\n```js\ns.date() // 14\ns.year() // 2017\ns.season() // Spring\ns = s.hour(5) // Change to 5am\ns = s.date(15) // Change to the 15th\n\ns = s.day('monday') // Change to (this week's) monday\ns = s.day('monday', true) // go forward to monday\ns = s.day('monday', false) // go backward to monday\n\ns = s.month('march') // Change to (this year's) March 1st\ns = s.quarter(2) // Change to April 1st\ns.era() // 'BC'/'AD'\ns.decade() // 2000\ns.century() // 21\n\n// Percentage-based information\ns.progress().month = 0.23 // We're a quarter way through the month\ns.progress().day = 0.48 // Almost noon\ns.progress().hour = 0.99 // 59 minutes and 59 seconds\n\n// Add/subtract methods\ns = s.add(1, 'week')\ns = s.add(3, 'quarters')\ns = s.subtract(2, 'months').add(1, 'day')\n\n// start-of/end-of\ns = s.startOf('day') // 12:00am\ns = s.startOf('month') // 12:00am, April 1st\ns = s.endOf('quarter') // 11:59:59pm, June 30th\n\ns = s.nearest('hour') //round up/down to the hour\ns = s.nearest('quarter-hour') //5:15, 5:30, 5:45..\ns = s.next('month') //start of the next month\ns = s.last('year') //start of the last year\n\n// fill-in all dates between a range\ns.every('week', 'Jan 1st 2020') // (in tz of starting-date)\n\n//utilities:\ns.clone() // Make a copy\ns.isValid() // Sept 32nd → false\ns.isAwake() // it's between 8am → 10pm\ns.json() // get values in every unit as key-val object\n```\n\nif it's **_9am on tuesday_**, and you \u003ci\u003eadd a week\u003c/i\u003e, it will still be 9am on tuesday.\n... even if some crazy changes happen.\n\nsetter methods also support a handy 2nd param that controls whether it should be set forward, or backward.\n\n```js\ns = s.time('4:00pm') // 4pm today\ns = s.time('4:00pm', true) // the next 4pm in the future\ns = s.time('4:00pm', false) // the most-recent 4pm\n\ns = s.set('march 5th 2020')\ns = s.set('march 4th') // 2020 (same year)\ns = s.set('march 4th', true) // 2021\ns = s.set('march 6th', false) // 2019\n```\n\nit's actually a little surprising how helpful this is.\n\n\u003cimg height=\"20px\" src=\"https://user-images.githubusercontent.com/399657/68221862-17ceb980-ffb8-11e9-87d4-7b30b6488f16.png\"/\u003e\n\n### Comparisons:\n\n```js\nlet s = spacetime([2017, 5, 2])\nlet start = s.subtract(1, 'milliseconds')\nlet end = s.add(1, 'milliseconds')\n\n// gt/lt/equals\ns.isAfter(d) // True\ns.isEqual(d) // False\ns.isBefore(d) // False\ns.isBetween(start, end, inclusive?) // True\n\n// Comparison by unit\ns.isSame(d, 'year') // True\ns.isSame(d, 'date') // False\ns.diff(d, 'day') // 5\ns.diff(d, 'month') // 0\n\n//make a human-readable diff\nlet before = spacetime([2018, 3, 28])\nlet now = spacetime([2017, 3, 28]) //one year later\nnow.since(before)\n// {diff: { months: 11, days: 30, ...},  rounded: 'in 12 months'  }\n```\n\nall comparisons are done with sensitivity of timezone - **_8am EST_** is \u003c **_8am PST_**.\n\n\u003cimg height=\"20px\" src=\"https://user-images.githubusercontent.com/399657/68221862-17ceb980-ffb8-11e9-87d4-7b30b6488f16.png\"/\u003e\n\n### Timezones:\n\nthe best way to describe a timezone is an [IANA code](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones):\n\n```js\n// Roll into a new timezone, at the same moment\ns = s.goto('Australia/Brisbane')\n```\n\nif you want to support relaxed timezone names like `'EST'`, `Eastern time`, use [timezone-soft](https://github.com/spencermountain/timezone-soft/)\n\n```js\nspacetime.extend(require('timezone-soft'))\n\ns = s.goto('milwaukee') // 'America/Chicago'\ns = s.goto('-7h') // UTC-7\ns = s.goto('GMT+8') // -8h!\n// (these should be used with some caution)\n```\n\nplay-around with timezones, and their DST-changes:\n\n```js\n//list timezones by their current time\nspacetime.whereIts('8:30pm', '9:30pm') // ['America/Winnipeg', 'America/Yellowknife'... ]\nspacetime.whereIts('9am') //(within this hour)\n\n// Timezone metadata\ns.timezone().name // 'Canada/Eastern' (either inferred or explicit)\ns.hemisphere() // North\ns.timezone().current.offset // -4 (in hours)\ns.hasDST() // True\ns.isDST() // True\n\n//list all timezones\nspacetime.timezones()\n```\n\nyou can flip-around the world pretty quick.\n\nspacetime will use your local timezone, by default:\n\n`.goto(null)` will pluck your current tz safely from your browser or computer.\n\n```js\nspacetime().time('4:30pm').goto('Europe/Paris').goto(null).time()\n// 4:30pm\n```\n\nIf, for some reason, you want to change the timezone *without changing the date*, you can do this via the `.timezone(str)` setter:\n```js\nlet s = spacetime('2023-01-01T5:30[America/Denver]')\ns = s.timezone('Europe/Zagreb') // hot-swap\nconsole.log(s.isoFull())\n// '2023-01-01T05:30:00.000+01:00[Europe/Zagreb]' (same time, new tz)\n```\n\n\u003cimg height=\"20px\" src=\"https://user-images.githubusercontent.com/399657/68221862-17ceb980-ffb8-11e9-87d4-7b30b6488f16.png\"/\u003e\n\n### Date Formatting:\n\nit's _[a pretty-sensible process](https://github.com/spencermountain/spacetime/wiki/Formatting)_ to create nice-looking dates:\n\n```js\n// Date + time formatting\ns.format('time') // '5:01am'\ns.format('numeric-uk') // 02/03/2017\ns.format('month') // 'April'\ns.format('month-short') // 'Apr'\ns.format('month-pad') // '03'\ns.format('iso-month') // '04'\n\n//if you want more complex formats, use {}'s\ns.format('{year}-{date-pad}-{month-pad}') // '2018-02-02'\ns.format(\"{hour} o'clock\") // '2 o'clock'\ns.format('{time}{ampm} sharp') // '2:30pm sharp'\n\n//if you prefer, you can also use unix-formatting\ns.unixFmt('yyyy.MM.dd h:mm a') // '2017.Nov.16 11:34 AM'\n\n// support for the new Temporal ISO format\ns.format('iso-full') // '2011-12-03T10:15:30.010+01:00[Europe/Paris]'\n\n// support for the SQL ISO 9075 format\ns.format('sql') // '2011-12-03 10:15:30'\n```\n\n\u003c!-- spacer --\u003e\n\u003cimg height=\"50px\" src=\"https://user-images.githubusercontent.com/399657/68221862-17ceb980-ffb8-11e9-87d4-7b30b6488f16.png\"/\u003e\n\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"https://user-images.githubusercontent.com/399657/68221814-05ed1680-ffb8-11e9-8b6b-c7528d163871.png\"/\u003e\n\u003c/div\u003e\n\n## Limitations \u0026 caveats\n\n#### ◆ Historical timezone info\n\nDST changes move around all the time, and timezones pop-in and out of existence.\nWe store and use only the latest DST information, and apply it to historical dates.\n\n#### ◆ International date line\n\n`.goto()` never crosses the date-line. This is mostly the intuitive behaviour.\n\nBut if you're in `Fiji` (just west of the date line), and you go to `Midway` (just east of the date line), .goto() will subtract a bunch of hours, instead of just adding one.\n\n#### ◆ Destructive changes\n\nif it's `2:30pm` and you add a month, it should still be `2:30pm`. Some changes are more destructive than others. Many of thse choices are subjective, but also sensible.\n\n#### ◆ 0-based vs 1-based ...\n\nfor better or worse we copy the JavaScript spec for 0-based months, and 1-based dates.\n\nISO-formatting is different, so keep on your toes.\n\nsee [more considerations and gotchas](https://github.com/spencermountain/spacetime/wiki)\n\n#### Daylight-savings gotchas\n\nWe've written in detail about how spacetime handles Daylight-savings changes [here](https://observablehq.com/@spencermountain/spacetime-daylight-savings-time?collection=@spencermountain/spacetime)\n\nFall DST changes have an hour that is repeated twice. There are a lot of tricky situations that come from this.\nAdd 10 minutes at `1:55am`, and a spacetime diff may show `-50mins`. Within an hour of this change, some spacetime methods may be off-by-one hour.\n\nSpringtime DST changes are generally smoother than Fall ones.\n\n\u003c!-- spacer --\u003e\n\u003cdiv align=\"center\"\u003e\n  \u003cimg height=\"25px\" src=\"https://user-images.githubusercontent.com/399657/68221862-17ceb980-ffb8-11e9-87d4-7b30b6488f16.png\"/\u003e\n\u003c/div\u003e\n\u003cdiv align=\"center\"\u003e\n  \u003cimg height=\"50px\" src=\"https://user-images.githubusercontent.com/399657/68221632-b9094000-ffb7-11e9-99e0-b48edd6cdf8a.png\"/\u003e\n\u003c/div\u003e\n\n### Config:\n\n#### Ambiguity warnings:\n\njavascript dates use millisecond-epochs, instead of second-epochs, like some other languages.\nThis is a common bug, and spacetime can warn if you set an epoch within January 1970.\nto enable:\n\n```js\nlet s = spacetime(123456, 'UTC', {\n  silent: false\n})\ns.log() // \"Jan 1st, 12:02am\"\n```\n\nThere is another situation where you may see a `console.warn` - if you give it a timezone, but then set a ISO-date string with a different offset, like `2017-04-03T08:00:00-0700` (-7hrs UTC offset).\nIt sets the timezone to UTC-7, but also gives a warning.\n\n```js\nlet s = spacetime('2017-04-03T08:00:00-0700', 'Canada/Eastern', {\n  silent: false\n})\ns.timezone().name // \"Etc/GMT-7\"\n```\n\n#### Configure 'today' context:\n\nspacetime makes some assumptions about some string inputs:\n\n```js\n// assumes start of month\nlet s = spacetime('June 1992')\ns.date() // 1\n\n// assumes current year\nlet s = spacetime('June 5th')\ns.year() // 2020 (or whatever it is now)\n\n// assumes Jan 1st\nlet s = spacetime('2030')\ns.month() // 'January'\n```\n\nyou can configure this assumed date (usually for testing) by passing it in as an option:\n\n```js\nlet today = {\n  month: 3,\n  date: 4,\n  year: 1996\n}\nlet s = spacetime('June 5th', null, { today: today })\ns.year() // 1996\n```\n\nit also works for `spacetime.now(tz, {today:today})` and others.\n\n#### Extending/Plugins:\n\nyou can throw any methods onto the Spacetime class you want, with `spacetime.extend()`:\n\n```js\nspacetime.extend({\n  isHappyHour: function () {\n    return this.hour() === 16\n  }\n})\n\nlet s = spacetime.now('Australia/Adelaide')\ns.isHappyHour()\n//false\n\ns = s.time('4:30pm')\ns.isHappyHour()\n//true\n```\n\n#### DD/MM/YYY interpretation:\n\nby default spacetime uses the American interpretation of ambiguous date formats, like javascript does:\n\n```js\nspacetime('12/01/2018') //dec 1st\n\n// unless it's clear (\u003e12):\nspacetime('13/01/2018') //jan 13th\n```\n\nyou can change this behaviour by passing in a `dmy` option, like this:\n\n```js\nspacetime('12/01/2018', null, { dmy: true }) //jan 12th\n```\n\nthis format is more common in [britain, and south america](https://en.wikipedia.org/wiki/Date_format_by_country).\n\n#### Custom languages:\n\n```js\nlet s = spacetime.now()\ns.i18n({\n  days: {\n    long: ['domingo', 'lunes', 'martes', 'miércoles', 'jueves', 'viernes', 'sábado'],\n    short: ['dom', 'lun', 'mar', 'mié', 'jue', 'vie', 'sáb']\n  },\n  months: {\n    long: [...],\n    short: ['ene', 'feb', 'mar', 'abr', 'may', 'jun', 'jul', 'ago', 'sep', 'oct', 'nov', 'dic'],\n  },\n  ampm: {\n    am: ' a. m.',\n    pm: ' a. m.'\n  },\n  distance: {\n    past: 'past',\n    future: 'future',\n    present: 'present',\n    now: 'now',\n    almost: 'almost',\n    over: 'over',\n    pastDistance: (value) =\u003e `${value} ago`,\n    futureDistance: (value) =\u003e `in ${value}`\n  },\n  units: {\n    second: 'second',\n    seconds: 'seconds',\n    minute: 'minute',\n    minutes: 'minutes',\n    hour: 'hour',\n    hours: 'hours',\n    day: 'day',\n    days: 'seconds',\n    month: 'month',\n    months: 'months',\n    year: 'year',\n    years: 'years',\n  },\n  useTitleCase: true // automatically in .format()\n});\ns.format('day') //'Sábado'\n```\n\n#### Configure start of week:\n\nby default, the start of the week is monday.\n\nYou can determine the week by the official country setting, with [spacetime-week](https://github.com/spencermountain/spacetime-week)\n\n```js\nlet s = spacetime.now()\ns = s.weekStart('sunday')\n\ns = s.startOf('week')\ns.dayName()\n//sunday\n\ns = s.endOf('week')\ns.dayName()\n//saturday\n```\n\n\u003c!-- spacer --\u003e\n\u003cdiv align=\"center\"\u003e\n  \u003cimg height=\"25px\" src=\"https://user-images.githubusercontent.com/399657/68221862-17ceb980-ffb8-11e9-87d4-7b30b6488f16.png\"/\u003e\n\u003c/div\u003e\n\u003cdiv align=\"center\"\u003e\n  \u003cimg height=\"50px\" src=\"https://user-images.githubusercontent.com/399657/68221824-09809d80-ffb8-11e9-9ef0-6ed3574b0ce8.png\"/\u003e\n\u003c/div\u003e\n\n#### See also:\n\n- [luxon](https://moment.github.io/luxon/) - a small library from the clever moment people\n- [date-fns](https://date-fns.org/) - an battle-hardened client-side Date utility\n- [sugarjs/dates](https://sugarjs.com/dates/) - well-made date fns + timezone math\n- [Intl.DateTimeFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat) - some _[sorta-green](https://caniuse.com/#feat=internationalization)_ in-browser date utilities\n- [BurntSushi/Jiff](https://github.com/BurntSushi/jiff) - Rust/wasm date library\n\nthank you to the amazing [timeanddate.com](https://www.timeanddate.com/)\n\nApache 2.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspencermountain%2Fspacetime","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspencermountain%2Fspacetime","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspencermountain%2Fspacetime/lists"}