fluent-date
v1.0.2
Published
A multi-language (Chinese, English) fluent date parser (relative time, duration).
Downloads
1
Maintainers
Readme
fluent-date
支持 TypeScript,JavaScript 的多语言通顺时间翻译器
A multi-language (Chinese, English) fluent date parser with native TypeScript and JavaScript support.
Format a date to:
- just now
- 3 seconds ago
- 6 minutes ago
- 1 hour ago
- 2 weeks ago
- 4 months ago
- 5 years ago
支持中文:
- 刚刚
- 3 秒前
- 6 分钟前
- 1 小时前
- 2 周前
- 4 月前
- 5 年前
Limitation
Those are the limitations for the latest version. Those features will be released in the future
- Only support English and Chinese for now
- Only support past dates (will be in the next version)
- Only support built-in phrases. (Customization will be released soon)
Install
$ npm install fluent-date
Usage
TypeScript
import { FluentDate, Language } from "fluent-date";
// English
const enFd = new FluentDate(); // The default language is English
console.log(enFd.relative(Date.now() - 60 * 1000 + 1)); // 59 seconds ago
console.log(enFd.relative(Date.now())); // just now
// Chinese
const zhFd = new FluentDate(Language.ZH);
console.log(zhFd.relative(Date.now() - 7200 * 1000 + 1)); // 1 小时前
console.log(zhFd.relative(Date.now())); // 刚刚
JavaScript
const { FluentDate, Language } = require("fluent-date");
// English
const enFd = new FluentDate(); // The default language is English
console.log(enFd.relative(Date.now() - 60 * 1000 + 1)); // 59 seconds ago
console.log(enFd.relative(Date.now())); // just now
// Chinese
const zhFd = new FluentDate(Language.ZH);
console.log(zhFd.relative(Date.now() - 7200 * 1000 + 1)); // 1 小时前
console.log(zhFd.relative(Date.now())); // 刚刚
Upcoming features
自定义时间尺度 Configurable time scale
多语言支持 Multi-language support
- 中文 Chinese
- 英文 English
- 日文 Japanese (wip)
- 佛文 Buddism(wip)
Bug reports
Please open an issue describing your bug.
Feature requests
Please open an issue for new feature requests.