Dreamdata Shared Utils & Constants - v1.19.0
    Preparing search index...

    Class DateTimeUtils

    Index

    Constructors

    Properties

    DEFAULT_FORMAT_OPTIONS: DateTimeFormatOptions = ...

    Methods

    • Calculates the number of days that have passed since a specified end date.

      Parameters

      • end: string

        The ISO string representing the end date.

      Returns number

      The number of days that have passed since the end date.

    • Calculates the number of days remaining until a specified end date.

      Parameters

      • end: string

        The ISO string representing the end date.

      Returns number

      The number of days remaining until the end date.

    • Converts number of days to number of months (approximate).

      Parameters

      • numDays: number

        The number of days to convert.

      Returns number

      The approximate number of months.

    • Returns the Unix timestamp (in seconds) at the start of the day for the given JavaScript Date.

      Parameters

      • jsDate: Date

        The JavaScript Date object to convert.

      Returns number

      The Unix timestamp in seconds at the start of the day in UTC.

    • Returns the start and end Unix timestamps (in seconds) of a date range set to UTC+0.

      Parameters

      • jsDateFrom: Date

        The start date of the date range as a JavaScript Date object.

      • jsDateTo: Date

        The end date of the date range as a JavaScript Date object.

      Returns { from: number; to: number }

      An object containing the start and end Unix timestamps (in seconds).

    • Converts a time range from local timezone to UTC seconds. For example: [Tue Jul 01 2025 02:00:00 GMT+0200, Fri Aug 01 2025 01:59:59 GMT+0200] to [1751328000, 1754006399]

      Parameters

      Returns { from: number; to: number }

      The time range in UTC seconds.

    • Returns a formatted date string with default or custom format options.

      Parameters

      • value: string | Date | null

        The date value to format.

      • formatOptions: DateTimeFormatOptions = ...

        Optional format options.

      Returns string

      The formatted date string or "No Data" if value is null/undefined.

    • Returns the start and end JavaScript Date objects for a given time range in UTC.

      Parameters

      • timerange: { from: number; to: number }

        The time range with 'from' and 'to' Unix timestamps in seconds.

      Returns [Date, Date]

      An array containing the start and end dates as JavaScript Date objects.

      getDefaultRange({ from: 1751414400, to: 1752105599 }) // [Wed Jul 02 2025 00:00:00 GMT+0200 (Central European Summer Time),
      Wed Jul 09 2025 23:59:59 GMT+0200 (Central European Summer Time)]
    • Returns a display value formatted as a short date string in UTC.

      Parameters

      • seconds: number

        The time in seconds since epoch.

      Returns string

      The formatted date string.

    • Formats a given UTC date-time string into the specified format. This function parses the input date-time string, assuming it is in UTC, and then formats it according to the given format string. If no format string is provided, it defaults to "MM/DD/YYYY".

      Parameters

      • utcDateTime: string

        The UTC date-time string to format.

      • format: string = "MM/dd/yyyy"

        The format string (defaults to "MM/dd/yyyy").

      Returns string

      The formatted date string.

    • Converts a Unix timestamp (in seconds) to a JavaScript Date object without applying any timezone offset.

      Parameters

      • dateInSeconds: number

        The Unix timestamp in seconds to convert.

      Returns Date

      The corresponding JavaScript Date object.

    • Gets a time range for one month before current date.

      Returns { from: number; relativeDateId: string; to: number }

      The time range object.

    • Gets a time range for two months before current date.

      Returns { from: number; id: string; relativeDateId: string; to: number }

      The time range object.

    • Parses a JavaScript Date object and returns its equivalent UTC DateTime.

      Parameters

      • date: Date

        The JavaScript Date object to parse.

      Returns DateTime

      The parsed DateTime in UTC.