HoraTimezone.fromOffset constructor
Creates a timezone from UTC offset hours and minutes.
Implementation
factory HoraTimezone.fromOffset(
int hours, {
int minutes = 0,
String? name,
}) {
if (hours.abs() > 23) {
throw ArgumentError.value(
hours,
'hours',
'Timezone hour offset must be in -23..23.',
);
}
if (minutes.abs() > 59) {
throw ArgumentError.value(
minutes,
'minutes',
'Timezone minute offset must be in -59..59.',
);
}
if (hours != 0 &&
minutes != 0 &&
((hours > 0 && minutes < 0) || (hours < 0 && minutes > 0))) {
throw ArgumentError.value(
minutes,
'minutes',
'Minute offset sign must match hour offset sign.',
);
}
final totalMinutes = switch ((hours, minutes)) {
(0, final m) => m,
(final h, final m) when h < 0 => h * 60 - m.abs(),
(final h, final m) => h * 60 + m.abs(),
};
return HoraTimezone.fromMinutes(totalMinutes, name: name);
}