How to use the startOfYear function from date-fns

Find comprehensive JavaScript date-fns.startOfYear code examples handpicked from public code repositorys.

67
68
69
70
71
72
73
74
75
76
}

getCalendar(event, payload) {
  const { locale } = this;
  const year = this.getDate(null, payload);
  const startOfYear = datefns.startOfYear(year);
  const endOfYear = datefns.endOfYear(year);
  const totalDays = datefns.differenceInCalendarDays(endOfYear, startOfYear);

  const days = [];
fork icon28
star icon313
watch icon7

+ 3 other calls in file

52
53
54
55
56
57
58
59
60
61
db.all('SELECT * FROM statistics', [], (selectErr, rows) => {
	if (!rows) return Logger.warn('No statistics found.');

	const startOfBootWeek = dateFns.startOfWeek(new Date(), { weekStartsOn: 1 }), endOfBootWeek = dateFns.endOfWeek(new Date(), { weekStartsOn: 1 });
	const startOfBootMonth = dateFns.startOfMonth(new Date()), endOfBootMonth = dateFns.endOfMonth(new Date());
	const startOfBootYear = dateFns.startOfYear(new Date()), endOfBootYear = dateFns.endOfYear(new Date());

	const thisWeek = rows.filter(row => dateFns.isWithinInterval(dateFns.parseISO(row.date), { start: startOfBootWeek, end: endOfBootWeek }));
	const thisMonth = rows.filter(row => dateFns.isWithinInterval(dateFns.parseISO(row.date), { start: startOfBootMonth, end: endOfBootMonth }));
	const thisYear = rows.filter(row => dateFns.isWithinInterval(dateFns.parseISO(row.date), { start: startOfBootYear, end: endOfBootYear }));
fork icon9
star icon40
watch icon0

166
167
168
169
170
171
172
173
174
175
exports.startOfQuarterImpl = dateFns.startOfQuarter
exports.startOfSecondImpl = dateFns.startOfSecond
exports.startOfTodayImpl = dateFns.startOfToday
exports.startOfTomorrowImpl = dateFns.startOfTomorrow
exports.startOfWeekImpl = dateFns.startOfWeek
exports.startOfYearImpl = dateFns.startOfYear
exports.startOfYesterdayImpl = dateFns.startOfYesterday
exports.subDaysImpl = dateFns.subDays
exports.subHoursImpl = dateFns.subHours
exports.subISOYearsImpl = dateFns.subISOYears
fork icon0
star icon2
watch icon1

+ 16 other calls in file

100
101
102
103
104
105
106
107
108
109
  }, 0);
  return Math.round(sum / forDate.getMonth());
}

async function getGlamMediaCountReport(glam, forDate) {
  const startOfYear = dateFns.startOfYear(forDate);
  const mediacountsQuery = `
    SELECT *
    FROM visualizations_sum
    WHERE access_date BETWEEN '${formatDateForPg(startOfYear)}'
fork icon5
star icon0
watch icon2

+ 3 other calls in file

141
142
143
144
145
146
147
148
149
150
    break;
case 'year':
    subIntervalBreaks = dateFns.eachYearOfInterval(queryInterval);
    if (subIntervalBreaks.length === 0) {
        subIntervalBreaks = [
            dateFns.startOfYear(queryInterval['start']),
            dateFns.addMilliseconds(dateFns.endOfYear(queryInterval['end']), 1)
        ];
        break;
    }
fork icon1
star icon0
watch icon0

282
283
284
285
286
287
288
289
290
291
        type: Date,
        required: false,
    },
},
setup(props, { emit }) {
    const from = vue.computed(() => dateFns.startOfYear(props.pageDate));
    const to = vue.computed(() => dateFns.endOfYear(props.pageDate));
    const format = vue.computed(() => fp.formatWithOptions({
        locale: props.locale,
    })(props.format));
fork icon0
star icon0
watch icon0

+ 9 other calls in file

Other functions in date-fns

Sorted by popularity

function icon

date-fns.format is the most popular function in date-fns (3838 examples)