本文整理汇总了TypeScript中date-fns.parseISO函数的典型用法代码示例。如果您正苦于以下问题:TypeScript parseISO函数的具体用法?TypeScript parseISO怎么用?TypeScript parseISO使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parseISO函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: test
test("should return false if the lesson's Weeks does not match the week number", () => {
expect(
testLessonAvailable(
[1, 3, 5, 7, 9, 11],
// Week 5
parseISO('2017-09-11'),
),
).toBe(true);
expect(
testLessonAvailable(
[1, 2, 3],
// Week 4
parseISO('2017-09-04'),
),
).toBe(false);
expect(
testLessonAvailable(
[1, 3, 5, 7, 9, 11],
// Week 5
parseISO('2017-09-11'),
),
).toBe(true);
});
示例2: minDate
(weekRange) => {
const end = minDate([parseISO(weekRange.end), date]);
for (let current = parseISO(weekRange.start); current <= end; current = addDays(current, 7)) {
if (isEqual(current, date)) return true;
}
return false;
},
示例3: instagram
async function instagram(topic: string, pathname: string) {
const [_null, _p, id] = pathname.split('/')
const { data } = await axios.get(`https://www.instagram.com${pathname}`)
const $ = cheerio.load(data)
const json = $('script[type="application/ld+json"]').html()
if (!json) {
console.error(`Photo data was not found for: ${path}`)
process.exit(1)
return
}
const schema = JSON.parse(json)
const date = dateFns.parseISO(schema.uploadDate)
const alt = `A photo taken in ${schema.contentLocation.name}`
const publishedAt = date.toISOString()
const text = dePants(schema.caption)
const url = `https://www.instagram.com${pathname}`
const mdx = `---\npublishedAt: ${publishedAt}\n\ninstagram:\n url: ${url}\n---\n\n<!-- prettier-ignore-start -->\n! ![${alt}](${id}.jpg)\n! ${text}\n\n<!-- prettier-ignore-end -->\n`
const dir = await uniqueNote(topic, date)
await fs.promises.mkdir(dir, { recursive: true })
const file = `${dir}/index.mdx`
await fs.promises.writeFile(file, mdx)
const image = `${dir}/${id}.jpg`
const writer = fs.createWriteStream(image)
const response = await axios.get(`https://www.instagram.com${pathname}media?size=l`, { responseType: 'stream' })
response.data.pipe(writer)
writer.on('error', console.error)
writer.on('finish', () => {
console.log(`Imported Instagram post to: ${file.replace(path.resolve(__dirname, '..'), '')}`)
})
}
示例4: parseDate
export function parseDate(string: string): Date {
return parseISO(`${string}T00:00+0800`);
}
示例5: format
export const dateFormat = (date: DateType, f: string = 'yyyy-MM-dd') =>
format(typeof date === 'string' ? parseISO(date) : date, f)
示例6: formatDistance
export const timeAgo = (date: DateType, locale: Locale = Locale.EN) =>
formatDistance(typeof date === 'string' ? parseISO(date) : date, Date.now(), {
locale: locales[locale],
})