How to use the addMinutes function from date-fns

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

date-fns.addMinutes is a JavaScript function that adds a specified number of minutes to a given date or timestamp, and returns a new Date object representing the resulting date and time.

80
81
82
83
84
85
86
87
88
89
90
  } else if (eligibility === 'INELIGIBLE_TOO_EARLY') {
    startTime = dateFns.addHours(startTime, 1);
  } else if (uuid === aboutToExpireUUID) {
    startTime = dateFns.subMinutes(startTime, 14);
  } else {
    startTime = dateFns.addMinutes(startTime, 15);
  }


  return startTime;
};
fork icon124
star icon219
watch icon0

+ 2 other calls in file

126
127
128
129
130
131
132
133
134
135
function offsetDate(date, timeLength, timeUnit) {
        switch (timeUnit) {
                case 's':
                        return dateTime.addSeconds(date, timeLength);
                case 'm':
                        return dateTime.addMinutes(date, timeLength);
                case 'h':
                        return dateTime.addHours(date, timeLength);
                case 'd':
                        return dateTime.addDays(date, timeLength);
fork icon55
star icon190
watch icon27

How does date-fns.addMinutes work?

date-fns.addMinutes works by taking two arguments: a JavaScript Date object or a Unix timestamp, and a number of minutes to add to the given date. The function first converts the input date or timestamp to a new Date object, and then adds the specified number of minutes to the Date object using the built-in setMinutes method. If the resulting number of minutes is greater than 59, date-fns.addMinutes also adjusts the Date object's hours and days accordingly. Once the new Date object is created and updated, date-fns.addMinutes returns it as the result of the function. Note that date-fns.addMinutes is part of the date-fns library, which provides a set of utility functions for working with dates and times in JavaScript, and supports various date formats and locales.

24
25
26
27
28
29
30
31
32
33

exports.addDaysImpl = dateFns.addDays
exports.addHoursImpl = dateFns.addHours
exports.addISOYearsImpl = dateFns.addISOYears
exports.addMillisecondsImpl = dateFns.addMilliseconds
exports.addMinutesImpl = dateFns.addMinutes
exports.addMonthsImpl = dateFns.addMonths
exports.addQuartersImpl = dateFns.addQuarters
exports.addSecondsImpl = dateFns.addSeconds
exports.addWeeksImpl = dateFns.addWeeks
fork icon0
star icon2
watch icon1

+ 16 other calls in file

286
287
288
289
290
291
292
293
294
295
296


//* Helper functions 
function createAccessToken(user) {
  return {
    tokenType: "Bearer",
    expiresIn: addMinutes(Date.now(), config.auth.jwtExpirationInterval),
    token: createJwt(user._id),
  }
}

fork icon0
star icon1
watch icon1

+ 13 other calls in file

Ai Example

1
2
3
4
5
6
7
8
const { addMinutes } = require("date-fns");

const date = new Date(2022, 2, 31, 10, 0); // March 31, 2022 at 10:00 AM
const minutesToAdd = 30;

const newDate = addMinutes(date, minutesToAdd);

console.log(newDate);

In this example, we first import the addMinutes function from the date-fns library and define a Date object representing March 31, 2022 at 10:00 AM. We then use addMinutes to create a new Date object representing the same date and time, but with 30 minutes added to it. The resulting newDate object is a JavaScript Date object representing March 31, 2022 at 10:30 AM, which can be used for various date and time operations. Note that date-fns.addMinutes can also be used with Unix timestamps and negative values, and can add or subtract different parts of a date and time, such as hours, days, months, and years.

56
57
58
59
60
61
62
63
64
65
const now = new Date();
let remindTime;

switch (time.slice(-1)) {
    case 'm':
        remindTime = addMinutes(now, parseInt(time.slice(0, -1)));
        break;
    case 'h':
        remindTime = addHours(now, parseInt(time.slice(0, -1)));
        break;
fork icon0
star icon0
watch icon0

+ 2 other calls in file

221
222
223
224
225
226
227
228
229
230
      fns.isSameDay(new Date(date), new Date(c.date)) &&
      c.master.id === master
  )
  .map((c) => ({
    start: c.date,
    end: fns.addMinutes(new Date(c.date), c.duration),
  }));

const spaces = utils
  .getFreeTimeRangesGPT(DB.secret.worktime, cards, date)
fork icon0
star icon0
watch icon0

147
148
149
150
151
152
153
154
155
156
157
158
const getIntervals = (start, end, shift) => {
  const result = [];


  while (!fns.isSameHour(start, end) || !fns.isSameMinute(start, end)) {
    result.push(start);
    start = fns.addMinutes(start, shift);
  }
  result.push(end);


  return result;
fork icon0
star icon0
watch icon0

+ 3 other calls in file

22
23
24
25
26
27
28
29
30
temp = dateFns.differenceInHours(y, x);
result = result + temp + ' hours ';
x = dateFns.addHours(x, temp);
temp = dateFns.differenceInMinutes(y, x);
result = result + temp + ' minutes ';
x = dateFns.addMinutes(x, temp);
temp = dateFns.differenceInSeconds(y, x);
let Gresult = result + temp + ' seconds';

fork icon0
star icon0
watch icon0

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