- Notifications
You must be signed in to change notification settings - Fork0
Date objects in JavaScript without Time components
License
lwileczek/dateonly
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A drop in replacement for Date objects in JavaScript without a time component.This avoids any hassel having to do with timezones.
Approximately 2kb after being built and minified.
If you find yourself only caring about dates, like a birthday, holiday, or vacation daybut the dates keep getting changed around because of timezones, this library avoidsthe hassel.
This project is in beta. It is stable under the "happy path" usage but still needsto have added validation around inputs.
npm install @patient-otter/dateonly
There are some differences to with built in Date objects
- The default date is
1970-01-01
not the current day. e.g.new DateOnly().toString() // 1970-01-01
- The Constructor only takes numbers, you must use static methods to create froma number, string, or Date object
- The month properties are indexed at 1, so the range is
1-12
where 1 is January12 is December
under construction...
importDateOnlyfrom"@patient-otter/dateonly";constdt=newDateOnly()//1970-01-01dt.setDate(dt.getDate()+12)//1970-01-13dt.toJSON()//1970-01-13T:00:00.000ZconstdateWithTime=newDate();constdateWithouttime=DateOnly.fromDate(dateWithTime);constdateFromString=DateOnly.fromString('06/25/2030');console.log(dateFromString.toString())//'2030-06-25'
- Create a new DateOnly object
- DateOnly
A date object with without time
Param | Type | Default | Description |
---|---|---|---|
[year] | number | 1970 | The year the of the date |
[date] | number | 1 | The year the of the date |
[month] | number | 1 | The year the of the date |
A date object with without time
Kind: global class
Return the year only from the DateOnly
Kind: instance method ofDateOnly
Returns{number}:
Return the month value from the DateOnly.Indexed from 1, 12 is december
Kind: instance method ofDateOnly
Returns{number}:
Return the date value, or the day of the monthIndexed from 1, max of 31 depending the month
Kind: instance method ofDateOnly
Returns{number}:
Return the year only from the DateOnly
Kind: instance method ofDateOnly
Param | Type | Description |
---|---|---|
v | number | The new desired value for the year |
Get day of the week
Kind: instance method ofDateOnly
Return the month value from the DateOnly.Indexed from 1, 12 is december
Kind: instance method ofDateOnly
Param | Type | Description |
---|---|---|
v | number | The new desired value for the value |
Set the date value, or the day of the month
Kind: instance method ofDateOnly
Param | Type | Description |
---|---|---|
v | number | The new desired value for the date |
Set the date value, or the day of the month
Kind: instance method ofDateOnly
Returns{string}: the date represented as a string
Param | Type | Default | Description |
---|---|---|---|
[sep] | string | "-" | The seperator to use between date components |
Return a string in ISO8601 formatAll time values are set to zero
Kind: instance method ofDateOnly
Returns{string}: the date represented as an ISO8601 string
JSON serializes the date to an ISO8601 date
Kind: instance method ofDateOnly
Returns{string}: the date represented as an ISO8601 string
Returns a Date stirng
Kind: instance method ofDateOnly
Returns if the current date time object is valid or not
Kind: instance method ofDateOnly
Crete a DateOnly Object from a number, numbers represent the days since1 Jan 1970
Kind: static method ofDateOnly
Param | Type | Description |
---|---|---|
n | number | The number to be converted to a DateOnly Object |
Create a DateOnly Object from some string. Wraps new Date(str)
Kind: static method ofDateOnly
Param | Type | Description |
---|---|---|
s | string | The string to read the date info from |
Create a DateOnly Object from some string. Wraps new Date(str)
Kind: static method ofDateOnly
Param | Type | Description |
---|---|---|
d | Date | The date to use in creating a new DateOnly object using the date's UTC values |
Create a new DateOnly object for the current date
Kind: static method ofDateOnly
Returns{dateonly}: A donly only object with the current local date
About
Date objects in JavaScript without Time components