chronia
    Preparing search index...

    Function isSameMonth

    • Check if two dates are in the same calendar month and year.

      This function compares two dates and returns true if they fall within the same calendar month and year, regardless of day or time components.

      Parameters

      • dateLeft: number | Date

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

      • dateRight: number | Date

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

      Returns boolean

      True if both dates are in the same month and year, false otherwise or if either date is invalid

      // Same month and year, different days
      const result = isSameMonth(new Date(2024, 5, 1), new Date(2024, 5, 30));
      // Returns: true

      // Different months
      const result2 = isSameMonth(new Date(2024, 5, 30), new Date(2024, 6, 1));
      // Returns: false

      // Same month and year, different times
      const result3 = isSameMonth(
      new Date(2024, 5, 15, 14, 30),
      new Date(2024, 5, 20, 9, 45)
      );
      // Returns: true

      // Same month, different years
      const result4 = isSameMonth(new Date(2024, 5, 15), new Date(2023, 5, 15));
      // Returns: false (different years)

      // Invalid dates return false
      const result5 = isSameMonth(new Date("invalid"), new Date(2024, 5, 1));
      // Returns: false
      • Validates arguments before processing (consistent with library patterns)
      • Returns false for any invalid input (Invalid Date, NaN, Infinity, -Infinity)
      • Accepts both Date objects and numeric timestamps
      • Ignores day and time components in the comparison
      • Requires both month AND year to match (June 2024 ≠ June 2023)
      • Uses diffMonths internally to determine if the month difference is zero
      • Handles month boundaries and leap years correctly