{"id":21594443,"url":"https://github.com/meduzen/datetime-attribute","last_synced_at":"2025-04-10T23:41:59.626Z","repository":{"id":40451033,"uuid":"347492641","full_name":"meduzen/datetime-attribute","owner":"meduzen","description":"Get a `datetime` attribute for the HTML `\u003ctime\u003e` element (and others).","archived":false,"fork":false,"pushed_at":"2025-01-01T11:48:53.000Z","size":1128,"stargazers_count":17,"open_issues_count":9,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-24T20:37:55.617Z","etag":null,"topics":["date","datetime","duration","html-attributes","html-time","iso-8601","javascript","temporal","time","timezone","typescript"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"wtfpl","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/meduzen.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-03-13T22:27:51.000Z","updated_at":"2024-12-04T12:45:08.000Z","dependencies_parsed_at":"2022-07-12T18:02:20.616Z","dependency_job_id":"ce6072c8-2729-43f5-baaa-34c314f7a033","html_url":"https://github.com/meduzen/datetime-attribute","commit_stats":{"total_commits":191,"total_committers":5,"mean_commits":38.2,"dds":0.3455497382198953,"last_synced_commit":"5c37a55bcba7c6abc1100f3061810091ee8a8afe"},"previous_names":[],"tags_count":44,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meduzen%2Fdatetime-attribute","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meduzen%2Fdatetime-attribute/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meduzen%2Fdatetime-attribute/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meduzen%2Fdatetime-attribute/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/meduzen","download_url":"https://codeload.github.com/meduzen/datetime-attribute/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247987184,"owners_count":21028891,"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","datetime","duration","html-attributes","html-time","iso-8601","javascript","temporal","time","timezone","typescript"],"created_at":"2024-11-24T17:18:22.647Z","updated_at":"2025-04-10T23:41:59.607Z","avatar_url":"https://github.com/meduzen.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# datetime-attribute\n\nGet a [`datetime` attribute](https://developer.mozilla.org/en-US/docs/Web/API/HTMLTimeElement/datetime) for HTML `\u003ctime\u003e` (and [other elements](#not-only-in-time)).\n\nIt covers the [whole WHATWG specification](https://html.spec.whatwg.org/multipage/text-level-semantics.html#attr-time-datetime) in 4 functions:\n- [**`datetime()`**](#expressing-moments-with-datetime) for a specific moment ([641 B compressed](https://bundlejs.com/?q=datetime-attribute\u0026treeshake=[{datetime}]\u0026config={\"compression\"%3A\"brotli\"}\u0026bundle));\n- [**`datetimeTz()`**](#adding-a-timezone-offset-to-a-moment-with-datetimetz) for a specific moment in a given timezone ([903 B](https://bundlejs.com/?q=datetime-attribute\u0026treeshake=[{datetimeTz}]\u0026config={\"compression\"%3A\"brotli\"}\u0026bundle));\n- [**`duration()`**](#expressing-durations-with-duration) for a duration ([284 B](https://bundlejs.com/?q=datetime-attribute\u0026treeshake=[{duration}]\u0026config={\"compression\"%3A\"brotli\"}\u0026bundle));\n- [**`tzOffset()`**](#expressing-timezone-offsets-with-tzoffset) for a timezone offset ([332 B](https://bundlejs.com/?q=datetime-attribute\u0026treeshake=[{tzOffset}]\u0026config={\"compression\"%3A\"brotli\"}\u0026bundle)).\n\nAdditionally, a [`DateTime` class](#the-datetime-class) ([710 B](https://bundlejs.com/?q=datetime-attribute\u0026treeshake=[{DateTime}]\u0026config={\"compression\"%3A\"brotli\"}\u0026bundle)) and some [other functions](#other-functions) are provided.\n\n[![Node.js CI](https://github.com/meduzen/datetime-attribute/actions/workflows/node.js.yml/badge.svg)](https://github.com/meduzen/datetime-attribute/actions/workflows/node.js.yml)\n\nThe package is lightweight ([~ 1.37 KB compressed](https://bundlejs.com/?q=datetime-attribute\u0026config={\"compression\"%3A\"brotli\"}\u0026bundle) for `import *`), tree-shakeable, typed and tested.\n\n## Table of contents\n\n- [Summary usage](#summary-usage)\n- [Installation](#installation)\n- Usage\n  - [**`datetime()`**](#expressing-moments-with-datetime) to express a **moment** at different [levels of precision](#available-precision-keywords):\n    - [date](#date)\n    - [time and UTC time](#time-and-utc-time)\n    - [datetime and UTC datetime](#datetime-and-utc-datetime)\n    - alternative to the UTC syntax with [`utc()`](#the-utc-shortcut)\n    - [datetime separator](#datetime-separator)\n  - [**`tzOffset()`**](#expressing-timezone-offsets-with-tzoffset) to express a **timezone offset**\n    - [hours-minutes separator](#hours-minutes-separator)\n    - [real-world timezone offset](#real-world-timezone-offset)\n    - [timezone configuration](#timezone-configuration)\n  - [**`datetimeTz()`**](#adding-a-timezone-offset-to-a-moment-with-datetimetz) to express a **moment with a specific timezone** offset\n  - [**`duration()`**](#expressing-durations-with-duration) to expressing a **duration**\n    - [units overflow](#units-overflow)\n- [The **`DateTime`** class](#the-datetime-class)\n  - [**`.getWeek()`**](#datetimeprototypegetweek)\n  - [**`.setWeek()`**](#datetimeprototypesetweek)\n  - [**`.to()`**](#datetimeprototypeto)\n- Other functions\n  - [**`daysBetween()`**](#daysbetween) to get the number of **days between two dates**\n  - [**`weekNumber()`**](#weeknumber) to get the **week number** (in the year) of a date\n- Various:\n  - [Changelog](#changelog)\n  - [Browser and tooling support](#browser-and-tooling-support)\n  - [Not only in `\u003ctime\u003e`](#not-only-in-time)\n  - [Security](#security)\n  - [Contributing](#contributing)\n  - [License](#license)\n\n## Summary usage\n\n```js\nimport * from 'datetime-attribute'\n\nconst now = new Date()\n\ndatetime(now)                   // '2021-03-14'\ndatetime(now, 'time')           // '10:29'\ndatetimeTz(now, 'datetime', -7) // '2021-03-14T10:29-07:00'\nutc(now, 'time')                // '09:29Z'\n\ntzOffset(-9, -30) // '-09:30' (Marquesas Islands)\nduration({ d: 4, h: 3, m: 17 }) // 'P4DT3H17M'\n\nconst importantMeeting = new DateTime(2021, 12, 17, 19, 00) // 17/11\nconst meetingWeek = importantMeeting.getWeek() // 46\n\nimportantMeeting.setWeek(meetingWeek + 1) // meeting now on 24/11\nimportantMeeting.to('week')        // 2021W47\nimportantMeeting.to('datetime')    // 2021-11-24T19:00\n\ndaysBetween(now, importantMeeting) // 248\n```\n\n## Installation\n\nInstall the package:\n\n`npm install datetime-attribute`\n\nThen, import the functions you need in your script:\n\n```js\n// if you only need `datetime` and `duration`\nimport { datetime, duration } from 'datetime-attribute'\n\n// if you need everything\nimport * from 'datetime-attribute'\n```\n\nNot using a package manager? Download [the package files](https://github.com/meduzen/datetime-attribute/releases) in your project and take the files in `/src`.\n\n## Expressing moments with `datetime()`\n\n`datetime()` accepts two optional arguments: a [Date object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date), and a [_precision_ keywords](#available-precision-keywords).\n\n```js\nimport { datetime } from 'datetime-attribute'\n\nconst now = new Date() // We’re 14 March 2021 and it’s 10:29 in Brussels.\n\ndatetime(now)             // '2021-03-14'\ndatetime(now, 'datetime') // '2021-03-14T10:29'\n```\n\nWithout argument, it defaults to _today_:\n```js\ndatetime() // today formatted in YYYY-mm-dd\ndatetime((new Date()), 'day') // same\n```\n\n### Available precision keywords\n\nBy default, `datetime()` precision is `day`, resulting in a `YYYY-mm-dd`\noutput. Many other values are available.\n\n#### Date\n\n|  precision | example output | description\n|--|--|--|\n| `day` | `2021-03-14` | the default, fitting a calendar |\n| `year` | `2021` | only the year |\n| `yearless` | `03-14` | a day in a month |\n| `month` | `2021-03` | a month in a year |\n| `week` | `2021W10` | the week number ([ISO-8601 spec](https://en.wikipedia.org/wiki/ISO_week_date)) and its year |\n\n#### Time and UTC time\n\nTime:\n\n|  precision | example output | description\n|--|--|--|\n| `time` | `10:29` | hours and minutes, like most clocks\n| `second` | `10:29:00` | time with precision up to seconds\n| `ms` | `10:29:00.000` | time with precision up to milliseconds\n\nTo get UTC time, add ` utc` to the time keyword:\n\n|  precision | example output | description\n|--|--|--|\n| `time utc` | `09:29Z` | `time`, shifted to UTC time\n| `second utc` | `09:29:00Z` | `second`, shifted to UTC time\n| `ms utc` | `09:29:00.000Z` | `ms`, shifted to UTC time\n\n#### Datetime and UTC datetime\n\nDatetime:\n\n|  precision | example output | description\n|--|--|--|\n`datetime` | `2021-03-14T10:29` | a local datetime (= date + time separated by `T`)\n`datetime second` | `2021-03-14T10:29:00` | time with precision up to seconds\n`datetime ms` | `2021-03-14T10:29:00.000` | time with precision up to milliseconds\n\nTo get UTC datetime, add ` utc` to the datetime keyword:\n\n|  precision | example output | description\n|--|--|--|\n`datetime utc` | `2021-03-14T09:29Z` | `datetime`, shifted to UTC time\n`datetime second utc` | `2021-03-14T09:29:00Z` | `datetime second`, shifted to UTC time\n`datetime ms utc` | `2021-03-14T09:29:00.000Z` | `datetime ms`, shifted to UTC time\n\n#### The `utc` shortcut\n\n💡 Instead of adding ` utc` to a [time](#time-and-utc-time) or [datetime](#datetime-and-utc-datetime) keyword, you can use `utc(date, precision)`, which has `datetime` as default precision:\n\n```js\nimport { datetime, utc } from 'datetime-attribute'\n\nconst now =  new  Date()  // We’re 14 March 2021 and it’s 10:29 in Brussels.\n\n// These are the same:\nutc(now, 'time') // `09:29Z`\ndatetime(now, 'time utc') // `09:29Z`\n\n// These are the same:\nutc(now)             // `2021-03-14T09:29Z`\nutc(now, 'datetime') // `2021-03-14T09:29Z`\ndatetime(now, 'datetime utc') // `2021-03-14T09:29Z`\n```\n\n### Datetime separator\n\n[Per spec](https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#local-dates-and-times), the separator between date and time can be `T` (default) or ` ` (1 space).\n\nTo change the separator globally, use `setTimeSeparator`:\n\n```js\nimport { setTimeSeparator } from 'datetime-attribute'\n\nsetTimeSeparator(' ')\n\n// All next datetime functions will follow the new setting.\ndatetime(now) // `2021-03-14 10:29`\n\n// Switch back to the default.\nsetTimeSeparator('T') // or `setTimeSeparator()`\n```\n\nSetting the separator to a space can be useful to deal with [MySQL](https://dev.mysql.com/doc/refman/8.0/en/datetime.html) or [MariaDB `DATETIME`](https://mariadb.com/kb/en/datetime/) column.\n\n## Expressing timezone offsets with `tzOffset()`\n\nTimezone offsets are a comparison against [UTC time](https://en.wikipedia.org/wiki/Coordinated_Universal_Time). For example, `+01:00` means “one hour ahead of UTC time” and `-05:00` means “five hours behind UTC time”.\n\n`tzOffset()` accepts three optional arguments for hours, minutes, and [compliance to real-world boundaries](#real-world-timezone-offset). Without argument, the local timezone offset is returned (and may differ based on daylight saving time).\n\n```js\nimport { tzOffset } from 'datetime-attribute'\n\ntzOffset(3)      // '+03:00' (Moscow)\n\ntzOffset(-9, -30) // '-09:30' (Marquesas Islands)\ntzOffset(-9.5)   // '-09:30' (same with 1 parameter)\n\ntzOffset(5, -30) // '+04:30' (Afghanistan)\ntzOffset(5, 30)  // '+05:30' (India)\n\ntzOffset(0)      //      'Z' (Ghana; 'Z' is equal to '+00:00')\n\n// in Belgium\ntzOffset()       // '+01:00'\ntzOffset()       // '+02:00' (under daylight saving time)\n```\n\n### Hours-minutes separator\n\n[Per spec](https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#time-zones), the separator between hours and minutes is optional. The allowed values are:\n- (default) a colon caracter (`:`);\n- an empty string.\n\nTo change the separator globally, use `setTzSeparator`:\n\n```js\nimport { setTzSeparator } from 'datetime-attribute'\n\nsetTzSeparator('')\n\n// All next timezone-related functions will follow the new setting.\ntzOffset(3)       // '+0300'\ntzOffset(-9, -30)  // '-0930'\n\n// Switch back to the default.\nsetTzSeparator(':')\n```\n\n### Real-world timezone offset\n\nThe timezone offset will always be adjusted to fit in the spec range (from `-23:59` to `+23:59`). This means `tzOffset(44)` will output `+20:00` instead of `+44:00`.\n\nHowever, timezone offsets of countries in the world are all between `-12:00` and `+14:00`. If you want `tzOffset(44)` to output `-04:00` (instead of `+20:00`) so that it matches real-world boundaries, give it a third parameter (default: `false`):\n\n```js\ntzOffset(44) // '+20:00'\ntzOffset(44, 0, true) // '-04:00'\n```\n\nTo change the behaviour globally, use `setTzInRealWorldRange`:\n\n```js\nimport { setTzInRealWorldRange } from 'datetime-attribute'\n\nsetTzInRealWorldRange(true)\n\n// All next timezone-related functions will follow the new setting.\ntzOffset(20)       // '-04:00'\ntzOffset(-14, -30) // '+09:30'\n\n// Switch back to the default.\nsetTzInRealWorldRange(false) // or setTzInRealWorldRange()\n```\n\nCurious about timezones? Have a look at [the timezone map](https://fr.m.wikipedia.org/wiki/Fichier:World_Time_Zones_Map.png) and the [daylight saving time chaos](https://en.wikipedia.org/wiki/Daylight_saving_time_by_country).\n\n### Timezone configuration\n\nIf you need both timezone configuration functions described in the previous section (`setTzSeparator` for the [hours-minutes separator](#hours-minutes-separator) and `setTzInRealWorldRange` for [timezones boundaries](#real-world-timezone-offset)), you can directly use `setTzConfig()`:\n\n```js\nimport { setTzConfig } from 'datetime-attribute'\n\nsetTzConfig({\n  inRealWorldRange: false, // see `setTzInRealWorldRange`\n  separator: ':', // see `setTzSeparator`\n})\n\n// Switch back to the default.\nsetTzConfig()\n```\n\n## Adding a timezone offset to a moment with `datetimeTz()`\n\nAs `datetime()` doesn’t care about timezones, you can use `datetimeTz()` when you need to be explicit about the timezone of a moment.\n\n💡 `datetimeTz()` is basically a concatenation of [`datetime(date, precision)`](#expressing-moments-with-datetime) and [`tzOffset(hours, minutes)`](#expressing-timezone-offsets-with-tzoffset), so be sure to read about them.\n\nIt accepts the same 5 parameters, all optional:\n\n```js\ndatetimeTz(date, precision, offsetHours, offsetMinutes, inRealWorldRange)\n```\n\n1. A date object (default: `new Date()`)\n2. A [precision keywords](#available-precision-keywords) among:\n    - `time`\n    - `second`\n    - `ms`\n    - `datetime` (default)\n    - `datetime second`\n    - `datetime ms`\n3. Hours offset like in [`tzOffset()`](#expressing-timezone-offsets-with-tzoffset)\n4. Minutes offset like in [`tzOffset()`](#expressing-timezone-offsets-with-tzoffset)\n5. Boundaries of the timezone offset like in [`tzOffset()`](#real-world-timezone-offset)\n\nWhen hours and minutes are not specified, the local timezone offset is used.\n\n```js\nimport { datetime, datetimeTz } from 'datetime-attribute'\n\nconst now = new Date() // We’re 2 April 2021 and it’s 23:51 in Brussels.\n\ndatetime(now)   // '2021-04-02'\ndatetimeTz(now) // '2021-04-02T23:51+02:00'\n\ndatetime(now, 'time')           // '23:51'\ndatetime(now, 'time utc')       // '21:51Z' (same as previous, converted to UTC)\ndatetimeTz(now, 'time', 0)      // '23:51Z' (datetimeTz does not convert)\ndatetimeTz(now, 'time')         // '23:51+02:00' (fall back on local timezone)\ndatetimeTz(now, 'time', 9)      // '23:51+09:00'\ndatetimeTz(now, 'time', -3, 30) // '23:51-03:30'\ndatetimeTz(now, 'time', -14, 0, true) // '23:51+10:00'\n```\n\n`datetimeTz()` **does not convert** your moment to another timezone: it **only adds the wanted timezone** to the moment. Its purpose is to generate a valid `datetime` attribute saying “here’s a moment, it has this [hours, minutes and] timezone offset”.\n\nLet’s take this sentence and its  HTML:\n\n\u003e When I’m in Brussels, I wake up at 8 o’clock every day.\n\n```html\n\u003cp\u003eWhen I’m in Brussels, I wake up \u003ctime datetime=\"08:00+02:00\"\u003eat 8 o’clock\u003c/time\u003e every day.\u003c/p\u003e\n```\n\nHere’s how you can get the `datetime` attribute fitting this sentence:\n\n```js\n// const awakeningAt = new Date(…) // a Date object with 08:00 as time\n\ndatetimeTz(awakeningAt, 'time', 2) // '08:00+02:00'\n```\n\n## Expressing durations with `duration()`\n\n`duration()` requires an object with entries for different levels of durations, from seconds to weeks. It also accepts a second parameter to control the [conversion of units overflow](#units-overflow) (default: `true`).\n\n```js\nimport { duration } from 'datetime-attribute'\n\nconst countdownBeforeBigParty = {\n  w: 3,   //     3 weeks\n  d: 5,   //     5 days\n  h: 10,  //    10 hours\n  m: 43,  //    43 minutes\n  s: 2.61 // 2.610 seconds\n}\n\nduration(countdownBeforeBigParty) // 'P3W5DT10H43M2'\n```\n\nAll object keys are optional:\n\n```js\nduration({ h: 17 }) // 'PT17H'\n```\n\n### Units overflow\n\nValues exceeding a unit are converted to upper units:\n\n```js\nduration({ h: 31, m: 63, s: 175 }) // 'P1DT8H5M55S'\n```\n\nIf you don’t need this behaviour, pass `false` as second parameter (default value: `true`).\n```js\nduration({ m: 175 }) // 'PT2H55M'\nduration({ m: 175 }, false) // 'PT175M'\n```\n\n## The `DateTime` class\n\nThe **`DateTime` class extends the native `Date` object** with methods allowing you to interact with the week number or to output a `datetime` string.\n\n### Constructor\n\nIts constructor remains the same as [the `Date` one](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date).\n\n```js\nimport { DateTime } from 'datetime-attribute'\n\n// One of the many ways to instantiate a `Date`, and this `DateTime`.\nconst summer = new DateTime(2021, 5, 21) // June 21, 2021\n```\n\n### `DateTime.prototype.getWeek()`\n\nReturns the week of the year, giving the same output as [`weekNumber()`](#weeknumber).\n\n```js\nconst summer = new DateTime(2021, 5, 21) // June 21, 2021\n\nsummer.getWeek() // 25\n```\n\n### `DateTime.prototype.setWeek()`\n\nShifts the date to the provided week, while preserving its initial day. In other words, if the initial date is a Friday, then the shifted date remains a Friday.\n\n```js\nconst summer = new DateTime(2021, 5, 21) // June 21, 2021\n\nsummer.setWeek(26) // shifts the date to June 28, 2021\nsummer.getWeek() // now it’s 26\n```\n\n### `DateTime.prototype.to()`\n\nReturns a `datetime` attribute. `DateTime.to()` accepts the same [`precision` keywords](#available-precision-keywords) as [`datetime()`](#expressing-moments-with-datetime).\n\n```js\nconst summer = new DateTime(2021, 5, 21) // June 21, 2021\n\nsummer.to('month') // 2021-06\nsummer.to('yearless') // 06-21\nsummer.to('datetime second') // 2021-06-21T00:00:00\n```\n\n## Other functions\n\nUnder the hood, the core features of `datetime-attribute` uses additional functions that you can also `import` individually.\n\n### `daysBetween()`\n\nCalculate the difference between 2 dates in days, **discarding the time of day**. It subtracts the first `Date` object from the second one.\n\n```js\nimport { daysBetween } from 'datetime-attribute'\n\nconst january1st2021 = new Date(2021, 0, 1, 10, 10, 12)\nconst january11th = new Date(2021, 0, 11, 10, 10, 12)\nconst january19th = new Date(2021, 0, 19, 10, 10, 12)\n\ndaysBetween(january1st2021, january11th) // 10\ndaysBetween(january19th, january11th) // -8\n```\n\n([110 B](https://bundlejs.com/?q=datetime-attribute\u0026treeshake=[{daysBetween}]\u0026config={\"compression\"%3A\"brotli\"}\u0026bundle))\n\n### `weekNumber()`\n\nGet the week number as [defined by the WHATWG](https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#weeks), following the ISO-8601 specs:\n- [a week starts on Monday](https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#concept-week);\n- the first week of the year includes a Thursday;\n- [week numbers go from 1 to 53](https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#week-number-of-the-last-day).\n\nIt accepts a `Date` object.\n\n```js\nimport { weekNumber } from 'datetime-attribute'\n\nconst january1st2021 = new Date(2021, 0, 1, 10, 10, 12)\nconst january11th = new Date(2021, 0, 11, 10, 10, 12)\nconst togoIndependanceDay = new Date(1960, 3, 27)\n\nweekNumber(togoIndependanceDay) // 17\nweekNumber(january1st2021) // 53: it’s a Friday!\nweekNumber(january11th) // 2\n```\n\n([183 B](https://bundlejs.com/?q=datetime-attribute\u0026treeshake=[{weekNumber}]\u0026config={\"compression\"%3A\"brotli\"}\u0026bundle))\n\n## Changelog\n\nSee [CHANGELOG.md](https://github.com/meduzen/datetime-attribute/blob/main/CHANGELOG.md) or the [releases](https://github.com/meduzen/datetime-attribute/releases).\n\n## Browser and tooling support\n\n`datetime-attribute` is provided [as module](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules#browser_compatibility) for [modern browsers usage](https://github.com/meduzen/datetime-attribute/blob/main/browserslist) with standard JavaScript syntax:\n- it is up to you to transpile it for legacy browsers;\n- you can’t import it using `require('datetime-attribute')`;\n- if you don’t transpile it, `DateTime` requires support for [`class` fields](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Public_class_fields#browser_compatibility) (Safari 14.0) starting `v1.32.0`.\n\n[Read more about ESModules](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).\n\n## Not only in `\u003ctime\u003e`\n\n[`\u003ctime\u003e`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/time) is not alone! Other elements can benefit from `datetime-attribute`:\n- `\u003cinput\u003e` of the following types: [`date`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date), [`datetime-local`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/datetime-local), [`month`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/month), [`week`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/week), [`time`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/time): check their `min`, `max`, `value`, `datalist` attributes.\n-  [`\u003cdel\u003e`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/del#attributes) and [`\u003cins\u003e`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ins#attributes) accept a `datetime` attribute.\n- Microdata types: [DateTime](https://schema.org/DateTime) and [Time](https://schema.org/Time) properties.\n- Open Graph [dates properties](https://ogp.me/#datetime): `release_date`, `published_time`, `modified_time` and `expiration_time`.\n- The browser [WebExtensions history search API](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/history/search).\n\n## Security\n\nSee the [security policy](https://github.com/meduzen/datetime-attribute/blob/main/SECURITY.md).\n\n## Contributing\n\nSee the [contributing guidelines](https://github.com/meduzen/datetime-attribute/blob/main/CONTRIBUTING.md).\n\n## License\n\nThe _datetime-attribute_ package is open-sourced software licensed under the [DWTFYWTPL](https://github.com/meduzen/datetime-attribute/blob/main/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeduzen%2Fdatetime-attribute","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmeduzen%2Fdatetime-attribute","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeduzen%2Fdatetime-attribute/lists"}