Home Reference Source Test
import Duration from 'brainspan/brainspan/Duration.js'
public class | source

Duration

Inspired by Rails' ActiveSupport::Duration. Provides accurate date and time measurements.

Example:

// Retuns a Date with the timestamp for a month before the current date and time.
(1).month.ago

Test:

Static Member Summary

Static Public Members
public static get
public static get
public static get
public static get
public static get
public static get

Constructor Summary

Public Constructor
public

Member Summary

Public Members
public get
public get
public get
public get
public get
public get
public get
public

Method Summary

Public Methods
public

after(date: Date): Date

Alias of since

public

ago(date: Date): Date

A Date in the past of the given Date, or new Date() if not supplied

public

before(date: Date): Date

Alias of ago

public

fromNow(date: Date): Date

Alias of since

public

since(date: Date): Date

A Date in the future of the given Date, or new Date() if not supplied

public

until(date: Date): Date

Alias of ago

public

Static Public Members

public static get SECONDS_PER_DAY: Number: * source

Return:

Number

the number of seconds in a day.

public static get SECONDS_PER_HOUR: Number: * source

Return:

Number

the number of seconds in an hour.

public static get SECONDS_PER_MINUTE: Number: * source

Return:

Number

the number of seconds in a minute.

public static get SECONDS_PER_MONTH: Number: * source

Return:

Number

the number of seconds in a month. Note: for this purpose, a month is presumed to be 1/12th of a year.

public static get SECONDS_PER_WEEK: Number: * source

Return:

Number

the number of seconds in a week.

public static get SECONDS_PER_YEAR: Number: * source

Return:

Number

the number of seconds in a month. Note: for this purpose, a year is presumed to be 365 days.

Public Constructors

public constructor(seconds: Number): Duration source

Params:

NameTypeAttributeDescription
seconds Number

The number of seconds the Duration represents.

Return:

Duration

An object representing a span of time.

Public Members

public get asDays: Number: * source

Return:

Number

the number of days in this duration.

public get asHours: Number: * source

Return:

Number

the number of hours in this duration.

public get asMilliseconds: Number: * source

Return:

Number

the number of millisends in this duration.

Test:

public get asMinutes: Number: * source

Return:

Number

the number of minutes in this duration.

public get asMonths: Number: * source

Return:

Number

the number of months in this duration.

public get asWeeks: Number: * source

Return:

Number

the number of weeks in this duration.

public get asYears: Number: * source

Return:

Number

the number of years in this duration.

Public Methods

public after(date: Date): Date source

Alias of since

Params:

NameTypeAttributeDescription
date Date
  • optional
  • default: new Date()

Return:

Date

public ago(date: Date): Date source

A Date in the past of the given Date, or new Date() if not supplied

Params:

NameTypeAttributeDescription
date Date
  • optional
  • default: new Date()

Return:

Date

Test:

public before(date: Date): Date source

Alias of ago

Params:

NameTypeAttributeDescription
date Date
  • optional
  • default: new Date()

Return:

Date

public fromNow(date: Date): Date source

Alias of since

Params:

NameTypeAttributeDescription
date Date
  • optional
  • default: new Date()

Return:

Date

public since(date: Date): Date source

A Date in the future of the given Date, or new Date() if not supplied

Params:

NameTypeAttributeDescription
date Date
  • optional
  • default: new Date()

Return:

Date

Test:

public until(date: Date): Date source

Alias of ago

Params:

NameTypeAttributeDescription
date Date
  • optional
  • default: new Date()

Return:

Date

public valueOf(): Number source

Return:

Number

The number of seconds represented by this Duration.

Test: