0.1.2 • Published 3 years ago

date-type v0.1.2

Weekly downloads
4
License
MIT
Repository
github
Last release
3 years ago

date-type npm

Build Status Code Climate Test Coverage downloads license

The date type.

Usage

//register the date type to the TypeInfo..
import { Type, DateType } from 'date-type'

expect(Type.get('Date')).toStrictEqual(DateType)

var today = DateType.today()
//var today = new DateType(new Date()).clearTime() //it's the same.
//var today = DateType.now().clearTime() //it's the same.

var nextDay = today.clone().addDays(1)
var FutureType = Type('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

  • The DateType Class
    • Methods:
      • now(): Gets a date type object that is set to the current date time.
      • today(): Gets a date type object that is set to the current date.
        • The time is set to the start of the day (00:00 or 12:00 AM).
      • clearTime(date): Resets the time of the Date object to 12:00 AM (00:00), which is the start of the day.
      • isLeapYear(aYear): Determines if the year whether a LeapYear.
      • getDaysInMonth(aYear, aMonth): Gets the number of days in the month, given a year and month value. Automatically corrects for LeapYear.
  • The DateType Value Class
    • Methods:
      • addYears(value): Adds the specified number of years to this instance.
      • addMonths(value): Adds the specified number of months to this instance.
      • addWeeks(value): Adds the specified number of weeks to this instance.
      • addDays(value): Adds the specified number of days to this instance.
      • clearTime(): Resets the time of this instance to 12:00 AM (00:00), which is the start of the day.
      • isLeapYear(): Determines this date whether a LeapYear.
      • getDaysInMonth(): Gets the number of days in the month. Automatically corrects for LeapYear.
      • equals(value): Compares this instance to another Date object and returns true if they are equal.
      • compareTo(value): Compares this instance to a Date object and returns an number indication of their relative values.
        • return: -1 = this is lessthan date. 0 = values are equal. 1 = this is greaterthan date.

See abstract-type

TODO

License

MIT