{"id":13519509,"url":"https://github.com/pragmaticly/smart-time-ago","last_synced_at":"2025-04-04T10:04:20.251Z","repository":{"id":57363975,"uuid":"5099521","full_name":"pragmaticly/smart-time-ago","owner":"pragmaticly","description":"Smart Time Ago is a little jQuery library to update the relative timestamps in your document. ","archived":false,"fork":false,"pushed_at":"2019-12-08T19:41:38.000Z","size":981,"stargazers_count":584,"open_issues_count":18,"forks_count":65,"subscribers_count":42,"default_branch":"master","last_synced_at":"2025-03-28T09:02:56.697Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://pragmaticly.github.com/smart-time-ago/","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/pragmaticly.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-07-18T17:31:43.000Z","updated_at":"2025-03-03T10:47:14.000Z","dependencies_parsed_at":"2022-08-31T00:22:01.888Z","dependency_job_id":null,"html_url":"https://github.com/pragmaticly/smart-time-ago","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pragmaticly%2Fsmart-time-ago","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pragmaticly%2Fsmart-time-ago/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pragmaticly%2Fsmart-time-ago/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pragmaticly%2Fsmart-time-ago/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pragmaticly","download_url":"https://codeload.github.com/pragmaticly/smart-time-ago/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247150183,"owners_count":20892096,"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":[],"created_at":"2024-08-01T05:01:59.933Z","updated_at":"2025-04-04T10:04:20.224Z","avatar_url":"https://github.com/pragmaticly.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","12. 日期格式化 \u0026 时间轴 ##","12. 日期格式化 \u0026 时间轴"],"sub_categories":["10.9 样式修正 ###","10.10 样式修正"],"readme":"Smart Time Ago\n======================\n\nSmart Time Ago is a little jQuery library to update the relative timestamps in your document intelligently. (e.g \"3 hours ago\").\n\nIt's originally built for https://fengche.co/ (Originally Pragmatic.ly).\n\nIt's inspired by another jQuery plugin http://timeago.yarp.com/ but give more flexibility and more intelligently.\n\nInstallation\n------------\n\nYou can use it as a jQuery plugin. \n\n    Just copy the lib/timeago.js or src/timeago.coffee to your project folder then load it after jQuery.\n\nOr if you use node, you can install it from npm.\n  \n    $ npm install -g smart-time-ago\n\nWhy Smart?\n-------------\n\nSmart Time Ago will check and update the relative time every 60000 millisecond (60 seconds) in the scope you specify at the beginning. Latter it will check the newest time in your scope then tune the checking time interval to a proper value. \n\nFor example, if the newest time in the scope you specify is '2 hours ago'. There is no need to check and update the relative time every 60 seconds. Instead, Smart Time Ago will automaticly make the checking time interval longer to 30 minutes.\n\nRules:\n  \n  The newest time is less than 44 minutes, the checking time interval will set to 1 minute.\n\n  The newest time is between 44 and 89 minutes, the checking time interval will set to 22 minutes.\n\n  The newest time is between 90 minutes and 42 hours, the checking time interval will set to 30 minutes.\n\n  The newest time is more than 42 hours, the checking time interval will set to half day.\n\nUsage\n------------\n\nBy default Smart Time Ago will keep watching on the time elements with a class of timeago and a ISO8601 timestamp in datatime attribute:\n\n    \u003ctime class=\"timeago\" datetime=\"2012-07-18T07:51:50Z\"\u003eabout 8 hours ago\u003c/time\u003e\n    \nYou can initialize the smart-time-ago in global like:\n\n    $('body').timeago();\n    \nIt will watch all your relative time elements by only one TimeAgo instance.\n\nOr you can use it in a specify scope like.\n   \n    \u003cdiv class=\"timeLables\"\u003e\n     \u003ctime class=\"timeago\" datetime=\"2012-07-18T07:51:50Z\"\u003eabout 8 hours ago\u003c/time\u003e\n     \u003ctime class=\"timeago\" datetime=\"2012-07-18T06:51:50Z\"\u003eabout 9 hours ago\u003c/time\u003e\n    \u003c/div\u003e\n    \n    $('.timeLables').timeago();\n \nIt will create one TimeAgo instance to update the time elements in the div with timeLables class.\n\nHowever you can also create TimeAgo instance for every time element separately like:\n\n    $('.timeago').timeago();\n\nBTW if you need dynamic add the time element to your document without refreshing the page or you want to refresh the timeago manually. You might need call the refresh function to refresh the instance like:\n\n    $('.timeago').timeago('refresh');\n\n    \nConfiguration\n--------------\n\nThere are some default configuration in Smart Time Ago:\n\n    $.fn.timeago.defaults = {\n      selector: 'time.timeago',\n      attr: 'datetime',\n      dir: 'up',\n      suffix: 'ago'\n    };\n    \nThe 'time.timeago' is the default selector to watch and update.\n\nThe 'datetime' is the default attribute to put the ISO8601 absolute time to parse.\n\nThe 'up' in dir means the elements in your scope is display by time desc. which means if the dir sets to 'up'. Smart Time Ago will treat the first element's time as the newest time to adjust the time interval. Oppositely if it set to 'down', Smart Time Ago will treat the last element's time as the newewst time.\n\n\nThe 'ago' in 'suffix' means the relative generated by Smart Time Ago will look like '3 hours ago'.\nIf you want the text looks like '3 hours from now', you might need change the 'suffix' to 'from now'.\n\nYou can change the default configurations by passing the options to\ntimeago function when initialize timeago like:\n\n    $('.timeago').timeago({selector: 'span.timeago', attr: 'title', dir: 'down', suffix: 'from now'})\n\n\nGem for Rails\n-------------\nThanks [ashchan](https://github.com/ashchan) for writing the ruby gem:\n[timeago-rails](https://github.com/ashchan/timeago-rails)\n\nIf you wanna running Smart Time Ago in Rails, please do check it out. \n\nTODO\n-----\n\nThanks very much if you could contribute.\n\n\nCredits\n-------\n\n![风车协作](https://fengche.co/assets/logo-with-name.png)\n\nSmart Time Ago is maintained and funded by [Fengche.co](https://fengche.co/ \"Fengche.co\").\n\nThanks to all the contributors.\n\nSpecial thanks to [unRob](https://github.com/unRob) for the i18n support.\n\nCopyright (c) 2012 Terry Tai, Fengche.co (terry@fengche.co, https://fengche.co/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpragmaticly%2Fsmart-time-ago","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpragmaticly%2Fsmart-time-ago","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpragmaticly%2Fsmart-time-ago/lists"}