10 examples of 'date-fns parseiso' in JavaScript

Every line of 'date-fns parseiso' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
20export default function parseDate(
21 date: string | number | Date,
22 mask = 'default',
23 locale = zhCN
24): Date {
25 if (date instanceof Date) {
26 return date;
27 }
28
29 if (typeof date === 'number') {
30 return new Date(date);
31 }
32
33 mask = mask || 'default';
34
35 const ret = parse(date, mask, locale);
36
37 if (!ret) {
38 return null;
39 }
40
41 return ret;
42}
189public resolveISOString(value: string): number {
190
191 let todayInMS: number = Date.UTC(this.today.getFullYear(), this.today.getMonth(), this.today.getDate());
192 let dt: string[] = value.split("-");
193
194 let year: number, month: number, day: number;
195 if (dt.length >= 3) {
196 year = parseInt(dt[0]);
197 month = parseInt(dt[1]) - 1;
198 day = parseInt(dt[2]);
199 } else if (dt.length >= 2) {
200 month = parseInt(dt[0]) - 1;
201 day = parseInt(dt[1]);
202 } else {
203 day = parseInt(dt[0]);
204 }
205
206 if (month && (month < 0 || month > 12)) throw new Error("Invalid value for month");
207 if (day && (day < 0 || day > 31)) throw new Error("Invalid value for day");
208
209 let inputInMS: number = 0;
210 if (year) {
211 // full date with year (e.g. 2016-10-24)
212 inputInMS = Date.UTC(parseInt(dt[0]), parseInt(dt[1]) - 1, parseInt(dt[2]));
213 } else if (month) {
214 // month and day (eg. 10-24)
215
216 inputInMS = Date.UTC(this.today.getFullYear(), parseInt(dt[0]) - 1, parseInt(dt[1]));
217 } else if (day) {
218 // just a day
219 inputInMS = Date.UTC(this.today.getFullYear(), this.today.getMonth(), parseInt(dt[0]));
220 } else {
221 throw new Error("Failed to parse the date");
222 }
223
224 let result: number = Math.floor((inputInMS - todayInMS) / (1000 * 60 * 60 * 24));
225 return result;
226}
17public static parse(date: any): Date {
18 return moment(date).toDate();
19 //return moment.utc(date).add('milliseconds', timeZoneOffset).toDate();
20}
120function parseDate (date) {
121 date = date.split('-')
122
123 var year = parseInt(date[0])
124 var month = parseInt(date[1]) - 1
125 var day = parseInt(date[2])
126
127 return new Date(year, month, day)
128}
28export function formatDateTimeStringISO(dateTimeString) {
29 if (!dateTimeString) {
30 return blankValue;
31 }
32 const parts = new Intl.DateTimeFormat('en', {
33 year: 'numeric',
34 month: '2-digit',
35 day: '2-digit',
36 hour: '2-digit',
37 minute: '2-digit',
38 second: '2-digit',
39 hour12: false,
40 }).formatToParts(new Date(dateTimeString));
41 const keys = {};
42 for (const {type, value} of parts) {
43 keys[type] = value;
44 }
45 return `${keys.year}-${keys.month}-${keys.day} ${keys.hour}:${keys.minute}:${keys.second}`;
46}
9function date (isostring) {
10 return isostring
11}
46parse(value, formatString) {
47 if (value === '') {
48 return null;
49 }
50
51 return dateFnsParse(value, formatString, new Date());
52}
106getISOTimestamp(date) {
107 return date.toISOString().split('.')[0] + 'Z';
108}
105export function parseDate(d: string): Date {
106 const matches = d.match(/\d+/);
107 return new Date(parseInt(matches![0], 10));
108}
49function parseDateFormat2(str) {
50 // 2010/31/2
51 const m = str.match(/^(\d{4})[/\s.\-,](\d{1,2})[/\s.\-,](\d{1,2})$/);
52 return (m) ? new Date(m[1], m[2] - 1, m[3]) : NaN;
53}

Related snippets