Code Monkey home page Code Monkey logo

fluent-date's Introduction

fluent-date

npm version npm downloads

支持 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

  1. Only support English and Chinese for now
  2. Only support past dates (will be in the next version)
  3. 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

  1. 中文 Chinese
  2. 英文 English
  3. 日文 Japanese (wip)
  4. 佛文 Buddism(wip)

Bug reports

Please open an issue describing your bug.

Feature requests

Please open an issue for new feature requests.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.