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#isLeapYear TypeScript Examples
The following examples show how to use
date-fns#isLeapYear.
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: WeekTimeline.tsx From life-calendar with MIT License | 4 votes |
transformData = (data: any = { events: [] }) => {
const _data = JSON.parse(JSON.stringify(data));
let firstEvent: any = {
...DefaultData.events[0],
_date: parseDate(DefaultData.events[0].date)
}; // default 1st event (as the "base" event)
_data.events = _data.events || [];
// for each item, calculate and append more properties:
_data.events = _data.events.map((item: any, idx: number) => {
item._date = parseDate(item.date);
if (idx === 0) {
firstEvent = { ...item };
item._weekNum = 0;
} else {
item._weekNum = differenceInWeeks(item._date, firstEvent._date);
}
return item;
});
// append "Today" to the _data.events (as the last event)
const now = new Date();
_data.events.push({
title: `Today`,
type: 0,
date: format(now, 'yyyy-MM-dd'),
_date: now,
_weekNum: differenceInWeeks(now, firstEvent._date)
});
const firstYear = getYear(firstEvent._date);
let markedWeeks = []; // highlighted boxes - [0, 52, 104, ...] for 90 years
let weeks = 0;
for (let i = 0; i < 90; i += 1) {
const year = firstYear + i;
weeks = weeks + (isLeapYear(year) ? 52.28571 : 52.14286);
let markedWeek = Math.round(weeks);
// adjust for better alignment (because of Math.round and leap years)
markedWeek++;
if (
[
4,
5,
6,
11,
12,
13,
18,
19,
20,
25,
26,
27,
32,
33,
34,
39,
40,
41,
46,
47,
48,
53,
54,
55,
60,
61,
62,
67,
68,
69,
74,
75,
76,
81,
82,
83,
88,
89,
90
].indexOf(i + 1) >= 0
) {
markedWeek = markedWeek - 1;
}
markedWeeks.push(markedWeek); // TODO: rounding leads to inaccurate box position
}
// console.log('markedWeeks', markedWeeks);
return [_data, markedWeeks];
}