chronia
    Preparing search index...

    Function setMinutes

    • Set the minutes of the given date.

      This function validates arguments before processing and returns a new Date instance with the specified minutes set. Fractional minutes are truncated toward zero.

      Parameters

      • date: number | Date

        The base date as a Date object or timestamp (number)

      • minutes: number

        The minutes to set (typically 0-59, but values outside this range will cause rollover)

      Returns Date

      A new Date object with the minutes set, or Invalid Date if any input is invalid

      // Set minutes to standard value
      const result = setMinutes(new Date(2025, 0, 15, 12, 30, 45), 45);
      // Returns: 2025-01-15 12:45:45

      // Set minutes to boundary value
      const result2 = setMinutes(new Date(2025, 0, 15, 12, 30, 45), 0);
      // Returns: 2025-01-15 12:00:45

      // Fractional minutes are truncated
      const result3 = setMinutes(new Date(2025, 0, 15, 12, 30, 45), 45.9);
      // Returns: 2025-01-15 12:45:45

      // Minutes outside 0-59 roll over to adjacent hours
      const result4 = setMinutes(new Date(2025, 0, 15, 12, 30, 45), 60);
      // Returns: 2025-01-15 13:00:45 (rolls over to next hour)

      // Invalid date returns Invalid Date
      const result5 = setMinutes(new Date("invalid"), 30);
      // Returns: Invalid Date
      • Validates arguments before conversion (consistent with library patterns)
      • Accepts both Date objects and numeric timestamps
      • Fractions are truncated using Math.trunc (45.9 → 45, -45.9 → -45)
      • Returns Invalid Date for: Invalid Date, NaN, Infinity, -Infinity
      • Preserves year, month, day, hour, seconds, and milliseconds components
      • Values outside 0-59 cause rollover: 60 → next hour, -1 → previous hour
      • Always returns a new Date instance (does not mutate input)