Giter VIP home page Giter VIP logo

date-utils's Introduction

Utils

momentjs based date utils.

Installation

CDN

This package published as dateUtils module in umd.

<script src="https://unpkg.com/@termehui/date-utils"></script>

NPM

npm i @termehui/date-utils

Usage

Parse

Parse standard unformatted gregorian date string.

// Signature
function parse(date: string): Moment;

ParseFrom

Parse formatted date from string. For parse jalali date use format params with j prefix (see moment-jalaali).

// Signature
function parseFrom(date: string, format: string): Moment;

// Example
import { parseFrom } from "@termehui/date-utils";
const gregorian = parseFrom("2020-01-12 15", "YYYY-MM-DD HH");
const jalaali = parseFrom("1400-03-19 21", "jYYYY-jMM-jDD HH");

Ago

Get ago string for date.

// Signature
function ago(date: Moment, locale: "fa" | "en"): string;

// Example
import { parse, ago } from "@termehui/date-utils";

const dt = parse("2020-12-03");
console.log(ago(dt, "en")); // 2 days ago
console.log(ago(dt, "fa")); // 2 روز قبل

Humanize

Get humanized duration string.

// Signature
function humanize(
  d: number,
  unit: DurationInputArg2 = "ms",
  locale: "fa" | "en" = "fa"
): string;

// Example
import { humanize } from "@termehui/date-utils";
const ts = 1555638000;
console.log(humanize(ts, "ms", "en")); // 21 days, 7 minutes, 18 seconds
console.log(humanize(ts, "ms", "fa")); // 21 روز و 7 دقیقه و 18 ثانیه

date-utils's People

Contributors

mekramy avatar

Watchers

 avatar

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.