2.0.23 • Published 2 years ago

formatted-time v2.0.23

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

What is this?

This library was made whit the purpose of use easier way to get the date

Installation

npm i formatted-time --save

Then you can do:

import { currentTime, preciseTime } from "formatted-time";

currentTime({ type: "type", format: "format" });
preciseTime({ type: "type", format: "format" || format });

// E.g
currentTime({
  type: "arr",
  format: "Y", // Only strings are supported
});

// Output: [2021]

// E.g
const format = "December 15, 2015, 13:13:31";

preciseTime({
  type: "arr",
  format: format,
});

// Output: [ 2015-12-15T16:15:00.000Z ]

You can change the date to:

By default it will always be returned as a string

  • type: arr
  • type: nmb
  • type: str

CurrentTime Options available

Normal date:

  • currentTime: For the current time
  • today: For the day's date
  • Y: For year
  • M: For month
  • D: For the date
  • d: For the day
  • h: For hours
  • m: For minutes
  • s: For seconds
  • ms: For milliseconds

UTC date:

  • currentTime: For the utc current time
  • today: For the utc day's date
  • uY: For utc year
  • uM: For utc month
  • uD: For utc date
  • ud: For utc day
  • uH: For utc hours
  • um: For utc minutes
  • us: For utc minutes
  • ums: For utc seconds

PreciseTime Options available

Whatever is accepted by the native Date

// E.g

  • December 17, 1995 03:24:00
  • 1995-12-17T03:24:00
  • 1995, 11, 17
  • 1995, 11, 17, 3, 24, 0
  • 628021800000

Get Closer

import { getCloser } from "formatted-time";

First param must be an array whit all the dates
const datesArray = [
  new Date(2015, 0, 1),
  new Date(2016, 0, 1),
  new Date(2017, 0, 1),
  new Date(2010, 0, 1),
];

Second params must be the date that you want to compare
const dateNow = new Date(2021);

function getDate(date) {
  console.log(date);
}

getDate(getCloser(datesArray, dateNow));

// Output: { date: 2017-01-01T03:00:00.000Z, timeLeft: 1483239597979 }

getMax

The param must be an array

  • get the max of the dates given

getMin

The param must be an array

  • get the min of the dates given

ConvertTime

daysConvert

function printData(data){
  console.log(daysToWeeks(data))
  console.log(daysToYears(data))
}
  • days to weeks
  • days to years

hrConvert

function printData(data){
  console.log(hrToMn(data))
  console.log(hrToMs(data))
  console.log(hrToSc(data))
}
  • hours to minutes
  • hours to milliseconds
  • hours to seconds

mnConvert

function printData(data){
  console.log(mnToHr(data))
  console.log(mnToSc(data))
  console.log(mnToMs(data))
}
  • minutes to hours
  • minutes to seconds
  • minutes to milliseconds

msConvert

function printData(data){
  console.log(msToSc(data))
  console.log(msToMinutes(data))
}
  • milliseconds to seconds
  • milliseconds to minutes

yearsConvert

function printData(data){
  console.log(yrsToLuster(data))
  console.log(yrsToCentury(data))
  console.log(yrsToDogYrs(data))
}
  • years to lusters
  • years to century
  • years to dog years

toDate

function printData(data){
  console.log(toDate(data))
}
  • Convert param to date

isAfter

function printData(date1, date2){
  console.log(isAfter(date1, date2)) // True or False
}
  • Checks if a date comes after to another

isBefore

function printData(date1, date2){
  console.log(isBefore(date1, date2)) // True or False
}
  • Checks if a date comes before to another

isDate

function printData(date){
  console.log(isDate(date)) // True or False
}
  • Checks if the param is a date

isPast

function printData(date){
  console.log(isPast(date)) // True or False
}
  • Checks if the date is in the past

isFuture

function printData(date){
  console.log(isFuture(date)) // True or False
}
  • Checks if the date is in the future

itHappened

function printData(date){
  console.log(itHappened(date)) // True or False
}
  • Checks if the date already happened

Week

getDay

function printData(date){
  console.log(getDay(date)) 
}
  • Prints the day of the week of the param given
1.0.6

2 years ago

2.0.15

2 years ago

2.0.3

2 years ago

2.0.16

2 years ago

2.0.2

2 years ago

2.0.13

2 years ago

2.0.5

2 years ago

2.0.14

2 years ago

2.0.4

2 years ago

2.0.11

2 years ago

2.0.7

2 years ago

2.0.12

2 years ago

2.0.6

2 years ago

2.0.9

2 years ago

2.0.10

2 years ago

2.0.8

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

2.0.19

2 years ago

2.0.17

2 years ago

2.0.18

2 years ago

2.0.22

2 years ago

2.0.23

2 years ago

2.0.20

2 years ago

2.0.21

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago