cc-time-ago
v2.1.0
Published
This is a simple module that calculates the time elapsed and has a good partten of displaying the time like "Just Now", "1 Second ago", "2 minutes ago", "2 hours ago" and so on.
Downloads
26
Maintainers
Readme
TinnovAce - Time Ago Module
This is a simple module that calculates the time elapsed by subtracting the time an entry was made from the current time. It has a good pattern of displaying the time like "just now," "1 second ago," "2 minutes ago," "2 hours ago," "1 day ago," "2 weeks ago," "1 month ago," "2 years ago," and so on.
You can also use the compact mode if you want something concise and compact. i.e "1d" instead of "1 day ago" or "1h" instead of "1 hour ago." Check the Compact Mode section for more information.
The module now supports multiple languages for time formatting. You can specify the language you want to use when formatting the time. Check the Languages Supported section for more information.
The module can be useful and integrated into various applications for time formatting, such as in blog posts, comments, user posts, social networks, or literally any app that uses time. The module is constantly being updated and is open source, easy to use, flexible, and scalable.
Installation
To use the module in your project, install it via npm:
npm install cc-time-ago
Usage
Include the module in your project using the import syntax:
const timeAgo = require('cc-time-ago');
The time-ago module has one method, which accepts the time an entry was made in milliseconds as the first argument and an optional second argument for specifying the language. We advise you to use the JavaScript time object with the method now() (e.g., Date.now()).
const entryTime = /* your entry time in milliseconds */;
const formattedTime = timeAgo(entryTime, 'es'); // Pass the language code as the second argument
console.log(formattedTime);
Compact Mode
You can also use the compact mode to get a more concise output:
const compactFormattedTime = timeAgo(entryTime, null, true);
console.log(compactFormattedTime); // Output might be "1h"
Languages Supported
The module supports the following languages for time formatting:
- English (en)
- Spanish (es)
- French (fr)
- German (de)
- Italian (it)
- Japanese (ja)
- Chinese (zh)
- Russian (ru)
- Portuguese (pt)
- Arabic (ar)
- Hindi (hi)
- Turkish (tr)
- Dutch (nl)
You can customize the language by passing the language code as the second argument when using the module. Otherwise it will attempt to detect the user's language automatically and if it fails English will be used as the default language.
Suggesting New Languages
We value your feedback and encourage you to suggest additional languages for time formatting. If there's a language you'd like to see supported, please open an issue in the repository, and we'll do our best to add it in future updates. Your input is essential in making this module more inclusive and versatile.
Contribution
Feel free to contribute to the module. Your pull requests will be reviewed and approved. For any problems encountered or further queries, please raise an issue.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Time Ago Module © 2022 - 2024, a product of TinnovAce.