sr-dates v1.0.3
sr-dates
Simple package with functions to format and interact with dates (string, dateTime from php, Date instance). 📆
Description
The purpose of this package is to make it easier to use dates in JavaScript.
Getting Started
Dependencies
NPM or Yarn
Installing
npm install sr-dates
yarn add sr-dates
Executing program
Import the functions and use it
import {isDefined} from "sr-dates"
const date = new Date()
isDefined(date)
isDefined
Test if a variable is defined (not undefined and not null)
import {isDefined} from "sr-dates"
const date = new Date()
isDefined(date) => will returns true
formatDate
Return a date with the format "DD/MM/YYYY", the entry format : "YYYY-MM-DDTHH:MM:SS"
import {formatDate} from "sr-dates"
const date = "2020-06-09T06:00:01"
formatDate(date) => will returns "09/06/2020"
formatDateTime
Return a french date with the format "DD/MM/YYYY à HHhMM", the entry format : "YYYY-MM-DDTHH:MM:SS"
import {formatDateTime} from "sr-dates"
const date = "2020-06-09T06:00:01"
formatDateTime(date) => will returns "09/06/2020 à 06h00"
formatDateInstance
Return a date with the format "DD/MM/YYYY", the entry : Date instance
import {formatDateInstance} from "sr-dates"
const date = new Date("2020", "05", "09")
formatDateInstance(date) => will returns "09/06/2020"
formatDateInstanceEN
Return a date with the format "YYYY-MM-DD", the entry : Date instance
import {formatDateInstanceEN} from "sr-dates"
const date = new Date("2020", "05", "09")
formatDateInstanceEN(date) => will returns "2020-06-09"
sortDates
Sort dates
import {sortDates} from "sr-dates"
const dates = [
new Date("2020", "5", "09"),
new Date("2020", "5", "04"),
new Date("2020", "5", "10")
]
sortDates(dates)
=> will returns [
new Date("2020", "5", "04"),
new Date("2020", "5", "09"),
new Date("2020", "5", "10")
]
Authors
Dimitri Dumont - SR Digitale
Version History
1.0.0 : Initial Release
- 1.0.1 : Add readme
- 1.0.2 : Fix tests
- 1.0.3 : Add documentation
License
This project is licensed under the MIT License - see the LICENSE.md file for details