{"id":13393452,"url":"https://github.com/aweary/tinytime","last_synced_at":"2025-05-16T05:06:54.694Z","repository":{"id":16428134,"uuid":"79506115","full_name":"aweary/tinytime","owner":"aweary","description":"⏰ A straightforward date and time formatter in \u003c1kb","archived":false,"fork":false,"pushed_at":"2023-01-12T05:12:08.000Z","size":613,"stargazers_count":1337,"open_issues_count":20,"forks_count":38,"subscribers_count":17,"default_branch":"master","last_synced_at":"2024-10-29T18:08:23.221Z","etag":null,"topics":["date","template","time"],"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/aweary.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-19T23:37:50.000Z","updated_at":"2024-09-18T09:55:10.000Z","dependencies_parsed_at":"2023-01-13T18:50:21.441Z","dependency_job_id":null,"html_url":"https://github.com/aweary/tinytime","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aweary%2Ftinytime","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aweary%2Ftinytime/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aweary%2Ftinytime/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aweary%2Ftinytime/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aweary","download_url":"https://codeload.github.com/aweary/tinytime/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254471061,"owners_count":22076585,"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","template","time"],"created_at":"2024-07-30T17:00:53.078Z","updated_at":"2025-05-16T05:06:53.840Z","avatar_url":"https://github.com/aweary.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","JavaScript (485)","Framework agnostic packages","Dates and Time"],"sub_categories":["Date","Reactive Programming"],"readme":"\n# Tinytime ⏰\n\u003e A straightforward date and time formatter in \u003c800b.\n\n\u003ca href=\"https://www.npmjs.org/package/tinytime\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/v/tinytime.svg?style=flat\" alt=\"npm\"\u003e\n  \u003c/a\u003e \u003ca href=\"https://travis-ci.org/aweary/tinytime\"\u003e\n  \u003cimg src=\"https://travis-ci.org/aweary/tinytime.svg?branch=master\" alt=\"travis\"\u003e\u003c/a\u003e\n\n## API\n\ntinytime exports a single function that returns a template object. This object has a single method, `render`, which\ntakes a `Date` and returns a string with the rendered data.\n\n```js\n\nimport tinytime from 'tinytime';\nconst template = tinytime('The time is {h}:{mm}:{ss}{a}.');\ntemplate.render(new Date());\n// The time is 11:10:20PM.\n```\n\n## Substitutions\n\n * `MMMM` - Full Month (September)\n * `MM` - Partial Month (Sep)\n * `Mo` - Numeric Month (9) \u003csup\u003e1\u003c/sup\u003e\n * `YYYY` - Full Year (1992)\n * `YY` - Partial Year (92)\n * `dddd` - Day of the Week (Monday)\n * `DD` - Day of the Month (24)\n * `Do` - Day (24th)\n * `h` - Hours - 12h format\n * `H` - Hours - 24h format\n * `mm` - Minutes (zero padded)\n * `ss` - Seconds (zero padded)\n * `a` - AM/PM\n \n \u003csup\u003e1\u003c/sup\u003e - you get padded months (`09` instead of `9`) by passing in the `padMonth` option.\n \n ```js\n const template = tinytime('{Mo}', { padMonth: true })\n ```\n\n\n## Efficiency\n\ntinytime takes an approach similar to a compiler and generates an AST representing your template. This AST is generated when\nyou call the main `tinytime` function. This lets you efficiently re-render your template without tinytime having to parse the\ntemplate string again. That means its important that you aren't recreating the template object frequently.\n\nHere's an example showing the right and wrong way to use tinytime with React.\n\nDon't do this:\n\n```jsx\nfunction Time({ date }) {\n  return (\n    \u003cdiv\u003e\n      {tinytime('{h}:{mm}:{ss}{a}').render(date)}\n    \u003c/div\u003e\n  )\n}\n```\n\nInstead, only create the template object once, and just re-render it.\n\n```jsx\nconst template = tinytime('{h}:{mm}:{ss}{a}');\nfunction Time({ date }) {\n  return (\n    \u003cdiv\u003e\n      {template.render(date)}\n    \u003c/div\u003e\n  )\n}\n```\n\n### Babel Plugins\n\nUsing one of the plugins below, you can resolve this efficiency concern at compile time.\n\n[`babel-plugin-transform-tinytime`](http://npm.im/babel-plugin-transform-tinytime) - Hoists `tinytime` calls out of the JSX render scope.\n\n[`babel-plugin-tinytime`](https://www.npmjs.com/package/babel-plugin-tinytime) - Hoists `tinytime` calls out of the current scope, regardless if its inside JSX or a ordinary function scope. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faweary%2Ftinytime","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faweary%2Ftinytime","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faweary%2Ftinytime/lists"}