Options
All
  • Public
  • Public/Protected
  • All
Menu

A class which holds a specific time during in any day.

Hierarchy

  • Time

Index

Constructors

constructor

  • new Time(hour: number, minute?: number, second?: number, millisecond?: number): Time
  • Creates a new Time instance given an hour and optionally a minute, second, and millisecond. If they have not been specified they default to 0.

    Parameters

    • hour: number

      The hour.

    • Default value minute: number = Constants.MINUTE_MIN

      The minute.

    • Default value second: number = Constants.SECOND_MIN

      The second.

    • Default value millisecond: number = Constants.MILLIS_MIN

      The millisecond.

    Returns Time

Properties

hour

hour: number

The hour between 0 and 23

millisecond

millisecond: number

The millisecond between 0 and 999

minute

minute: number

The minute between 0 and 59

second

second: number

The second between 0 and 59

Static REGEX

REGEX: RegExp = /^(\d\d?):?(\d\d)?:?(\d\d)?\.?(\d\d\d)?$/

The regular expression used to parse a time from a string.

  • = hour

  • ##:## = hour & minute
  • ##:##:## = hour, minute, & second
  • ##:##:##.### = hour, minute, second, and milliseconds

Methods

format

  • format(format: string): string
  • Formats this time into a string.

    see

    TimeFormat

    Parameters

    • format: string

      The format to output.

    Returns string

    The formatted time.

matches

  • matches(time: Time): boolean
  • Determines whether this time is an exact match for the given time.

    Parameters

    • time: Time

      The given time to test against.

    Returns boolean

    true if the time matches this time, otherwise false.

matchesHour

  • matchesHour(time: Time): boolean
  • Determines whether this time has the same hour as the given time.

    Parameters

    • time: Time

      The given time to test against.

    Returns boolean

    true if the given hour matches this hour, otherwise false.

matchesMinute

  • matchesMinute(time: Time): boolean
  • Determines whether this time has the same hour and minute as the given time.

    Parameters

    • time: Time

      The given time to test against.

    Returns boolean

    true if the given hour and minute matches, otherwise false.

matchesSecond

  • matchesSecond(time: Time): boolean
  • Determines whether this time has the same hour, minute, and second as the given time.

    Parameters

    • time: Time

      The given time to test against.

    Returns boolean

    true if the given hour, minute, and second matches, otherwise false.

set

  • Sets the time of this instance to the same time of the given input.

    Parameters

    Returns boolean

    true if this time was set, otherwise false (invalid input).

toIdentifier

  • toIdentifier(): number
  • Returns number

    A unique identifier for this time. The number returned is in the following format: SSSssmmHH

toMilliseconds

  • toMilliseconds(): number
  • Returns number

    The number of milliseconds from the start of the day until this time.

toObject

  • Returns TimeInput

    An object with hour, minute, second, a millisecond properties if they are non-zero on this time.

toString

  • toString(): string
  • Returns string

    The time formatted using the smallest format that completely represents this time.

Static build

  • build(hour: number, minute?: number, second?: number, millisecond?: number): Time
  • Returns a new instance given an hour and optionally a minute, second, and millisecond. If they have not been specified they default to 0.

    Parameters

    • hour: number

      The hour.

    • Default value minute: number = Constants.MINUTE_MIN

      The minute.

    • Default value second: number = Constants.SECOND_MIN

      The second.

    • Default value millisecond: number = Constants.MILLIS_MIN

      The millisecond.

    Returns Time

    A new instance.

Static fromIdentifier

  • fromIdentifier(time: number): Time
  • Parses a number and converts it to a Time instance. The number is assumed to be in the Time.toIdentifier format.

    Parameters

    • time: number

      The number to parse.

    Returns Time

    The instance parsed.

Static fromString

  • fromString(time: string): Time
  • Parses a string and converts it to a Time instance. If the string is not in a valid format null is returned.

    see

    Time.REGEX

    Parameters

    • time: string

      The string to parse.

    Returns Time

    The instance parsed or null if it was invalid.

Static parse

  • parse(input: any): Time
  • Parses a value and tries to convert it to a Time instance.

    see

    Parse.time

    Parameters

    • input: any

      The input to parse.

    Returns Time

    The instance parsed or null if it was invalid.

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc