{"id":13880705,"url":"https://github.com/marcoroth/local-time","last_synced_at":"2025-05-07T10:07:02.637Z","repository":{"id":60476070,"uuid":"543416880","full_name":"marcoroth/local-time","owner":"marcoroth","description":"Modern fork of Basecamp's `local-time`","archived":false,"fork":false,"pushed_at":"2022-11-29T21:48:55.000Z","size":287,"stargazers_count":12,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-31T08:52:07.679Z","etag":null,"topics":["date","datetime","hacktoberfest","javascript","local-time","rails","ruby","time","time-elements"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/marcoroth.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-09-30T03:36:47.000Z","updated_at":"2023-07-10T22:00:58.000Z","dependencies_parsed_at":"2023-01-22T19:15:12.177Z","dependency_job_id":null,"html_url":"https://github.com/marcoroth/local-time","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcoroth%2Flocal-time","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcoroth%2Flocal-time/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcoroth%2Flocal-time/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcoroth%2Flocal-time/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marcoroth","download_url":"https://codeload.github.com/marcoroth/local-time/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232654814,"owners_count":18556470,"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","hacktoberfest","javascript","local-time","rails","ruby","time","time-elements"],"created_at":"2024-08-06T08:03:24.759Z","updated_at":"2025-01-05T23:40:36.065Z","avatar_url":"https://github.com/marcoroth.png","language":"TypeScript","readme":"# Modern Local Time\n\n\u003e This is a modern fork of Basecamp's `local-time` npm package and gem. The original repo can be found here: https://github.com/basecamp/local_time\n\nLocal Time makes it easy to display times and dates to users in their local time. Its Rails helpers render `\u003ctime\u003e` elements in UTC (making them cache friendly), and its JavaScript component immediately converts those elements from UTC to the browser's local time.\n\n## Installation\n\n1. Add `gem 'local_time', github: 'marcoroth/local-time'` to your Gemfile.\n2. If you are using Webpack(er) / esbuild / Vite: Run `yarn add @marcoroth/local-time` to add the npm package to your `package.json` \n2. If you are using Import Maps run `bin/importmap pin @marcoroth/local-time`\n3. Import `LocalTime` from [`@marcoroth/local-time`](https://www.npmjs.com/package/@marcoroth/local-time) in your application's JavaScript bundle.\n\n```js\nimport LocalTime from \"@marcoroth/local-time\"\n\nLocalTime.start()\n```\n\n## Example\n\n```ruby\n\u003e comment.created_at\n\"Wed, 27 Nov 2013 18:43:22 EST -0500\"\n```\n\n```erb\n\u003c%= local_time(comment.created_at) %\u003e\n```\n\nRenders:\n\n```html\n\u003ctime data-format=\"%B %e, %Y %l:%M%P\"\n      data-local=\"time\"\n      datetime=\"2013-11-27T23:43:22Z\"\u003eNovember 27, 2013 11:43pm\u003c/time\u003e\n```\n\nAnd is converted client-side to:\n\n```html\n\u003ctime data-format=\"%B %e, %Y %l:%M%P\"\n      data-local=\"time\"\n      datetime=\"2013-11-27T23:43:22Z\"\n      title=\"November 27, 2013 6:43pm EDT\"\n      data-localized=\"true\"\u003eNovember 27, 2013 6:43pm\u003c/time\u003e\n```\n\n*(Line breaks added for readability)*\n\n## Time and date helpers\n\n```erb\n\u003c%= local_time(time) %\u003e\n```\n\nFormat with a strftime string (default format shown here)\n\n```erb\n\u003c%= local_time(time, '%B %e, %Y %l:%M%P') %\u003e\n```\n\nAlias for `local_time` with a month-formatted default\n\n```erb\n\u003c%= local_date(time, '%B %e, %Y') %\u003e\n```\n\nTo set attributes on the time tag, pass a hash as the second argument with a `:format` key and your attributes.\n\n```erb\n\u003c%= local_time(time, format: '%B %e, %Y %l:%M%P', class: 'my-time') %\u003e\n```\n\nTo use a strftime format already defined in your app, pass a symbol as the format.\n\n```erb\n\u003c%= local_time(date, :long) %\u003e\n```\n\n`I18n.t(\"time.formats.#{format}\")`, `I18n.t(\"date.formats.#{format}\")`, `Time::DATE_FORMATS[format]`, and `Date::DATE_FORMATS[format]` will be scanned (in that order) for your format.\n\nNote: The included strftime JavaScript implementation is not 100% complete. It supports the following directives: `%a %A %b %B %c %d %e %H %I %l %m %M %p %P %S %w %y %Y %Z`\n\n## Time ago helpers\n\n```erb\n\u003c%= local_time_ago(time) %\u003e\n```\n\nDisplays the relative amount of time passed. With age, the descriptions transition from {quantity of seconds, minutes, or hours} to {date + time} to {date}. The `\u003ctime\u003e` elements are updated every 60 seconds.\n\nExamples (in quotes):\n\n* Recent: \"a second ago\", \"32 seconds ago\", \"an hour ago\", \"14 hours ago\"\n* Yesterday: \"yesterday at 5:22pm\"\n* This week: \"Tuesday at 12:48am\"\n* This year: \"on Nov 17\"\n* Last year: \"on Jan 31, 2012\"\n\n## Relative time helpers\n\nPreset time and date formats that vary with age. The available types are `date`, `time-ago`, `time-or-date`, and `weekday`. Like the `local_time` helper, `:type` can be passed a string or in an options hash.\n\n```erb\n\u003c%= local_relative_time(time, 'weekday') %\u003e\n\u003c%= local_relative_time(time, type: 'time-or-date') %\u003e\n```\n\n**Available `:type` options**\n\n* `date` Includes the year unless it's current. \"Apr 11\" or \"Apr 11, 2013\"\n* `time-ago` See above. `local_time_ago` calls `local_relative_time` with this `:type` option.\n* `time-or-date` Displays the time if it occurs today or the date if not. \"3:26pm\" or \"Apr 11\"\n* `weekday` Displays \"Today\", \"Yesterday\", or the weekday (e.g. Wednesday) if the time is within a week of today.\n* `weekday-or-date` Displays the weekday if it occurs within a week or the date if not. \"Yesterday\" or \"Apr 11\"\n\n\n## Configuration\n\n**Internationalization (I18n)**\n\nLocal Time includes a [set of default `en` translations](lib/assets/javascripts/src/local-time/config/i18n.coffee) which can be updated directly. Or, you can provide an entirely new set in a different locale:\n\n```js\nLocalTime.config.i18n[\"es\"] = {\n  date: {\n    dayNames: [ … ],\n    monthNames: [ … ],\n    …\n  },\n  time: {\n    …\n  },\n  datetime: {\n    …\n  }\n}\n\nLocalTime.config.locale = \"es\"\n```\n\n## License\n\nCopyright © 2022 Marco Roth, Copyright © 2013-2018 Javan Makhmali, Basecamp. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.\n","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcoroth%2Flocal-time","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarcoroth%2Flocal-time","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcoroth%2Flocal-time/lists"}