How to use the parseISO function from date-fns

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

date-fns.parseISO is a function that parses a date string in ISO 8601 format and returns a JavaScript Date object.

1771
1772
1773
1774
1775
1776
1777
1778
1779
1780

_buildGradingJobStats(job) {
  if (job) {
    const phases = [];
    const totalDuration = differenceInMilliseconds(
      parseISO(job.graded_at),
      parseISO(job.grading_requested_at)
    );
    const formatDiff = (start, end, addToPhases = true) => {
      const duration = differenceInMilliseconds(parseISO(end), parseISO(start));
fork icon252
star icon248
watch icon14

+ 39 other calls in file

345
346
347
348
349
350
351
352
353
354
}

// Date filtering
if (req.query.from && !req.query.to) {
	requestedStatistics = requestedStatistics.filter(day => {
		const parsedDate = dateFns.parseISO(day.date);
		return dateFns.isWithinInterval(parsedDate, { start: from, end: latestStatisticsEntry });
	});
}
else if (!req.query.from && req.query.to) {
fork icon9
star icon40
watch icon0

+ 19 other calls in file

How does date-fns.parseISO work?

date-fns.parseISO is a function provided by the date-fns library that parses a date string in ISO 8601 format and returns a JavaScript Date object.

The ISO 8601 format is a standardized date and time format that represents dates and times in a human-readable and machine-readable format. The format consists of a combination of date and time components, separated by a T character, and includes time zone information.

To use date-fns.parseISO, you pass an ISO 8601 formatted string as an argument. The function will then parse the string and return a JavaScript Date object representing the parsed date and time.

For example, if you have an ISO 8601 formatted date string like this:

javascript
const isoString = '2023-04-06T13:30:00.000Z';

You can parse it into a JavaScript Date object using date-fns.parseISO like this:

javascript
const parseISO = require('date-fns/parseISO'); const date = parseISO(isoString); console.log(date); // Thu Apr 06 2023 06:30:00 GMT-0700 (Pacific Daylight Time)

In this example, we are using date-fns.parseISO to parse the isoString variable into a JavaScript Date object.

The function returns a Date object representing the date and time specified in the string. The date and time will be converted to the local time zone of the system running the JavaScript code.

The date-fns.parseISO function is useful for situations where you need to parse date strings in ISO 8601 format, such as when working with date and time data from APIs or databases.

14
15
16
17
18
19
20
21
22
  tempDate.setDate(tempDate.getDate() - 1);
  return formatDate(tempDate);
};
const businessRulesDeadline = (decisionDate, appealType, applicationDecision, rawDate = false) => {
  const deadlineDate = rules.appeal.deadlineDate(
    parseISO(decisionDate),
    appealType,
    applicationDecision
  );
fork icon5
star icon4
watch icon10

+ 5 other calls in file

4
5
6
7
8
9
10
11
12
const { parseDate } = require('chrono-node');

module.exports = {
  fmtDuration (start, allowSeconds, end = new Date()) {
    if (typeof start === 'string') {
      start = dfns.parseISO(start);
    }

    const defOpts = ['years', 'months', 'weeks', 'days', 'hours', 'minutes'];
fork icon1
star icon13
watch icon3

Ai Example

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

const isoString = "2023-04-06T13:30:00.000Z";
const date = parseISO(isoString);

console.log(date); // Thu Apr 06 2023 06:30:00 GMT-0700 (Pacific Daylight Time)

In this example, we are using date-fns.parseISO to parse the isoString variable into a JavaScript Date object. We first import the parseISO function from the date-fns library using destructuring assignment. We then pass the isoString variable as an argument to the parseISO function, which parses the string and returns a JavaScript Date object representing the parsed date and time. The resulting date variable contains a Date object representing the date and time specified in the isoString variable. The date and time will be converted to the local time zone of the system running the JavaScript code. This example demonstrates how date-fns.parseISO can be used to easily parse date strings in ISO 8601 format into JavaScript Date objects.

41
42
43
44
45
46
47
48
49
50
onChangeHandler(mutationsList, observer) {
  for (let index = 0; index < mutationsList.length; index++) {
    const mutation = mutationsList[index]

    if (mutation.type === 'childList') {
      const parsedDate = parseISO(this.settings.datetime)
      const overdue = isPast(parsedDate)
      const imminent =
        differenceInMinutes(parsedDate, new Date()) <
        this.settings.imminentOffset
fork icon3
star icon6
watch icon8

45
46
47
48
49
50
51
52
53
54
  )}"`,
  // ContentType: "image/*",
});

const params = new URL(preSignedUrl).searchParams;
const creationDate = parseISO(params.get("X-Amz-Date"));
const expiresInSecs = Number(params.get("X-Amz-Expires"));
const expiryDate = addSeconds(creationDate, expiresInSecs);

return { preSignedUrl, expiryDate };
fork icon0
star icon4
watch icon2

+ 38 other calls in file

36
37
38
39
40
41
42
43
44
            message:"Project not found"
        }
    });
}

const projectStartDate = parseISO(findProject.startDate.toISOString().split("T")[0]);
const projectEndDate = parseISO(findProject.endDate.toISOString().split("T")[0]);
const taskStartDate = parseISO(startDate);
const taskEndDate = parseISO(endDate);
fork icon0
star icon3
watch icon1

+ 175 other calls in file

13
14
15
16
17
18
19
20
21
22
/**
 * dateIsPast
 */

function dateIsPast(date) {
  const parsed = parseISO(date);
  return isBefore(parsed, new Date().getTime());
}

module.exports.dateIsPast = dateIsPast;
fork icon0
star icon3
watch icon2

+ 3 other calls in file

102
103
104
105
106
107
108
109
110
111
  return dateFns.isToday(dateFns.parseISO(reviewDate)) 
         ? dateFns.getHours(new Date()) > 19
         : !dateFns.isFuture(dateFns.parseISO(reviewDate)) &&
         !isMealCancelledOnDate(reviewDate)&&  
         dateFns.differenceInDays(
                dateFns.parseISO(reviewDate),
                dateFns.addDays(new Date() , -5) )
                  <=  5
                   
}
fork icon2
star icon0
watch icon3

+ 3 other calls in file

14
15
16
17
18
19
20
21
22
23
24
}


function processSelectedDate(selectedDate) {
  const dateSelection = getDateSelection(new Date(), parseISO(selectedDate));
  const fromDate = isValidDateSelection(selectedDate, dateSelection)
    ? parseISO(selectedDate)
    : startOfMonth(new Date());
  const endOfSelectedMonth = endOfMonth(fromDate);
  const toDate = !isFuture(endOfSelectedMonth)
    ? endOfSelectedMonth
fork icon2
star icon2
watch icon0

646
647
648
649
650
651
652
653
654
655
656
  return isAppearance ? true : false;
};


// returns true if special's release date is after today's date
const isSpecialNotOutYet = (special) => {
  const specialDate = parseISO(special.release_date);
  const today = new Date();
  return isAfter(specialDate, today) ? true : false;
};

fork icon0
star icon2
watch icon1

+ 314 other calls in file

117
118
119
120
121
122
123
124
125
126
127
128
129
};


const parseDate = value => {
  if (dateFns.isDate(value)) return dateFns.format(value, 'yyyy-MM-dd');
  try {
    let date = dateFns.parseISO(value);


    if (dateFns.isValid(date)) return dateFns.format(date, 'yyyy-MM-dd');


    throw new InvalidDateError(`Invalid format, expected an ISO compatible date`);
fork icon0
star icon0
watch icon1

+ 93 other calls in file

12
13
14
15
16
17
18
19
20
    new Date(),
    localeString ? { locale: locale[localeString.replace("-", "")] } : undefined,
  );
}
else {
  dateValue = parseISO(
    stringValue,
  );
}
fork icon0
star icon0
watch icon1

+ 6 other calls in file

132
133
134
135
136
137
138
139
140
141
142
143


function isExpired(url) {
    const params = new Proxy(new URLSearchParams(url), {
        get: (searchParams, prop) => searchParams.get(prop),
    });
    const creationDate = parseISO(params['X-Amz-Date']);
    const expiresInSecs = Number(params['X-Amz-Expires']);


    const expiryDate = addSeconds(creationDate, expiresInSecs);

fork icon0
star icon0
watch icon1

+ 11 other calls in file

63
64
65
66
67
68
69
70
71
72
if (key == "pageno" || key == "limit" || key == "atime" || key == "etime" || key == "stdcont")
	continue;
if (["batch._id", "center._id", "teacher._id"].includes(key))
	Filter.push({ [key]: ObjectId(req.query[key]) });
else if (key == "start_time") {
	Filter.push({ start_time: { $gte: parseISO(req.query[key]) } });
} else if (key == "end_time") {
	Filter.push({ start_time: { $lt: add(parseISO(req.query[key]), { days: 1 }) } });
} else if (key == "topics") {
	temp = req.query[key]?.split(",").map((item) => ({ "topics": item }));
fork icon0
star icon0
watch icon1

+ 33 other calls in file

28
29
30
31
32
33
34
35
36
37
else if (key.includes("courses")) {
	(req.query[key].split(',')).map(val => {
		Arr.push({ [key]: ObjectId(val) })
	});
} else if (key == "date") {
	let date = parseISO(req.query[key]);
	let date2 = add(date, { days: 1 });
	temp.push({ "followup_list.date": { $gte: date, $lt: date2 } });
}
else temp.push({ [key]: { $regex: req.query[key] } });
fork icon0
star icon0
watch icon1

+ 33 other calls in file

130
131
132
133
134
135
136
137
138
139

eleventyConfig.addFilter("day", dateObject => getDate(dateObject));
eleventyConfig.addFilter("machineDate", dateObject => formatISO(dateObject, { representation: "date" }));
eleventyConfig.addFilter("month", dateObject => getMonth(dateObject) + 1);
eleventyConfig.addFilter("padZeroes", (number, zeroes) => number.toString().padStart(zeroes, '0'));
eleventyConfig.addFilter("parseDate", dateString => parseISO(dateString));
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('/')}/`);
fork icon0
star icon0
watch icon0

372
373
374
375
376
377
378
379
380
381
382
383
function isLeapYear(year) {
  return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
}


function as_date(str) {
  return datefns.parseISO(str + "T01:00:00.000Z");
}


function date_format(date) {
  return as_date(date).toDateString();
fork icon0
star icon0
watch icon0

2
3
4
5
6
7
8
9
10
11
12
13
const inspector = require('./controllers/modules/tenant/billing_inspector');//move to listing module folder
const handler = require('./controllers/modules/utils/handle');
const promise_query = require('./controllers/modules/utils/promise_connection');


var readline = require('readline');
var today = datefns.parseISO("2019-01-01Tnnn00:00:00.000Z");
var rl = readline.createInterface(process.stdin, process.stdout);


//correctly generate rent, other and late payments for lease duration

fork icon0
star icon0
watch icon0

4
5
6
7
8
9
10
11
12
13
14
15
16
17
const dateRegex = /^\d{4}[\/\-](0[1-9]|1[012])[\/\-](0[1-9]|[12][0-9]|3[01])$/;


const checkIfOverdue = (dueDate) => {
  if (!dateRegex.test(dueDate)) return 'Date must be YYYY-MM-DD';


  const due = dateFns.parseISO(dueDate);


  const isOverDue = dateFns.isPast(due);


  const distanceFromToday = dateFns.formatDistanceToNowStrict(due, {
fork icon0
star icon0
watch icon0

Other functions in date-fns

Sorted by popularity

function icon

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