date-type

0.1.2 • Public • Published

date-type npm

Build Status Code Climate Test Coverage downloads license

The date type.

Usage

//register the date type to the TypeInfo..
require('date-type')
var TypeInfo = require('abstract-type')
//get the date type info:
var DateType = TypeInfo('date')
/*
//Just load date type only:
var DateTypeInfo = require('date-type')
var DateType = DateTypeInfo('date')
 */
 
var today = DateType.today()
//var today = DateType.create(new Date()).clearTime() //it's the same.
//var today = DateType.create(Date.now()).clearTime() //it's the same.
 
var nextDay = today.clone().addDays 1
var FutureType = TypeInfo('date', min: nextDay)
 
console.log(today)
//<type "Date": "value":"2016-02-28T04:13:46.352Z">
console.log(today.isValid())
//=true
console.log(today.toJson()))
//='"2016-02-28T04:13:46.352Z"'
console.log(today.toJson({withType:true})))
//='{"value":"2016-02-28T04:13:46.352Z","name":"Date"}'
console.log(FutureType.isValid(nextDay))
//=true
console.log(FutureType.isValid(today))
//=true
var n = nextDay.clone();
n.assign('aaa')
//=TypeError: "aaa" is an invalid Date
console.log(nextDay > today)
//=true

API

See abstract-type

TODO

License

MIT

Package Sidebar

Install

npm i date-type

Weekly Downloads

8

Version

0.1.2

License

MIT

Last publish

Collaborators

  • riceball