isBetweenMonths method

bool isBetweenMonths(
  1. int startMonth,
  2. int endMonth
)

Converts a numeric timestamp (in milliseconds since epoch) to a DateTime object.

Example:

1609459200000.timestampToDate; // Returns DateTime for 2021-01-01 00:00:00.000

Checks if the number (assumed to represent a month, 1-based) is within the specified range of months.

This method handles ranges that cross the year boundary (e.g., December to February).

Example:

3.isBetweenMonths(12, 2); // Returns false, March is outside December-February
1.isBetweenMonths(12, 2); // Returns true, January is within December-February
6.isBetweenMonths(3, 8);  // Returns true, June is within March-August

Implementation

// Removed: prefer ConvertObject.toDateTime(this) for epoch values.

/// Checks if the number (assumed to represent a month, 1-based) is within the specified range of months.
///
/// This method handles ranges that cross the year boundary (e.g., December to February).
///
/// Example:
/// ```dart
/// 3.isBetweenMonths(12, 2); // Returns false, March is outside December-February
/// 1.isBetweenMonths(12, 2); // Returns true, January is within December-February
/// 6.isBetweenMonths(3, 8);  // Returns true, June is within March-August
/// ```
bool isBetweenMonths(int startMonth, int endMonth) {
  final month = toInt();
  // Handle cases where the range crosses over the year boundary (e.g., December to February)
  if (startMonth > endMonth) {
    return month >= startMonth || month <= endMonth;
  } else {
    return month >= startMonth && month <= endMonth;
  }
}