Giter Club home page Giter Club logo

timestampy's Introduction

Timestampy

Bunch of utilities useful when working with UNIX timestamps ๐Ÿ•’

Build Status XO Code Style


Highlights

  • Simple API
  • No dependencies
  • Tree Shakeable
  • Written in TypeScript

Install

npm install timestampy

Usage

import {addHours, toDate} from 'timestampy'

addHours(1546344000, {amount: 3}); //=> 1546354800
toDate(1564146357); //=> '7/26/2019'

API

  • Add
    • addSeconds
    • addMinutes
    • addHours
    • addDays
    • addWeeks
    • addMonths
    • addYears
  • Subtract
    • subtractSeconds
    • subtractMinutes
    • subtractHours
    • subtractDays
    • subtractWeeks
    • subtractMonths
    • subtractYears
  • Is
    • isOlderThan
    • isNewerThan
    • isMinuteOld
    • isHourOld
    • isDayOld
    • isWeekOld
    • isFortnightOld
    • isMonthOld
    • isHalfYearOld
    • isYearOld
    • isOldCustom
  • To
    • toDate
    • toTime
  • Other
    • getCurrentTimestamp
    • howOld

Add

addSeconds(timestamp, {options})

Returns a modified timestamp.

timestamp

Type: number

UNIX Timestamp.

options

Type: object

Any of the options below.

amount

Type: number

The amount of seconds you want to add to the timestamp.


addMinutes(timestamp, {options})

Returns a modified timestamp.

timestamp

Type: number

UNIX Timestamp.

options

Type: object

Any of the options below.

amount

Type: number

The amount of minutes you want to add to the timestamp.


addHours(timestamp, {options})

Returns a modified timestamp.

timestamp

Type: number

UNIX Timestamp.

options

Type: object

Any of the options below.

amount

Type: number

The amount of hours you want to add to the timestamp.


addDays(timestamp, {options})

Returns a modified timestamp.

timestamp

Type: number

UNIX Timestamp.

options

Type: object

Any of the options below.

amount

Type: number

The amount of days you want to add to the timestamp.


addWeeks(timestamp, {options})

Returns a modified timestamp.

timestamp

Type: number

UNIX Timestamp.

options

Type: object

Any of the options below.

amount

Type: number

The amount of weeks you want to add to the timestamp.


addMonths(timestamp, {options})

Returns a modified timestamp.

timestamp

Type: number

UNIX Timestamp.

options

Type: object

Any of the options below.

amount

Type: number

The amount of months you want to add to the timestamp.


addYears(timestamp, {options})

Returns a modified timestamp.

timestamp

Type: number

UNIX Timestamp.

options

Type: object

Any of the options below.

amount

Type: number

The amount of years you want to add to the timestamp.


Subtract

subtractSeconds(timestamp, {options})

Returns a modified timestamp.

timestamp

Type: number

UNIX Timestamp.

options

Type: object

Any of the options below.

amount

Type: number

The amount of seconds you want to subtract from the timestamp.


subtractMinutes(timestamp, {options})

Returns a modified timestamp.

timestamp

Type: number

UNIX Timestamp.

options

Type: object

Any of the options below.

amount

Type: number

The amount of minutes you want to subtract from the timestamp.


subtractHours(timestamp, {options})

Returns a modified timestamp.

timestamp

Type: number

UNIX Timestamp.

options

Type: object

Any of the options below.

amount

Type: number

The amount of hours you want to subtract from the timestamp.


subtractDays(timestamp, {options})

Returns a modified timestamp.

timestamp

Type: number

UNIX Timestamp.

options

Type: object

Any of the options below.

amount

Type: number

The amount of days you want to subtract from the timestamp.


subtractWeeks(timestamp, {options})

Returns a modified timestamp.

timestamp

Type: number

UNIX Timestamp.

options

Type: object

Any of the options below.

amount

Type: number

The amount of weeks you want to subtract from the timestamp.


subtractMonths(timestamp, {options})

Returns a modified timestamp.

timestamp

Type: number

UNIX Timestamp.

options

Type: object

Any of the options below.

amount

Type: number

The amount of months you want to subtract from the timestamp.


subtractYears(timestamp, {options})

Returns a modified timestamp.

timestamp

Type: number

UNIX Timestamp.

options

Type: object

Any of the options below.

amount

Type: number

The amount of years you want to subtract from the timestamp.


Is

isOlderThan(firstTimestamp, secondTimestamp)

Returns a boolean of whether the firstTimestamp is older than the secondTimestamp.

firstTimestamp

Type: number

UNIX Timestamp.

secondTimestamp

Type: number

UNIX Timestamp.


isNewerThan(firstTimestamp, secondTimestamp)

Returns a boolean of whether the firstTimestamp is newer than the secondTimestamp.

firstTimestamp

Type: number

UNIX Timestamp.

secondTimestamp

Type: number

UNIX Timestamp.

isMinuteOld(timestamp)

Returns a boolean of whether the timestamp is at least minute old (from now).

timestamp

Type: number

UNIX Timestamp.


isHourOld(timestamp)

Returns a boolean of whether the timestamp is at least an hour old (from now).

timestamp

Type: number

UNIX Timestamp.


isDayOld(timestamp)

Returns a boolean of whether the timestamp is at least a day old (from now).

timestamp

Type: number

UNIX Timestamp.


isWeekOld(timestamp)

Returns a boolean of whether the timestamp is at least week old (from now).

timestamp

Type: number

UNIX Timestamp.


isFortnightOld(timestamp)

Returns a boolean of whether the timestamp is at least 2 weeks (from now).

timestamp

Type: number

UNIX Timestamp.


isMonthOld(timestamp)

Returns a boolean of whether the timestamp is at least month old (from now).

timestamp

Type: number

UNIX Timestamp.


isHalfYearOld(timestamp)

Returns a boolean of whether the timestamp is at 6 months old (from now).

timestamp

Type: number

UNIX Timestamp.


isYearOld(timestamp)

Returns a boolean of whether the timestamp is at least year old (from now).

timestamp

Type: number

UNIX Timestamp.


isOldCustom(timestamp, {options})

Returns a boolean of whether the timestamp is at least year old (from now).

timestamp

Type: number

UNIX Timestamp.

options

Type: object

Any of the options below.

time

Type: number

How old the timestamp should be for the function to return true.


To

toDate(timestamp)

Returns a date extracted from timestamp.

timestamp

Type: number

UNIX Timestamp.


toTime(timestamp)

Returns time extracted from timestamp.

timestamp

Type: number

UNIX Timestamp.


Other

getCurrentTimestamp()

Returns a current UNIX timestamp.


howOld(timestamp)

Returns the amount of second of how old the given timestamp is (from now).

timestamp

Type: number

UNIX Timestamp.


License

MIT ยฉ Antoni Kepinski

Timestamp icon made by Freepik from www.flaticon.com is licensed by CC 3.0 BY

timestampy's People

Contributors

xxczaki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  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.