@angular/common#formatDate TypeScript Examples

The following examples show how to use @angular/common#formatDate. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: data-store.service.ts    From mylog14 with GNU General Public License v3.0 6 votes vote down vote up
private getRecordsByDate(records: Record[]): RecordsByDate {
    const initialDateGroups: RecordsByDate = {};
    return records.reduce<{}>((dateGroups: RecordsByDate, record) => {
      const date = formatDate(record.timestamp, 'yyyy-MM-dd', 'en-us');
      if (!dateGroups[date]) {
        dateGroups[date] = [];
      }
      dateGroups[date].push(record);
      return dateGroups;
    }, initialDateGroups);
  }
Example #2
Source File: sending-post-capture.page.ts    From capture-lite with GNU General Public License v3.0 6 votes vote down vote up
readonly previewAsset$ = combineLatest([
    this.asset$,
    this.receiverEmail$,
    this.assetFileUrl$,
    this.contacts$,
  ]).pipe(
    switchMap(async ([asset, receiverEmail, assetFileUrl, contacts]) => {
      const previewAsset: DiaBackendAsset = {
        ...asset,
        asset_file: assetFileUrl,
        asset_file_thumbnail: assetFileUrl,
        sharable_copy: assetFileUrl,
        caption: this.message !== '' ? this.message : asset.caption,
        source_transaction: {
          id: '',
          sender: asset.owner_name,
          receiver_email: receiverEmail,
          created_at: '',
          fulfilled_at: formatDate(Date.now(), 'short', 'en-US'),
          expired: false,
        },
      };
      if (contacts.find(cont => cont.contact_email == receiverEmail) != null) {
        this.contactAlreadyExists = true;
        this.shouldCreateContact = false;
      }
      return previewAsset;
    })
  );
Example #3
Source File: app.component.ts    From covid19-people-counter-system with MIT License 6 votes vote down vote up
refreshData(){
    const newData:{title: string, barChartLabels: Label[], barChartData: ChartDataSets[]}[] = [];
    this.spinner.show();
    this.apiService.getAllData().pipe(take(1)).subscribe(graphs=>{
      graphs.forEach(singleGraphData=>{
        const barChartData: ChartDataSets[] =[];
        const barChartLabels: Label[] = [];
        barChartData[0]  = {data:[], label: singleGraphData[0][2]}
        singleGraphData.forEach(singleData=>{
          barChartData[0]['data'].push(singleData[0]);
          barChartLabels.push(formatDate(singleData[1],environment.dateFormat,environment.locale,environment.timezone));
        })
        barChartData[0]['data'] = barChartData[0]['data'].reverse();
        
        newData.push({title:singleGraphData[0][3] ,barChartData: barChartData, barChartLabels: barChartLabels.reverse()})
      })

      this.data = newData;
      this.spinner.hide();
    });
    
  }
Example #4
Source File: pb-date-pipe.ts    From protobuf-ts with Apache License 2.0 6 votes vote down vote up
transform(value: any, format = 'mediumDate', timezone?: string, locale?: string): string | null {
    if (value == null || value === '' || value !== value) {
      return null;
    }
    if (isPbDateTime(value)) {
      let dt = new Date(value.year, value.month - 1, value.day, value.hours, value.minutes, value.seconds, value.nanos / 1000);
      if (value.timeOffset) {
        if (value.timeOffset.oneofKind === "timeZone") {
          throw new Error("Do not understand IANA time zone. Cannot convert to javascript Date.");
        } else if (value.timeOffset.oneofKind === "utcOffset") {
          let pbOffset = PbLong.from(value.timeOffset.utcOffset.seconds).toNumber() / 60;
          let jsOffset = dt.getTimezoneOffset();
          dt.setMinutes(dt.getMinutes() + (pbOffset - jsOffset))
        }
      }
      return formatDate(dt, format, locale ?? this.locale, timezone);
    }
    if (isPbTimestamp(value)) {
      let tsSeconds = PbLong.from(value.seconds).toNumber();
      let dt = new Date(tsSeconds * 1000 + Math.ceil(value.nanos / 1000000));
      return formatDate(dt, format, locale ?? this.locale, timezone);
    }
    return formatDate(value, format, locale ?? this.locale, timezone);
  }
Example #5
Source File: capture-tab.component.ts    From capture-lite with GNU General Public License v3.0 5 votes vote down vote up
readonly capturesByDate$ = this.proofs$.pipe(
    map(proofs => proofs.sort((a, b) => b.timestamp - a.timestamp)),
    map(proofs =>
      groupBy(proofs, proof =>
        formatDate(proof.timestamp, 'yyyy/MM/dd', 'en-US')
      )
    )
  );