tarids

Tardis JS

Tardis JS an open source JavaScript Date library for parsing, formatting and processing. A simple, light weight and easy to implement module that you can use in your JS appication or website.

Install

Via NPM: npm i lbx-tardis

or

Include tardis.js in your build directory or link to it directly

<script type="text/javascript" src="tardis.js"></script>

Download tardis.js

Clone it on GitHub

Usage

const getDate = tardis.dateparts() // { year: 119, month: 6, day: 29, hour: 13, min: '04', sec: '12', fullYear: 2019, shortYear: '19', wordYear: 'two thousand and nineteen',  fullMonth: 'June',  shortMonth: 'Jun',....}

const getISO = tardis.ISO() // 2019-06-29

const getTimeStamp = tardis.patterned(1133481000, 'M/DD/YYYY - H:I:s TT tt'); // { pattern: '12/02/2005 - 18:50:{{26}} PM pm', time: 1133481000 }

const getTime = tardis.patterned('2019-06-29T17:26:43', 'M/DD/YYYY - HH:II:SS tt'); //{ pattern: '6/30/2019 - 18:26:43 pm', time: '2019-06-29T17:26:43' }

The Date Object

{
    Day: "03"
    HHour:  "20"
    MMin:  "07"
    MMonth:  "07"
    SSec:  "22"
    TT:  "PM"
    YYear:  "19"
    day:  2
    dayInt:  2
    fullDay:  "Tuesday"
    fullMonth:  "July"
    fullYear:  2019
    hour:  20
    hourInt:  20
    min:  "07"
    minInt:  7
    month:  7
    monthInt:  6
    sec:  "22"
    secInt:  22
    shortDay:  "Tue"
    shortMonth:  "Jul"
    shortYear:  "19"
    timestamp:  1562112442
    tt:  "pm"
    utc:  Tue Jul 02 2019 20:07:22 GMT-0400 (Eastern Daylight Time) {}
    wordHour:  "twenty"
    wordMin:  "seven"
    wordSec:  "twenty two"
    wordYear:  "two thousand and nineteen"
    year:  119
    yearInt:  119
}

Filters

By using a simple mask you can create an unique time format to meet all of your needs. Simply by invoking the patterned method, passing in a time stamp and define a filter pattern. If you do not supply a time stamp the methid will assume you want the current time and return date.Now(). The returned object ({pattern: pattern, time: theTime}) with have your patterned string and the time as a unix time stamp should you need to reuse it.

Mask
Key
Result
Legend
YYYY
thisDate.fullYear
2019
full 4 digit year
YYY
thisDate.wordYear
two thousand and nineteen
full english 4 digit year
YY
thisDate.shortYear
19
truncated string of YYYY
y
thisDate.year
119
integer value, no leading 0, years from 1970
MMMM
thisDate.fullMonth
June
name value of month from months array
MMM
thisDate.shortMonth
Jun
months[date.getMonth()].substr(0, 3)
MM
thisDate.MMonth
06
string value of month with leading 0
M
thisDate.month
6
integer value, no leading 0
m
thisDate.monthInt
6
integer value, no leading 0
DDDD
thisDate.fullDay
Saturday
name value of day or week from Days Array
DDD
thisDat.shortDay
Sat
truncated string of DDDD
DD
thisDate.DDay
06
string value of D with leading 0
D
thisDate.day
6
integer value, no leading 0
D
thisDate.dayInt
1
Day of week counter (Sun = 0, Sat = 6)
HHHH
thisDate.wordHour
nine
string value of english text for a number
HH
thisDate.HHour
09
string value of H with leading 0
H
thisDate.hour
4
integer value, no leading 0
h
thisDate.hourInt
4
integer value, no leading 0
IIII
thisDate.wordSec
twenty one
string value of english text for a number
II
thisDate.MMin
30
string value of I with leading 0
I
thisDate.min
30
integer value, no leading 0
i
thisDate.minInt
30
integer value, no leading 0
SSSS
thisDate.wordMin
thirty three
string value of english text for a number
SS
thisDate.sec
05
string value of S with leading 0
S
thisDate.sec
45
integer value, no leading 0
s
thisDate.secInt
45
integer value, no leading 0
TT
thisDate.hour
AM/PM
meridiem display - upper case
tt
thisDate.hour
am/pm
meridiem display - lower case

Presets

Tardis JS has several prebuilt filter patterns for the most commonly use time formats. Simply, call the method of the preset format you want and set a time stamp. If you do not supply a timestamp, date.Now() will be returned.

tardis.ISO({date})                // 2019-06-30
tardis.ShortDate({date})          // 06/30/2019
tardis.LongDate({date})           // Jun 30 2019
tardis.DayMonthDate({date})       // Thursday,  Decemeber 1, 2005
tardis.MonthDateTime({date})      // Decemeber 1, 2005 18:50
tardis.MonthDateTime12({date})    // Decemeber 1, 2005 6:50 PM
tardis.MonthDate({date})          // Decemeber 1, 2005
tardis.TimeOfDay({date})          // 14:00:53
tardis.TimeOfDay12({date})        // 2:01:31 PM
tardis.Year({date})               // 2019
tardis.Month({date})              // June
tardis.Day({date})                // Sunday