Skip to content

Commit faf2551

Browse files
committed
fix pageable time range
1 parent dab9bbc commit faf2551

File tree

6 files changed

+80
-9
lines changed

6 files changed

+80
-9
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 3.3.0
2+
3+
- Fixed where `PageableRange.next` and/or `PageableRange.last` could end up with
4+
illegal values such as month=13, day=32, etc...
5+
16
## 3.2.1
27

38
- Make static analyzer happy; +10 pts to Gryffindor

lib/src/time_range/day.dart

+25-3
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,38 @@ class DayTimeRange extends TimeRange with PageableRange<DayTimeRange> {
99
final int month;
1010
final int day;
1111

12-
/// Please note that [hour], [minute], [second], [millisecond], [microsecond]
13-
/// will be ignored.
14-
const DayTimeRange(
12+
factory DayTimeRange(
13+
int year,
14+
int month,
15+
int day, {
16+
bool isUtc = false,
17+
}) {
18+
final DateTime dateTime = DateTimeConstructors.withTimezone(
19+
isUtc,
20+
year,
21+
month,
22+
day,
23+
);
24+
25+
return DayTimeRange._internal(
26+
dateTime.year,
27+
dateTime.month,
28+
dateTime.day,
29+
isUtc: dateTime.isUtc,
30+
);
31+
}
32+
33+
const DayTimeRange._internal(
1534
this.year,
1635
this.month,
1736
this.day, {
1837
this.isUtc = false,
1938
}) : assert(month > 0 && month <= 12 && day > 0 && day <= 31);
2039

2140
/// Will preserve the timezone of [dateTime]
41+
///
42+
/// Please note that [hour], [minute], [second], [millisecond], [microsecond]
43+
/// will be ignored.
2244
factory DayTimeRange.fromDateTime(DateTime dateTime) => DayTimeRange(
2345
dateTime.year,
2446
dateTime.month,

lib/src/time_range/hour.dart

+27-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,33 @@ class HourTimeRange extends TimeRange with PageableRange<HourTimeRange> {
1212

1313
/// Please note that [minute], [second], [millisecond], [microsecond]
1414
/// will be ignored.
15-
const HourTimeRange(
15+
factory HourTimeRange(
16+
int year,
17+
int month,
18+
int day,
19+
int hour, {
20+
bool isUtc = false,
21+
}) {
22+
final DateTime dateTime = DateTimeConstructors.withTimezone(
23+
isUtc,
24+
year,
25+
month,
26+
day,
27+
hour,
28+
);
29+
30+
return HourTimeRange._internal(
31+
dateTime.year,
32+
dateTime.month,
33+
dateTime.day,
34+
dateTime.hour,
35+
isUtc: dateTime.isUtc,
36+
);
37+
}
38+
39+
/// Please note that [minute], [second], [millisecond], [microsecond]
40+
/// will be ignored.
41+
const HourTimeRange._internal(
1642
this.year,
1743
this.month,
1844
this.day,

lib/src/time_range/month.dart

+13-3
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,25 @@ class MonthTimeRange extends TimeRange with PageableRange<MonthTimeRange> {
88
final int year;
99
final int month;
1010

11-
/// Please note that [day], [hour], [minute], [second], [millisecond], [microsecond]
12-
/// will be ignored.
13-
const MonthTimeRange(
11+
factory MonthTimeRange(
12+
int year,
13+
int month, {
14+
bool isUtc = false,
15+
}) {
16+
final DateTime date = DateTimeConstructors.withTimezone(isUtc, year, month);
17+
return MonthTimeRange._internal(date.year, date.month, isUtc: date.isUtc);
18+
}
19+
20+
const MonthTimeRange._internal(
1421
this.year,
1522
this.month, {
1623
this.isUtc = false,
1724
}) : assert(month > 0 && month <= 12);
1825

1926
/// Will preserve the timezone of [dateTime]
27+
///
28+
/// Please note that [day], [hour], [minute], [second], [millisecond], [microsecond]
29+
/// will be ignored.
2030
factory MonthTimeRange.fromDateTime(DateTime dateTime) => MonthTimeRange(
2131
dateTime.year,
2232
dateTime.month,

lib/src/time_range/year.dart

+9-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@ class YearTimeRange extends TimeRange with PageableRange<YearTimeRange> {
77

88
final int year;
99

10-
const YearTimeRange(
10+
factory YearTimeRange(
11+
int year, {
12+
bool isUtc = false,
13+
}) {
14+
final DateTime dateTime = DateTimeConstructors.withTimezone(isUtc, year);
15+
return YearTimeRange._internal(dateTime.year, isUtc: dateTime.isUtc);
16+
}
17+
18+
const YearTimeRange._internal(
1119
this.year, {
1220
this.isUtc = false,
1321
});

pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: moment_dart
22
description: Multi-purpose immutable DateTime subclass. Supports multiple localizations to easily convert DateTime and Duration into human-readable format
3-
version: 3.2.1
3+
version: 3.3.0
44
homepage: https://github.com/sadespresso/moment_dart
55
issue_tracker: https://github.com/sadespresso/moment_dart/issues
66
funding:

0 commit comments

Comments
 (0)