Skip to content

daniel-samson/relative-date

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

relative-date

Converts relative date strings into dates. It ports the relative time format from PHP's strtotime relative formats.

Usage

function relativeDate(relativeDateString: string, baseDate?: Date): Date

relativeDateString

The timestamp which is used as a base for the calculation of relative dates.

baseDate (optional)

The date which is used as a base for the calculation of relative dates. when not provided, the current date is used.

Examples

import { relativeDate } from "@danielsamson/relative-date";

console.log(relativeDate("now"));
console.log(relativeDate("1 day ago"));
console.log(relativeDate("+1 week"));
console.log(relativeDate("+1 week 2 days 4 hours 2 seconds"));
console.log(relativeDate("next Thursday"));
console.log(relativeDate("last Monday"));

License

MIT

Generate Parser

npm install
npm start

About

Converts relative dates into dates

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published