Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

since-time-ago-typescript

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

since-time-ago-typescript

typescript package to convert time stamp into a readable format

  • 2.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
decreased by-80%
Maintainers
1
Weekly downloads
 
Created
Source

This fork added Typescript typing and num seconds ago

since-time-ago

npm(scooped)

since-time-ago converts timestamps into readable format

Formats a timestamp to:

  • just now
  • 3 minutes ago
  • 5 hours ago
  • 8 days ago
  • 6 months ago
  • 4 years ago

Install

$ npm i since-time-ago

Use

This module exports a main function 'since()' that takes one argument 'timestamp' and returns timestamp formated in a readable form:

import since from "since-time-ago";

// Timestamps for one minute, one hour, one day, one month and one year
const minute = 60 * 1000;
const hour = 60 * minute;
const day = 24 * hour;
const month = 30 * day;
const year = 12 * month;

// simulating different inputs
const nowTimestamp = new Date().getTime(); // now
const fiveMinutesAgoTimestamp = nowTimestamp - 5 * minute; // timestamp for 5 minutes ago
const fiveHoursAgoTimestamp = nowTimestamp - 5 * hour; // timestamp for 5 hours ago
const fiveDaysAgoTimestamp = nowTimestamp - 5 * day; // timestamp for 5 days ago
const fiveMonthsAgoTimestamp = nowTimestamp - 5 * month; // timestamp for 5 months ago
const fiveYearsAgoTimestamp = nowTimestamp - 5 * year; // timestamp for 5 years ago

// using since()
since(); // returns undefined
since("hello world"); // throws an Error
since(nowTimestamp); // returns 'just now'
since(fiveMinutesAgoTimestamp); // returns '5 minutes ago'
since(fiveHoursAgoTimestamp); // returns '5 hours ago'
since(fiveDaysAgoTimestamp); // returns '5 days ago'
since(fiveMonthsAgoTimestamp); // returns '5 months ago'
since(fiveYearsAgoTimestamp); // returns '5 years ago'

License

MIT

Keywords

FAQs

Package last updated on 01 Oct 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc