How to use the getYear function from date-fns

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

118
119
120
121
122
123
124
125
126
127
    const d = Date.parse(date)
    return subDays(d, getDate(d) - 1) // first day of month
  })
).sort(([a], [b]) => compareAsc(Date.parse(a), Date.parse(b)))

const yearGrouped = Object.entries(_.groupBy(monthGrouped, ([date]) => getYear(Date.parse(date)))).sort(([a], [b]) =>
  a.localeCompare(b)
)

return yearGrouped
fork icon3
star icon10
watch icon7

44
45
46
47
48
49
50
51
52
53
var counter = 0

const { jobs, plans } = data
// set init date
const date = new Date()
let year = getYear(date)
// get current month
let currentMonth = getMonth(date)
let currentDays = getDaysInMonth(date)
// get next month
fork icon2
star icon4
watch icon4

+ 3 other calls in file

97
98
99
100
101
102
103
104
105
});

// Extracts the year from a post
eleventyConfig.addNunjucksFilter("year", function (post) {
    if (post && post.date) {
        return getYear(post.date);
    }
    return "n/a";
});
fork icon0
star icon2
watch icon0

87
88
89
90
91
92
93
94
95
96
exports.getMonthImpl = dateFns.getMonth
exports.getOverlappingDaysInRangesImpl = dateFns.getOverlappingDaysInRanges
exports.getQuarterImpl = dateFns.getQuarter
exports.getSecondsImpl = dateFns.getSeconds
exports.getTimeImpl = dateFns.getTime
exports.getYearImpl = dateFns.getYear
exports.isAfterImpl = dateFns.isAfter
exports.isBeforeImpl = dateFns.isBefore
exports.isDateImpl = dateFns.isDate
exports.isEqualImpl = dateFns.isEqual
fork icon0
star icon2
watch icon1

+ 16 other calls in file

51
52
53
54
55
56
57
58
59
60
const QUERY_PARAMS = { maxResults: 1, fields: ["KEY"] }

STATUS.forEach((status) => {
    dateList.forEach((d, ndx) => {
        // sleep(1000).then(() => {
            let y = datefns.getYear(d)
            let m = datefns.getMonth(d)+1
            let day = datefns.getDate(d)

            let nextDay = datefns.addDays(d, 1)
fork icon0
star icon2
watch icon2

+ 3 other calls in file

180
181
182
183
184
185
186
187
188
189
const from = vue.computed(() => dateFns.startOfDecade(props.pageDate));
const to = vue.computed(() => dateFns.endOfDecade(props.pageDate));
const isEnabled = (target, lower, upper) => {
    if (!lower && !upper)
        return true;
    if (lower && dateFns.getYear(target) < dateFns.getYear(lower))
        return false;
    if (upper && dateFns.getYear(target) > dateFns.getYear(upper))
        return false;
    return true;
fork icon0
star icon0
watch icon0

+ 69 other calls in file

136
137
138
139
140
141
142
143
144
145
eleventyConfig.addFilter("readableDate", dateObject => format(dateObject, "MMMM do, yyyy"));
eleventyConfig.addFilter("readableMonth", dateObject => format(dateObject, "MMMM yyyy"));
eleventyConfig.addFilter("removeCategoryFromUrl", url => `/${url.split('/').slice(2, -1).join('/')}/`);
eleventyConfig.addFilter("removeSlugFromUrl", url => `${url.split('/').slice(0, -2).join('/')}/`);
//eleventyConfig.addFilter("urlDate", dateObject => format(dateObject, "yyyyMMddHHmmss"));
eleventyConfig.addFilter("year", dateObject => getYear(dateObject));



/*
fork icon0
star icon0
watch icon0

155
156
157
158
159
160
161
162
163
164
165
    }
  }
}


function findEtat(etats, ref) {
  const refYear = getYear(ref.date_changement_etat);
  const refMonth = getMonth(ref.date_changement_etat);
  const refDay = getDate(ref.date_changement_etat);
  for (const etat of etats) {
    const year = getYear(etat.date_changement_etat);
fork icon0
star icon0
watch icon0

+ 3 other calls in file

30
31
32
33
34
35
36
37
38
39
40
41
};


const toSameDate = (toDate, date) => {
  return fns.setYear(
    fns.setMonth(fns.setDate(toDate, fns.getDate(date)), fns.getMonth(date)),
    fns.getYear(date)
  );
};


const getFreeTimeRangesGPT = (worktime, appointments, date) => {
fork icon0
star icon0
watch icon0

+ 3 other calls in file

81
82
83
84
85
86
87
88
89
90
}

function update_cal(data) {
        const { pos } = data
        let date = setMonth(new Date(), pos)
        current_state.opts.year = getYear(date)
        current_state.opts.days = getDaysInMonth(date)
        current_state.opts.month = getMonth(date)
        adjust_cal_to_month()
}
fork icon0
star icon0
watch icon2

+ 11 other calls in file

30
31
32
33
34
35
36
37
38
39
      const month_name1 = `cal-month-1`
      const days_name1 = `cal-days-1`

const date1 = setMonth(new Date(), current_state.first.pos)
current_state.first.days = getDaysInMonth(date1)
current_state.first.year = getYear(date1)

const cal_month1 = calendarMonth({ pos: current_state.first.pos }, contacts.add(month_name1))
let cal_days1 = calendarDays({
  name: days_name1, 
fork icon0
star icon0
watch icon2

+ 3 other calls in file

25
26
27
28
29
30
31
32
33
34
      const month_name = `month-selector`
      const days_name = `day-selector`

const date = setMonth(new Date(), current_state.pos)
current_state.days = getDaysInMonth(date)
current_state.year = getYear(date)

const cal_month = calendarMonth({ pos: current_state.pos }, contacts.add(month_name))
let cal_days = calendarDays({
  name: days_name, 
fork icon0
star icon0
watch icon0

+ 3 other calls in file

60
61
62
63
64
65
66
67
68
69

const weekList= ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']

const date1 = setMonth(new Date(), current_state.opts.first.pos)
current_state.opts.first.days.count = getDaysInMonth(date1)
current_state.opts.first.year = getYear(date1)

const date2 = setMonth(new Date(), current_state.opts.second.pos)
current_state.opts.second.days.count = getDaysInMonth(date2)
current_state.opts.second.year = getYear(date2)
fork icon0
star icon0
watch icon2

+ 2 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)