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


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

本文整理汇总了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));
		}
	}
开发者ID:RinMinase,项目名称:anidb,代码行数:26,代码来源:utility.service.ts

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

示例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
    }
}
开发者ID:DroopyTersen,项目名称:droopy-static,代码行数:12,代码来源:azureADAuth.ts

示例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],
开发者ID:vgebrev,项目名称:Tesli,代码行数:31,代码来源:lessons.ts

示例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;
    }
开发者ID:asadsahi,项目名称:AspNetCoreSpa,代码行数:13,代码来源:custom-date-adapter.service.ts

示例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);
  }));
开发者ID:vgebrev,项目名称:Tesli,代码行数:14,代码来源:calendar.component.spec.ts

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

示例8: parse

 public parse(dS:string, f:string, bD:Date):Date {
     return parse(dS, f, bD, this._config);
 }
开发者ID:edcarroll,项目名称:ng2-semantic-ui,代码行数:3,代码来源:date-fns.ts

示例9: parseDate

export function parseDate(rawDate: ParsableDate): Date {
  return parse(rawDate);
}
开发者ID:christophelevis,项目名称:sonarqube,代码行数:3,代码来源:dates.ts

示例10: parse

 parse(value: string, format: string): Date | null {
   const date = dateFnsParse(value, format, new Date());
   return this.isValidDate(date) ? date : null;
 }
开发者ID:ng-lightning,项目名称:ng-lightning,代码行数:4,代码来源:date-fns-adapter.ts


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