File

src/app/shared/utils/period-time.ts

Index

Properties
  • Readonly Static All
  • Readonly Static Day
  • Readonly Static Month
  • Readonly Static Week
  • Readonly Static Year
Methods

Methods

Static getPeriod
getPeriod(periodName: PeriodTimeName)
Parameters :
Name Type Optional Description
periodName PeriodTimeName
Returns : Period

Properties

Readonly Static All
All: PeriodTimeName
Type : PeriodTimeName
Default value : "All time"
Readonly Static Day
Day: PeriodTimeName
Type : PeriodTimeName
Default value : "Day"
Readonly Static Month
Month: PeriodTimeName
Type : PeriodTimeName
Default value : "Month"
Readonly Static Week
Week: PeriodTimeName
Type : PeriodTimeName
Default value : "Week"
Readonly Static Year
Year: PeriodTimeName
Type : PeriodTimeName
Default value : "Year"
import {Period} from "../models/period";

export class PeriodTime {

  static readonly Day: PeriodTimeName = "Day";
  static readonly Week: PeriodTimeName = "Week";
  static readonly Month: PeriodTimeName = "Month";
  static readonly Year: PeriodTimeName = "Year";
  static readonly All: PeriodTimeName = "All time";

  static getPeriod(periodName: PeriodTimeName): Period {
    let fromTime = new Date();
    switch (periodName) {
      case PeriodTime.Day:
        break;
      case PeriodTime.Week:
        fromTime.setDate(fromTime.getDate() - 7);
        break;
      case PeriodTime.Month:
        fromTime.setMonth(fromTime.getMonth() - 1);
        break;
      case PeriodTime.Year:
        fromTime.setFullYear(fromTime.getFullYear() - 1);
        break;
      case PeriodTime.All:
        fromTime.setTime(0);
        break;
    }

    return new Period(fromTime.getTime(), new Date().getTime()).toStartAndEndOfDay()
  }

}

export type PeriodTimeName = "Day" | "Week" | "Month" | "Year" | "All time"

results matching ""

    No results matching ""