1.2.25 • Published 3 years ago

its-a-date v1.2.25

Weekly downloads
15
License
ISC
Repository
github
Last release
3 years ago

alt tag

When given a Date description, it returns a Date object. No need to know exact date format.

Currently supporting languages:

  • English
  • Russian
  • Arabic
  • Persian
  • Turkish
  • Greek
  • Spanish
  • French
  • Portuguese

Installation

$ npm install its-a-date --save

Code Example

var itsadate = require('its-a-date');

// Mon May 02 2016 05:48:00 GMT+0300 (Jerusalem Daylight Time)`
itsadate.parse("May 2 05:48:29 2016");

// Wed Apr 11 1990 00:45:00 GMT+0300 (Jerusalem Daylight Time)
itsadate.parse("3 months after 11/01/1990");

// Sat Aug 26 1989 02:43:00 GMT+0300 (Jerusalem Daylight Time)
itsadate.parse("10000 days before 11/01/2017")

More Code Examples

Parse Hour & Date

// Fri Aug 19 2016 11:47:00 GMT+0300 (Jerusalem Daylight Time) 
itsadate.parse("11:47");

// Tue Mar 27 2012 14:05:00 GMT+0200 (Jerusalem Standard Time)
itsadate.parse("27.3.2012");

// Tue Mar 27 2012 12:00:00 GMT+0200 (Jerusalem Standard Time)
itsadate.parse("27/3/2012 12:00");

Parse Relatives

// Thu Aug 18 2016 14:05:00 GMT+0300 (Jerusalem Daylight Time)
itsadate.parse("yesterday");

// Thu Aug 18 2016 16:20:00 GMT+0300 (Jerusalem Daylight Time)
itsadate.parse("yesterday at 16:20");

//Fri Aug 19 2011 14:05:00 GMT+0300 (Jerusalem Daylight Time)
itsadate.parse("5 years ago");

// Fri Aug 19 2011 15:44:00 GMT+0300 (Jerusalem Daylight Time)
itsadate.parse("5 years ago at 15:44");

Parse the Extreme (Not Recommended)

When its-a-date doesn't know what date it is, it will return undefined. However many times it surprises.

// Sun Jan 01 1984 14:05:00 GMT+0200 (Jerusalem Standard Time)
itsadate.parse('it was on the 1st of January, ' +
                    'the dark cold winter of 1984');

// undefined
itsadate.parse("pikachu");

Settings, Formats & Time Differences

Use settings to alter the format expected

// Hint its-a-date to prefer mm/dd/yyyy over dd/mm/yyyy
itsadate.settings({'day_before_month':false});

// Thu Nov 01 1990 01:55:00 GMT+0200 (Jerusalem Standard Time)
itsadate.parse("11/1/1990");
// Don't allow its-a-date to guess any other format than specified (day MUST be before month or vise-versa)
itsadate.settings({'strict':true});

You can prevent changing the settings globaly, by delivering it as a second parameter

// November 3rd 2014
itsadate.parse("11-3-2014",{'day_before_month':false});

// Doesn't use prev settings March 11th 2014 
itsadate.parse("11-3-2014");

Restore settings to default

// Restore setting back to default (day_before_month=true)
itsadate.settings().restore();

// Thu Jan 11 1990 01:55:00 GMT+0200 (Jerusalem Standard Time)
itsadate.parse("11/1/1990");

Alter GMT to overcome time difference

// Set GMT+5.5, Mumbai India
itsadate.settings({gmt: 5.5});
itsadate.parse("now");

Learn More

Hit brag() to console out examples of any token implemented

itsadate.brag();

Hit settings() to get settings object with configutations you can alter. descriptions included.

itsadate.settings();

No Exceptions

When date description has inner conflicts it resolves to undefined

// undefined
itsadate.parse('1st of november 02/03/2000')

Motivation

  1. Allows a user to type a date more naturally in a web page or social media.
  2. Allows crawlers to parse relative dates easily.

Strategy (How it works?)

A micro-compiler is implemented. It parses date part tokens & interpret them as modifications on the perceived date.

Upcoming Features

  1. Custom token insertion
  2. More Languages perhaps

Git

https://github.com/bendorshai/its-a-date

1.2.25

3 years ago

1.2.21

3 years ago

1.2.20

4 years ago

1.2.19

4 years ago

1.2.18

4 years ago

1.2.17

4 years ago

1.2.16

4 years ago

1.2.14

4 years ago

1.2.15

4 years ago

1.2.13

5 years ago

1.2.12

5 years ago

1.2.11

5 years ago

1.2.10

6 years ago

1.2.91

6 years ago

1.2.9

6 years ago

1.2.8

6 years ago

1.2.7

6 years ago

1.2.6

6 years ago

1.2.5

7 years ago

1.2.4

7 years ago

1.2.3

7 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

8 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.0.93

8 years ago

0.0.92

8 years ago

0.0.91

8 years ago

0.0.90

8 years ago

0.0.89

8 years ago

0.0.88

8 years ago

0.0.87

8 years ago

0.0.86

8 years ago

0.0.85

8 years ago

0.0.84

8 years ago

0.0.83

8 years ago

0.0.82

8 years ago

0.0.81

8 years ago

0.0.8

8 years ago

0.0.77

8 years ago

0.0.76

8 years ago

0.0.75

8 years ago

0.0.74

8 years ago

0.0.73

8 years ago

0.0.72

8 years ago

0.0.71

8 years ago

0.0.7

8 years ago

0.0.66

8 years ago

0.0.65

8 years ago

0.0.64

8 years ago

0.0.63

8 years ago

0.0.62

8 years ago

0.0.61

8 years ago

0.0.6

8 years ago

0.0.51

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.33

8 years ago

0.0.31

8 years ago

0.0.3

8 years ago

0.0.23

8 years ago

0.0.22

8 years ago

0.0.21

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago