当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript date-fns.parseISO函数代码示例

本文整理汇总了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);
  });
开发者ID:nusmodifications,项目名称:nusmods,代码行数:25,代码来源:timetables.test.ts

示例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;
    },
开发者ID:nusmodifications,项目名称:nusmods,代码行数:8,代码来源:timetables.ts

示例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, '..'), '')}`)
  })
}
开发者ID:jeremyboles,项目名称:jeremyboles.com,代码行数:41,代码来源:import.ts

示例4: parseDate

export function parseDate(string: string): Date {
  return parseISO(`${string}T00:00+0800`);
}
开发者ID:nusmodifications,项目名称:nusmods,代码行数:3,代码来源:timify.ts

示例5: format

export const dateFormat = (date: DateType, f: string = 'yyyy-MM-dd') =>
  format(typeof date === 'string' ? parseISO(date) : date, f)
开发者ID:JounQin,项目名称:blog,代码行数:2,代码来源:time.ts

示例6: formatDistance

export const timeAgo = (date: DateType, locale: Locale = Locale.EN) =>
  formatDistance(typeof date === 'string' ? parseISO(date) : date, Date.now(), {
    locale: locales[locale],
  })
开发者ID:JounQin,项目名称:blog,代码行数:4,代码来源:time.ts


注:本文中的date-fns.parseISO函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。