ExtDate is a simple and lite module to deal with Date object in javascript (and typescript), strongly inspired by Rails "Date" and "Time" objects.
npm install extdate
To import the ExtDate functionality:
import { ExtDate } from 'extdate'
// create ExtDate instance from year, month and day
let date: ExtDate = new ExtDate(2017, 3, 8);
// create ExtDate instance from today's date
let today: ExtDate = new ExtDate();
// create ExtDate instance from javascript's Date object
let dateFromJS: ExtDate = new ExtDate(new Date());
Available instance methods are as follows:
method name | args => return value | description |
---|---|---|
unixTime | () => number | returns unixtime |
miliSecond | () => number | returns the value at 'mili-second' digit |
second | () => number | returns the value at 'second' digit |
minute | () => number | returns the value at 'minute' digit |
hour | () => number | returns the value at 'hour' digit |
day | () => number | returns the value at 'day' digit |
month | () => number | returns the value at 'month' digit |
year | () => number | returns the value at 'year' digit |
dayOfWeek | (format?: string) => string | returns day of week in natural language (in format language) |
dayOfWeekInShort | (format?: string) => string | returns day of week in short in natural language (in format language) |
toArray | () => number[] | returns each digit of the date, [2017, 3, 5, ...] |
method name | args => return value | description |
---|---|---|
nextSecond | (step?: number) => ExtDate | returns ExtDate object of step -second after (step is 1 if nothing given) |
nextMinute | (step?: number) => ExtDate | returns ExtDate object of step -minute after (step is 1 if nothing given) |
nextHour | (step?: number) => ExtDate | returns ExtDate object of step -hour after (step is 1 if nothing given) |
nextDay | (step?: number) => ExtDate | returns ExtDate object of step -day after (step is 1 if nothing given) |
nextWeek | (step?: number) => ExtDate | returns ExtDate object of step -week after (step is 1 if nothing given) |
nextMonth | (step?: number) => ExtDate | returns ExtDate object of step -month after (step is 1 if nothing given) |
nextYear | (step?: number) => ExtDate | returns ExtDate object of step -year after (step is 1 if nothing given) |
prevSecond | (step?: number) => ExtDate | returns ExtDate object of step -second before (step is 1 if nothing given) |
prevMinute | (step?: number) => ExtDate | returns ExtDate object of step -minute before (step is 1 if nothing given) |
prevHour | (step?: number) => ExtDate | returns ExtDate object of step -hour before (step is 1 if nothing given) |
prevDay | (step?: number) => ExtDate | returns ExtDate object of step -day before (step is 1 if nothing given) |
prevWeek | (step?: number) => ExtDate | returns ExtDate object of step -week before (step is 1 if nothing given) |
prevMonth | (step?: number) => ExtDate | returns ExtDate object of step -month before (step is 1 if nothing given) |
prevYear | (step?: number) => ExtDate | returns ExtDate object of step -year before (step is 1 if nothing given) |
beginningOfDay | () => ExtDate | returns ExtDate object of the beginning of the day |
beginningOfWeek | () => ExtDate | returns ExtDate object of the beginning of the week |
beginningOfMonth | () => ExtDate | returns ExtDate object of the beginning of the month |
beginningOfYear | () => ExtDate | returns ExtDate object of the beginning of the year |
endOfDay | () => ExtDate | returns ExtDate object of the end of the day |
endOfWeek | () => ExtDate | returns ExtDate object of the end of the week |
endOfMonth | () => ExtDate | returns ExtDate object of the end of the month |
endOfYear | () => ExtDate | returns ExtDate object of the end of the year |
method name | args => return value | description |
---|---|---|
isSameDay | (date: ExtDate) => boolean | returns whether given 2 days are same or not |
isSameWeek | (date: ExtDate) => boolean | returns whether given 2 days are in a same week or not |
isSameMonth | (date: ExtDate) => boolean | returns whether given 2 days are in a same month or not |
isSameYear | (date: ExtDate) => boolean | returns whether given 2 days are in a same year or not |
method name | args => return value | description |
---|---|---|
strftime | (formatString: string, lang?: string) => string | returns arbitary format of time, lang is used only when day of week (including in short) is embedded |
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
The gem is available as open source under the terms of the MIT License.