{"id":22423310,"url":"https://github.com/prantlf/datetime-placeholder","last_synced_at":"2025-03-27T05:40:39.077Z","repository":{"id":143569777,"uuid":"616102840","full_name":"prantlf/datetime-placeholder","owner":"prantlf","description":"Simplifies a date/time-formatting pattern using Unicode LDML tokens to a pattern usable in date/time pickers.","archived":false,"fork":false,"pushed_at":"2023-12-10T18:34:32.000Z","size":81,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-04T09:39:27.415Z","etag":null,"topics":["date","date-picker","date-time","datepicker","datetime","datetime-picker","datetimepicker","format","intl","ldml","pattern","picker","placeholder","time","unicode"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/prantlf.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-03-19T16:09:13.000Z","updated_at":"2023-03-19T18:31:59.000Z","dependencies_parsed_at":"2023-05-18T00:45:33.624Z","dependency_job_id":null,"html_url":"https://github.com/prantlf/datetime-placeholder","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prantlf%2Fdatetime-placeholder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prantlf%2Fdatetime-placeholder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prantlf%2Fdatetime-placeholder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prantlf%2Fdatetime-placeholder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/prantlf","download_url":"https://codeload.github.com/prantlf/datetime-placeholder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245791898,"owners_count":20672667,"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","date-picker","date-time","datepicker","datetime","datetime-picker","datetimepicker","format","intl","ldml","pattern","picker","placeholder","time","unicode"],"created_at":"2024-12-05T18:09:58.122Z","updated_at":"2025-03-27T05:40:39.057Z","avatar_url":"https://github.com/prantlf.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DateTime Pattern Placeholder\n\n[![Latest version](https://img.shields.io/npm/v/datetime-placeholder)\n ![Dependency status](https://img.shields.io/librariesio/release/npm/datetime-placeholder)\n](https://www.npmjs.com/package/datetime-placeholder)\n[![Coverage](https://codecov.io/gh/prantlf/datetime-placeholder/branch/master/graph/badge.svg)](https://codecov.io/gh/prantlf/datetime-placeholder)\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/9f1034029c0747a980cd49f64f16338b)](https://www.codacy.com/app/prantlf/datetime-placeholder?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=prantlf/datetime-placeholder\u0026amp;utm_campaign=Badge_Grade)\n\nSimplifies a date/time-formatting pattern using [Unicode LDML] tokens to a pattern usable in date/time pickers.\n\nAlthough [Unicode LDML] is a widely accepted standard for tokens in date/time formatting patterns, the variety of the tokens is not comprehensible, when presented in a date/time picker to an end-user. Patterns presented as value placeholders can be simpler, because the parser accepts more variants of the input form of a date/value part.\n\n| Locale | Formatting pattern  | Picker placeholder          |\n|:-------|:--------------------|:----------------------------|\n| en     | M/d/yy, h:mm a      | mm/dd/yy, hh:mm aa          |\n| cs     | d. MMMM y H:mm:ss z | dd. mmm yyyy hh:mm:ss zz    |\n\n```js\nconst placeholder = simplifyDateTimePattern('d.M.yy') // dd.mm.yy\n```\n\n* ES, CJS and UMD module exports.\n* TypeScript type declarations (typings).\n* No other dependencies.\n* Tiny code base - 2.05 kB minified, 942 B gzipped, 834 B brotlied.\n\nRelated projects:\n\n* [date-and-time-formatter] - formats a date/time value to a localised string using a pattern consisting of [Unicode LDML] tokens.\n* [datetime-locale-patterns] - provides localized date/time format patterns for styles `full`, `long`, `medium` and `short` using [Unicode CLDR], compliant with [Unicode LDML].\n* [intl-datetimeformat-options] - provides localized date/time format patterns for styles `full`, `long`, `medium` and `short`, using [`Intl.DateTimeFormat`].\n* [intl-datetimeformat-pattern] - creates a valid [`Intl.DateTimeFormat`] options object from a [Unicode CLDR] skeleton or token pattern.\n\n## Installation\n\nThis module can be installed in your project using [NPM], [PNPM] or [Yarn]. Make sure, that you use [Node.js] version 16.14 or newer.\n\n```sh\n$ npm i datetime-placeholder\n$ pnpm i datetime-placeholder\n$ yarn add datetime-placeholder\n```\n\nFunctions are exposed as named exports from ES and CJS modules, for example:\n\n```js\nimport { simplifyDateTimePattern } from 'datetime-placeholder'\n```\n\n```js\nconst { simplifyDateTimePattern } = require('datetime-placeholder')\n```\n\nA UMD module can be loaded to the browser either directly:\n\n```html\n\u003cscript src=\"https://unpkg.com/datetime-placeholder@1.0.0/lib/index.min.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n  const { simplifyDateTimePattern } = window.dateTimePlaceholder\n\u003c/script\u003e\n```\n\nOr using an AMD module loader:\n\n```html\n\u003cscript\u003e\n  require([\n    'https://unpkg.com/datetime-placeholder@1.0.0/lib/index.min.js'\n  ], ({ simplifyDateTimePattern }) =\u003e {\n    ...\n  })\n\u003c/script\u003e\n```\n\n## API\n\n### simplifyDateTimePattern(pattern, options?)\n\nReturns a simplified pattern to show to the end-user in a date/time picker.\n\nThe **pattern** argument must be a date/time-formatting pattern using [Unicode LDML] tokens.\n\n```js\nimport { simplifyDateTimePattern } from 'datetime-placeholder'\n\nconst placeholder = simplifyDateTimePattern('M/d/yy')\nconsole.log(placeholder) // prints 'mm/dd/yy'\n```\n\n### simplifyDateTimePatternToParts(pattern, options?)\n\nReturns a simplified pattern to show to the end-user in a date/time picker as an array of parts, which values are supposed to be concatenated together.\n\nThe **pattern** argument must be a date/time-formatting pattern using [Unicode LDML] tokens.\n\n```js\nimport { simplifyDateTimePatternToParts } from 'datetime-placeholder'\n\nconst placeholder = simplifyDateTimePatternToParts('M/d/yy')\nconsole.log(placeholder) // prints the following:\n// [{ type: 'month', value: 'mm',\n//    type: 'literal', value: '/',\n//    type; 'day', value: 'dd',\n//    type: 'literal', value: '/',\n//    type: 'year': value: 'yy' }]\n```\n\n### Options\n\nThe pattern simplification can be customised by an optional parameter - an object with the following properties:\n\n| Name         | Default       | Description |\n|:-------------|:--------------|:------------|\n| `letterCase` | `'lowercase'` | if the pattern should be rendered lowercase (`'lowercase'`) or uppercase (`'uppercase'`) |\n\n\n## Pattern Conversion\n\nThe characters wrapped between two single quotes characters (`'`) are escaped.\nTwo single quotes in a row, whether inside or outside a quoted sequence,\nrepresent a \"real\" single quote. (see the last example)\n\nThe input pattern is based on [Unicode Technical Standard #35].\nOnly those tokens are supported, which can appear in patterns for formatting\ninstances of `Date` by [`Intl.DateTimeFormat`]. For example, only the \"formatting\"\nvariant of a token (M, E) is supported, not the \"stand-alone\" one (L, i).\n(\"Formatting\" means declined according to the rules of the language\n in the context of a date. \"Stand-alone\" means always nominative singular.)\n\nAccepted patterns:\n\n| Unit                         | Pattern | Placeholder | Meaning      |\n|------------------------------|---------|-------------|--------------|\n| Era                          | G...    | ee          | era          |\n| Calendar year                | y       | yyyy        | full year    |\n|                              | yy      | yy          | 2-digit year |\n|                              | yyy...  | yyyy        | full year    |\n| Month                        | M | MM  | mm          | month number |\n|                              | MMM...  | mmm         | month name   |\n| Day of month                 | d | dd  | dd          | day number   |\n| Day of week                  | E...    | www         | weekday name |\n| AM, PM                       | a...    | aa          | AM/PM        |\n| AM, PM, noon, midnight       | b...    | aa          |              |\n| Flexible day period          | B...    | aa          |              |\n| Hour [1-12]                  | h | hh  | hh          | hours        |\n| Hour [0-23]                  | H | HH  | hh          |              |\n| Hour [0-11]                  | K | KK  | hh          |              |\n| Hour [1-24]                  | k | kk  | hh          |              |\n| Minute                       | m | mm  | mm          | minutes      |\n| Second                       | s | ss  | ss          | seconds      |\n| Fraction of second           | S...    | mmm         | milliseconds |\n| Timezone (ISO-8601 w/ Z)     | X...    | zz          | time zone    |\n| Timezone (ISO-8601 w/o Z)    | x...    | zz          |              |\n| Timezone (GMT)               | O...    | zz          |              |\n| Timezone (specific non-loc.) | z...    | zz          |              |\n\nAlthough some placeholders are the same, their meaning is clear from the context within the pattern, because people know how to write down a date/time value.\n\n### Examples\n\n```js\n// Represent 11 February 2014 in middle-endian format\nsimplifyDateTimePattern('MM/dd/yyyy')\n//=\u003e 'mm/dd/yyyy'\n```\n\n```js\n// Escape string by single quote characters\nsimplifyDateTimePattern(\"h 'o''clock'\", { letterCase: 'uppercase' })\n//=\u003e \"HH o'clock\"\n```\n\n## Contributing\n\nIn lieu of a formal styleguide, take care to maintain the existing coding style.  Add unit tests for any new or changed functionality. Lint and test your code using Grunt.\n\n## License\n\nCopyright (c) 2023 Ferdinand Prantl\n\nLicensed under the MIT license.\n\n[Node.js]: http://nodejs.org/\n[NPM]: https://www.npmjs.com/\n[PNPM]: https://pnpm.io/\n[Yarn]: https://yarnpkg.com/\n[date-and-time-formatter]: https://github.com/prantlf/date-and-time-formatter\n[datetime-locale-patterns]: https://github.com/prantlf/datetime-locale-patterns\n[intl-datetimeformat-pattern]: https://github.com/caridy/intl-datetimeformat-pattern\n[intl-datetimeformat-options]: https://github.com/prantlf/intl-datetimeformat-options\n[Unicode LDML]: https://unicode.org/reports/tr35/\n[Unicode CLDR]: https://cldr.unicode.org/\n[`Intl.DateTimeFormat`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat\n[Unicode Technical Standard #35]: https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprantlf%2Fdatetime-placeholder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprantlf%2Fdatetime-placeholder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprantlf%2Fdatetime-placeholder/lists"}