date-fns APIs
- format
- parseISO
- addDays
- subDays
- isAfter
- isBefore
- parse
- add
- startOfDay
- differenceInDays
- addHours
- addMinutes
- isSameDay
- formatDistance
- formatDistanceToNow
- endOfDay
- startOfWeek
- isEqual
- subHours
- getYear
- isToday
- startOfMonth
- differenceInMilliseconds
- addMonths
- eachDayOfInterval
- differenceInSeconds
- getDaysInMonth
- isValid
- endOfMonth
- startOfHour
- differenceInCalendarDays
- getUnixTime
- endOfWeek
- addWeeks
- sub
- toDate
- subMinutes
- fromUnixTime
- getDate
- getDay
- formatISO
- isWithinInterval
- subMonths
- subWeeks
- formatRelative
- differenceInMinutes
- differenceInHours
- getMonth
- getHours
- formatDistanceToNowStrict
- intervalToDuration
- addMilliseconds
- addYears
- endOfYear
- startOfMinute
- subYears
- isSameMonth
- formatDuration
- lightFormat
- setDate
- eachMonthOfInterval
- startOfYear
- isPast
- addSeconds
- isWeekend
- parseJSON
- set
- roundToNearestMinutes
- setMinutes
- differenceInCalendarYears
- max
- isTomorrow
- startOfToday
- isSameYear
- addQuarters
- endOfHour
- endOfQuarter
- startOfQuarter
- subSeconds
- getTime
- compareAsc
- differenceInWeeks
- eachWeekOfInterval
- eachYearOfInterval
- endOfYesterday
- setDay
- getDaysInYear
- formatISODuration
- getMilliseconds
- differenceInCalendarMonths
- lastDayOfMonth
- endOfDecade
- endOfMinute
- startOfDecade
- isThisISOWeek
- startOfTomorrow
- Duration
- startOfYesterday
- isYesterday
- setHours
- getMinutes
- compareDesc
- differenceInCalendarQuarters
- eachHourOfInterval
- eachQuarterOfInterval
- getISODay
- getWeek
- isDate
- isFriday
- isLeapYear
- isMonday
- isSameWeek
- isSaturday
- isSunday
- isThursday
- isTuesday
- isWednesday
- min
- setMonth
- Locale
- millisecondsInHour
- hoursToSeconds
Other Related APIs
- date-fns#format
- date-fns#addHours
- date-fns#startOfDay
- date-fns#isBefore
- date-fns#addMinutes
- date-fns#startOfHour
- date-fns#parseISO
- date-fns#addDays
- date-fns#addMonths
- date-fns#addYears
- date-fns#endOfWeek
- date-fns#endOfMonth
- date-fns#endOfYear
- date-fns#endOfDay
- date-fns#addQuarters
- date-fns#addWeeks
- date-fns#endOfHour
- date-fns#endOfMinute
- date-fns#endOfQuarter
- date-fns#startOfDecade
- date-fns#startOfMinute
date-fns#endOfDecade TypeScript Examples
The following examples show how to use
date-fns#endOfDecade.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: dateUtils.ts From ant-extensions with MIT License | 5 votes |
parseDate = (dt?: string, rounded?: "start" | "end"): ParsedDate => {
if (dt && isDate(dt)) {
return parseISO(dt);
} else if (dt && isDateLike(dt)) {
const parts = getDateParts(dt);
if (parts) {
const { part, op, diff } = parts;
const diffNum = parseInt(`${op}${diff}`, 10);
let date = startOfMinute(new Date());
switch (part) {
case DateParts.NOW:
return date;
case DateParts.DECADE:
if (rounded) {
date = (rounded === "start" ? startOfDecade : endOfDecade)(date);
}
return addYears(date, diffNum * 10);
case DateParts.YEAR:
if (rounded) {
date = (rounded === "start" ? startOfYear : endOfYear)(date);
}
return addYears(date, diffNum);
case DateParts.QUARTER:
if (rounded) {
date = (rounded === "start" ? startOfQuarter : endOfQuarter)(date);
}
return addQuarters(date, diffNum);
case DateParts.MONTH:
if (rounded) {
date = (rounded === "start" ? startOfMonth : endOfMonth)(date);
}
return addMonths(date, diffNum);
case DateParts.WEEK:
if (rounded) {
date = (rounded === "start" ? startOfWeek : endOfWeek)(date);
}
return addWeeks(date, diffNum);
case DateParts.DAY:
if (rounded) {
date = (rounded === "start" ? startOfDay : endOfDay)(date);
}
return addDays(date, diffNum);
case DateParts.HOUR:
if (rounded) {
date = (rounded === "start" ? startOfHour : endOfHour)(date);
}
return addHours(date, diffNum);
case DateParts.MINUTE:
if (rounded) {
date = (rounded === "start" ? startOfMinute : endOfMinute)(date);
}
return addMinutes(date, diffNum);
}
}
}
return undefined;
}