date-fns#addSeconds TypeScript Examples

The following examples show how to use date-fns#addSeconds. 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: fitbit-helper.ts    From nyxo-app with GNU General Public License v3.0 6 votes vote down vote up
formatFitbitSample = (
  fitbitObject: FitbitSleepObject
): Night[] => {
  const startDate = new Date(fitbitObject.startTime).toISOString()
  const endDate = new Date(fitbitObject.endTime).toISOString()
  const totalDuration = fitbitObject.timeInBed

  const inBedSample: Night = {
    id: `fitbit_${fitbitObject.logId}_${startDate}_${endDate}_${Value.InBed}`,
    sourceId: CONFIG.FITBIT_CONFIG.bundleId,
    sourceName: 'Fitbit',
    value: Value.InBed,
    startDate,
    endDate,
    totalDuration
  }

  const asleepSamples: Night[] = fitbitObject.levels.data.map((sample) => {
    const start = new Date(sample.dateTime).toISOString()
    const end = addSeconds(
      new Date(sample.dateTime),
      sample.seconds
    ).toISOString()

    return {
      id: `fitbit_${fitbitObject.logId}_${start}_${end}_${Value.Asleep}`,
      sourceId: CONFIG.FITBIT_CONFIG.bundleId,
      sourceName: 'Fitbit',
      value: Value.Asleep,
      startDate: start,
      endDate: end,
      totalDuration: Math.floor(sample.seconds / 60)
    }
  })

  return [inBedSample, ...asleepSamples]
}
Example #2
Source File: timeParser.ts    From tempomat with MIT License 6 votes vote down vote up
export function toInterval(seconds: number, startTime: string, referenceDate: Date): Interval | null {
    if (seconds < 0) return null
    const parsedStartTime = fnsParse(startTime, 'HH:mm:ss', referenceDate)
    if (isValid(parsedStartTime)) {
        const startTime = format(parsedStartTime, 'HH:mm')
        const endTime = format(addSeconds(parsedStartTime, seconds), 'HH:mm')
        return {
            startTime: startTime,
            endTime: endTime
        }
    } else {
        return null
    }
}
Example #3
Source File: date.ts    From ngx-gantt with MIT License 6 votes vote down vote up
add(amount: number, unit?: GanttDateUtil) {
        switch (unit) {
            case 'second':
                return new GanttDate(this.value).addSeconds(amount);
            case 'minute':
                return new GanttDate(this.value).addMinutes(amount);
            case 'hour':
                return new GanttDate(this.value).addHours(amount);
            case 'day':
                return new GanttDate(this.value).addDays(amount);
            case 'week':
                return new GanttDate(this.value).addWeeks(amount);
            case 'month':
                return new GanttDate(this.value).addMonths(amount);
            case 'quarter':
                return new GanttDate(this.value).addQuarters(amount);
            case 'year':
                return new GanttDate(this.value).addYears(amount);
            default:
                return new GanttDate(this.value).addSeconds(amount);
        }
    }
Example #4
Source File: withings-helper.ts    From nyxo-app with GNU General Public License v3.0 5 votes vote down vote up
formatWithingsSample = (
  withingsSleepObject: WithingsSleepObject
): Night[] => {
  const {
    data: { durationtosleep = 0, durationtowakeup = 0 }
  } = withingsSleepObject

  const startDate = new Date(withingsSleepObject.startdate).toISOString()
  const endDate = new Date(withingsSleepObject.enddate).toISOString()
  const timeInBed = getNightDuration(startDate, endDate)

  const inBedSample: Night = {
    id: `withings_${withingsSleepObject.date}_${startDate}_${endDate}_${Value.InBed}`,
    sourceId: CONFIG.WITHINGS_CONFIG.bundleId,
    sourceName: 'Withings',
    value: Value.InBed,
    startDate,
    endDate,
    totalDuration: timeInBed
  }

  const asleepStartDate = addSeconds(
    new Date(startDate),
    durationtosleep
  ).toISOString()
  const asleepEndDate = subSeconds(
    new Date(startDate),
    durationtowakeup
  ).toISOString()

  const timeAsleep = getNightDuration(asleepStartDate, asleepEndDate)

  const asleepSample: Night = {
    id: `withings_${withingsSleepObject.date}_${asleepStartDate}_${asleepEndDate}_${Value.Asleep}`,
    sourceId: CONFIG.WITHINGS_CONFIG.bundleId,
    sourceName: 'Withings',
    value: Value.Asleep,
    startDate: asleepStartDate,
    endDate: asleepEndDate,
    totalDuration: timeAsleep
  }

  return [inBedSample, asleepSample]
}
Example #5
Source File: date.ts    From ngx-gantt with MIT License 5 votes vote down vote up
getDaysInQuarter() {
        return differenceInCalendarDays(this.endOfQuarter().addSeconds(1).value, this.startOfQuarter().value);
    }
Example #6
Source File: date.ts    From ngx-gantt with MIT License 5 votes vote down vote up
getDaysInYear() {
        return differenceInCalendarDays(this.endOfYear().addSeconds(1).value, this.startOfYear().value);
    }
Example #7
Source File: date.ts    From ngx-gantt with MIT License 5 votes vote down vote up
addSeconds(amount: number): GanttDate {
        return new GanttDate(addSeconds(this.value, amount));
    }