本文整理汇总了TypeScript中date-fns.parse函数的典型用法代码示例。如果您正苦于以下问题:TypeScript parse函数的具体用法?TypeScript parse怎么用?TypeScript parse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: autofillYear
autofillYear(date: string) {
if (date.split(" ").length === 2) {
const monthRaw: any = parseInt(date.split(" ")[0]) || date.split(" ")[0];
const day = date.split(" ")[1];
let month: any;
month = (isNaN(monthRaw)) ? this.getMonthByName(monthRaw) : format(parse(monthRaw), "MM");
const yearToday = getYear(new Date());
const dateParsed = `${month}-${day}-${yearToday}`;
const dateParsedUnix = this.getUnix(parse(dateParsed));
const dateTodayUnix = this.getUnix();
if (dateParsedUnix > dateTodayUnix) {
date += ` ${(yearToday - 1).toString()}`;
} else {
date += ` ${yearToday.toString()}`;
}
}
if ((new Date(date)).toString().indexOf("Invalid Date") === 0) {
return this.getUnix();
} else {
return this.getUnix(new Date(date));
}
}
示例2: mapExamInfo
export function mapExamInfo(moduleExam: ModuleExam): ExamInfo {
const { exam_date, start_time, duration } = moduleExam;
const date = parse(`${exam_date} ${start_time} +08:00`, 'yyyy-MM-dd HH:mm XXX', new Date());
return {
examDate: date.toISOString(),
examDuration: duration,
};
/* eslint-enable */
}
示例3: function
export const getTokenFromCache = function() : AuthProps {
try {
var token = JSON.parse(localStorage.getItem(authConfig.cacheKey));
if (parse(token.expires) > new Date()) {
return token;
}
return null;
} catch(e) {
return null
}
}
示例4: Date
date: new Date(2018, 7, 8, 10, 0),
startTime: '10:00',
endTime: '11:00',
lessonAttendees: [{
id: 1,
lessonId: 1,
studentId: students[0].id,
student: students[0],
hasAttended: true,
hasPaid: true,
price: 300
}],
status: 'active',
}, {
id: 2,
date: parse(format(new Date(), 'YYYY-MM-DD 15:00')),
startTime: '15:00',
endTime: '16:00',
lessonAttendees: [{
id: 2,
lessonId: 2,
studentId: students[0].id,
student: students[0],
hasAttended: false,
hasPaid: false,
price: 240
}, {
id: 3,
lessonId: 2,
studentId: students[1].id,
student: students[1],
示例5: fromModel
fromModel(date: Date | string): NgbDateStruct {
if (date instanceof Date) {
return { year: date.getUTCFullYear(), month: date.getUTCMonth() + 1, day: date.getUTCDate() };
}
if (typeof date === 'string') {
const parsedDate = parse(date);
return { year: parsedDate.getUTCFullYear(), month: parsedDate.getUTCMonth() + 1, day: parsedDate.getUTCDate() };
}
return null;
}
示例6: inject
inject([LessonService], (lessonService) => {
const calendarEvent = component.events[0];
const newStart = parse(format(new Date(), 'YYYY-MM-DD'));
const newEnd = addHours(newStart, 1);
let refreshed = false;
component.refresh.subscribe(() => refreshed = true);
component.changeEventTimes({ event: calendarEvent, newStart: newStart, newEnd: newEnd, type: undefined });
expect(calendarEvent.start).toEqual(newStart);
expect(calendarEvent.end).toEqual(newEnd);
expect(refreshed).toBeTruthy();
expect(lessonService.updateLesson).toHaveBeenCalledWith(calendarEvent.meta);
}));
示例7: twitter
async function twitter(topic: string, pathname: string) {
const [_null, username, _type, id] = pathname.split('/')
const { data } = await axios.get('https://api.twitter.com/1.1/statuses/show.json', {
headers: { Authorization: `Bearer ${process.env.TWITTER_BEARER_TOKEN}` },
params: { id },
})
const date = dateFns.parse(data.created_at, 'eee MMM dd HH:mm:ss xxxx yyyy', new Date())
const dir = await uniqueNote(topic, date)
await fs.promises.mkdir(dir, { recursive: true })
async function reducer(acc: Promise<string[]>, { media_url_https, type }: { media_url_https: string; type: string }) {
if (type !== 'photo') return acc
try {
const basename = path.basename(media_url_https)
const image = `${dir}/${basename}`
const writer = fs.createWriteStream(image)
const response = await axios.get(media_url_https, { responseType: 'stream' })
await new Promise((resolve, reject) => {
response.data.pipe(writer)
writer.on('error', reject)
writer.on('finish', resolve)
})
return [...(await acc), basename]
} catch (e) {
console.error(e)
return acc
}
}
if (data.entities && data.entities.media) {
const images = await data.entities.media.reduce(reducer, Promise.resolve([]))
console.log('Downloaded images attached to this tweet:', images)
}
const publishedAt = date.toISOString()
const text = dePants(data.text)
const url = `https://twitter.com${pathname}`
const mdx = `---\npublishedAt: ${publishedAt}\n\ntwitter:\n url: ${url}\n---\n\n${text}\n`
const file = `${dir}/index.mdx`
await fs.promises.writeFile(file, mdx)
console.log(`Imported tweet to: ${file.replace(path.resolve(__dirname, '..'), '')}`)
}
示例8: parse
public parse(dS:string, f:string, bD:Date):Date {
return parse(dS, f, bD, this._config);
}
示例9: parseDate
export function parseDate(rawDate: ParsableDate): Date {
return parse(rawDate);
}
示例10: parse
parse(value: string, format: string): Date | null {
const date = dateFnsParse(value, format, new Date());
return this.isValidDate(date) ? date : null;
}