Skip to content

Commit

Permalink
improve name
Browse files Browse the repository at this point in the history
  • Loading branch information
saropa committed Jan 8, 2025
1 parent 0a1f579 commit 7ee63f5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Learn more at https://saropa.com, or email [email protected]

****

## 0.3.17+Kyoto (Latest)
## 0.3.18+Kyoto (Latest)

* ⏰ Added boilerplate [DateTimeRange] utils
* ⏰ Added many useful boilerplate [DateTime] utils
Expand Down
2 changes: 1 addition & 1 deletion lib/datetime/date_time_range_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extension DateTimeRangeExtensions on DateTimeRange {
/// Determines if the nth occurrence of a specific day of the week in a given
/// month falls within the specified date range.
///
bool isNthDayOfMonth(
bool isNthDayOfMonthInRange(
int n,
int dayOfWeek,
int month, {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: saropa_dart_utils
description: "Boilerplate reduction tools and human-readable extension methods by Saropa"
version: 0.3.17
version: 0.3.18+Kyoto

homepage: https://app.saropa.com
repository: https://github.com/saropa/saropa_dart_utils
Expand Down
52 changes: 26 additions & 26 deletions test/datetime/date_time_range_utils_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,47 @@ void main() {
start: DateTime(2023),
end: DateTime(2023, 12, 31),
);
expect(range.isNthDayOfMonth(2, DateTime.monday, 3), true);
expect(range.isNthDayOfMonthInRange(2, DateTime.monday, 3), true);
});

test('returns false for 2nd Monday of March outside range', () {
final range = DateTimeRange(
start: DateTime(2023, 4),
end: DateTime(2023, 12, 31),
);
expect(range.isNthDayOfMonth(2, DateTime.monday, 3), false);
expect(range.isNthDayOfMonthInRange(2, DateTime.monday, 3), false);
});

test('returns true for 1st Friday of January at start of range', () {
final range = DateTimeRange(
start: DateTime(2023),
end: DateTime(2023, 12, 31),
);
expect(range.isNthDayOfMonth(1, DateTime.friday, 1), true);
expect(range.isNthDayOfMonthInRange(1, DateTime.friday, 1), true);
});

test('returns true for last day of range', () {
final range = DateTimeRange(
start: DateTime(2023),
end: DateTime(2023, 12, 31),
);
expect(range.isNthDayOfMonth(5, DateTime.sunday, 12), true);
expect(range.isNthDayOfMonthInRange(5, DateTime.sunday, 12), true);
});

test('returns false for day just after range', () {
final range = DateTimeRange(
start: DateTime(2023),
end: DateTime(2023, 12, 30),
);
expect(range.isNthDayOfMonth(5, DateTime.sunday, 12), false);
expect(range.isNthDayOfMonthInRange(5, DateTime.sunday, 12), false);
});

test('returns true for recurring holiday across multiple years', () {
final range = DateTimeRange(
start: DateTime(2022),
end: DateTime(2024, 12, 31),
);
expect(range.isNthDayOfMonth(3, DateTime.monday, 1), true);
expect(range.isNthDayOfMonthInRange(3, DateTime.monday, 1), true);
});

test('returns false when nth occurrence does not exist', () {
Expand All @@ -58,7 +58,7 @@ void main() {
end: DateTime(2023, 12, 31),
);
expect(
range.isNthDayOfMonth(5, DateTime.monday, 2),
range.isNthDayOfMonthInRange(5, DateTime.monday, 2),
false,
); // February never has 5 Mondays
});
Expand All @@ -69,7 +69,7 @@ void main() {
end: DateTime(2024, 12, 31),
);
expect(
range.isNthDayOfMonth(5, DateTime.thursday, 2),
range.isNthDayOfMonthInRange(5, DateTime.thursday, 2),
true,
); // February 29, 2024
});
Expand All @@ -80,68 +80,68 @@ void main() {
end: DateTime(2023, 12, 31),
);
expect(
range.isNthDayOfMonth(5, DateTime.thursday, 2),
range.isNthDayOfMonthInRange(5, DateTime.thursday, 2),
false,
); // February 29, 2024 not in 2023
});

test('returns true for 1st Monday of January in multi-year range', () {
final range =
DateTimeRange(start: DateTime(2023), end: DateTime(2025, 12, 31));
expect(range.isNthDayOfMonth(1, DateTime.monday, 1), true);
expect(range.isNthDayOfMonthInRange(1, DateTime.monday, 1), true);
});

test('returns false for 6th Friday of April (impossible case)', () {
final range =
DateTimeRange(start: DateTime(2023), end: DateTime(2023, 12, 31));
expect(range.isNthDayOfMonth(6, DateTime.friday, 4), false);
expect(range.isNthDayOfMonthInRange(6, DateTime.friday, 4), false);
});

test('returns true for 5th Wednesday of May 2023 (May 31, 2023)', () {
final range =
DateTimeRange(start: DateTime(2023), end: DateTime(2023, 12, 31));
expect(range.isNthDayOfMonth(5, DateTime.wednesday, 5), true);
expect(range.isNthDayOfMonthInRange(5, DateTime.wednesday, 5), true);
});

test('returns false for 5th Wednesday of May 2024', () {
final range =
DateTimeRange(start: DateTime(2024), end: DateTime(2024, 12, 31));
expect(range.isNthDayOfMonth(5, DateTime.wednesday, 5), true);
expect(range.isNthDayOfMonthInRange(5, DateTime.wednesday, 5), true);
});

test('returns true for 4th Thursday of November (Thanksgiving) in 2023',
() {
final range =
DateTimeRange(start: DateTime(2023), end: DateTime(2023, 12, 31));
expect(range.isNthDayOfMonth(4, DateTime.thursday, 11), true);
expect(range.isNthDayOfMonthInRange(4, DateTime.thursday, 11), true);
});

test(
'returns false for 4th Thursday of November (Thanksgiving) in range '
'ending before November', () {
final range =
DateTimeRange(start: DateTime(2023), end: DateTime(2023, 10, 31));
expect(range.isNthDayOfMonth(4, DateTime.thursday, 11), false);
expect(range.isNthDayOfMonthInRange(4, DateTime.thursday, 11), false);
});

test('returns true for 1st Sunday of February in leap year 2024', () {
final range =
DateTimeRange(start: DateTime(2024), end: DateTime(2024, 12, 31));
expect(range.isNthDayOfMonth(1, DateTime.sunday, 2), true);
expect(range.isNthDayOfMonthInRange(1, DateTime.sunday, 2), true);
});

test('returns false for 5th Saturday of December 2023', () {
final range =
DateTimeRange(start: DateTime(2023), end: DateTime(2023, 12, 31));
expect(range.isNthDayOfMonth(5, DateTime.saturday, 12), true);
expect(range.isNthDayOfMonthInRange(5, DateTime.saturday, 12), true);
});

test(
'returns true for 2nd Tuesday of February in non-leap year range '
'including multiple years', () {
final range =
DateTimeRange(start: DateTime(2023), end: DateTime(2025, 12, 31));
expect(range.isNthDayOfMonth(2, DateTime.tuesday, 2), true);
expect(range.isNthDayOfMonthInRange(2, DateTime.tuesday, 2), true);
});

test('returns false when nth occurrence does not exist', () {
Expand All @@ -150,40 +150,40 @@ void main() {
end: DateTime(2023, 12, 31),
);
expect(
range.isNthDayOfMonth(5, DateTime.monday, 2),
range.isNthDayOfMonthInRange(5, DateTime.monday, 2),
false,
); // February never has 5 Mondays
});

test('returns false for 6th Friday of April (impossible case)', () {
final range =
DateTimeRange(start: DateTime(2023), end: DateTime(2023, 12, 31));
expect(range.isNthDayOfMonth(6, DateTime.friday, 4), false);
expect(range.isNthDayOfMonthInRange(6, DateTime.friday, 4), false);
});

test('returns false for 5th Wednesday of May 2024', () {
final range =
DateTimeRange(start: DateTime(2024), end: DateTime(2024, 12, 31));
expect(range.isNthDayOfMonth(5, DateTime.wednesday, 5), true);
expect(range.isNthDayOfMonthInRange(5, DateTime.wednesday, 5), true);
});

test('returns true for 5th Saturday of December 2024 (does not exist)', () {
final range =
DateTimeRange(start: DateTime(2024), end: DateTime(2024, 12, 31));
expect(range.isNthDayOfMonth(5, DateTime.saturday, 12), false);
expect(range.isNthDayOfMonthInRange(5, DateTime.saturday, 12), false);
});

test('returns true for 1st Monday of January in multi-year range', () {
final range =
DateTimeRange(start: DateTime(2023), end: DateTime(2025, 12, 31));
expect(range.isNthDayOfMonth(1, DateTime.monday, 1), true);
expect(range.isNthDayOfMonthInRange(1, DateTime.monday, 1), true);
});

test('returns true for February 29 in leap year', () {
final range =
DateTimeRange(start: DateTime(2024), end: DateTime(2024, 12, 31));
expect(
range.isNthDayOfMonth(1, DateTime.thursday, 2),
range.isNthDayOfMonthInRange(1, DateTime.thursday, 2),
true,
); // February has a Thursday on Feb.29
});
Expand All @@ -193,7 +193,7 @@ void main() {
final range =
DateTimeRange(start: DateTime(2023), end: DateTime(2023, 12, 31));
expect(
range.isNthDayOfMonth(5, DateTime.monday, 2),
range.isNthDayOfMonthInRange(5, DateTime.monday, 2),
false,
); // February never has a fifth Monday
});
Expand All @@ -202,7 +202,7 @@ void main() {
final range =
DateTimeRange(start: DateTime(2023), end: DateTime(2023, 12, 31));
expect(
range.isNthDayOfMonth(5, DateTime.sunday, 12),
range.isNthDayOfMonthInRange(5, DateTime.sunday, 12),
true,
); // December has a Sunday on Dec.31
});
Expand Down

0 comments on commit 7ee63f5

Please sign in to comment.