Skip to content

Commit 984c19c

Browse files
onairmarcEncoreBot
andauthored
Create Calendar Enums and Tests (#102)
Co-authored-by: EncoreBot <[email protected]>
1 parent 8d8251b commit 984c19c

File tree

7 files changed

+221
-0
lines changed

7 files changed

+221
-0
lines changed

.git-blame-ignore-revs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,4 @@ e224e927dabcd3046455985118ed424c43aba054
4343
20e2de4b44af7511cb0eb6e6f71676253b4c2667
4444
e85fae4f7290329ac9cfae159e19c1bb55062e4b
4545
10daa978ac4beebdbc8e9dcc6fa07657001fd91e
46+
5bd6cc77c40f19059dbdda4704d2f380099b29e3

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,4 @@ fabric.properties
174174
######## MacOS ########
175175
##################################
176176
.DS_Store
177+
/.idea/copilotDiffState.xml

.idea/php-test-framework.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Objects/Calendar/DayOfWeek.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
/*
4+
* Copyright (c) 2025. Encore Digital Group.
5+
* All Rights Reserved.
6+
*/
7+
8+
namespace EncoreDigitalGroup\StdLib\Objects\Calendar;
9+
10+
use EncoreDigitalGroup\StdLib\Objects\Support\Traits\HasEnumValue;
11+
12+
enum DayOfWeek: string
13+
{
14+
use HasEnumValue;
15+
16+
case Sunday = "sunday";
17+
case Monday = "monday";
18+
case Tuesday = "tuesday";
19+
case Wednesday = "wednesday";
20+
case Thursday = "thursday";
21+
case Friday = "friday";
22+
case Saturday = "saturday";
23+
24+
public function toInt(bool $zero = true): int
25+
{
26+
$int = match ($this->value) {
27+
self::Sunday->value => 0,
28+
self::Monday->value => 1,
29+
self::Tuesday->value => 2,
30+
self::Wednesday->value => 3,
31+
self::Thursday->value => 4,
32+
self::Friday->value => 5,
33+
self::Saturday->value => 6,
34+
};
35+
36+
if (!$zero) {
37+
$int++;
38+
}
39+
40+
return $int;
41+
}
42+
}

src/Objects/Calendar/Month.php

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
3+
/*
4+
* Copyright (c) 2025. Encore Digital Group.
5+
* All Rights Reserved.
6+
*/
7+
8+
namespace EncoreDigitalGroup\StdLib\Objects\Calendar;
9+
10+
use EncoreDigitalGroup\StdLib\Objects\Support\Traits\HasEnumValue;
11+
12+
enum Month: string
13+
{
14+
use HasEnumValue;
15+
16+
case January = "january";
17+
case February = "february";
18+
case March = "march";
19+
case April = "april";
20+
case May = "may";
21+
case June = "june";
22+
case July = "july";
23+
case August = "august";
24+
case September = "september";
25+
case October = "october";
26+
case November = "november";
27+
case December = "december";
28+
29+
public function toInt(): int
30+
{
31+
return match ($this) {
32+
self::January => 1,
33+
self::February => 2,
34+
self::March => 3,
35+
self::April => 4,
36+
self::May => 5,
37+
self::June => 6,
38+
self::July => 7,
39+
self::August => 8,
40+
self::September => 9,
41+
self::October => 10,
42+
self::November => 11,
43+
self::December => 12,
44+
};
45+
}
46+
47+
public function next(): self
48+
{
49+
return match ($this) {
50+
self::January => self::February,
51+
self::February => self::March,
52+
self::March => self::April,
53+
self::April => self::May,
54+
self::May => self::June,
55+
self::June => self::July,
56+
self::July => self::August,
57+
self::August => self::September,
58+
self::September => self::October,
59+
self::October => self::November,
60+
self::November => self::December,
61+
self::December => self::January,
62+
};
63+
}
64+
65+
public function previous(): self
66+
{
67+
return match ($this) {
68+
self::January => self::December,
69+
self::February => self::January,
70+
self::March => self::February,
71+
self::April => self::March,
72+
self::May => self::April,
73+
self::June => self::May,
74+
self::July => self::June,
75+
self::August => self::July,
76+
self::September => self::August,
77+
self::October => self::September,
78+
self::November => self::October,
79+
self::December => self::November,
80+
};
81+
}
82+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/*
3+
* Copyright (c) 2025. Encore Digital Group.
4+
* All Rights Reserved.
5+
*/
6+
7+
use EncoreDigitalGroup\StdLib\Objects\Calendar\DayOfWeek;
8+
9+
describe("DayOfWeek Tests", function () {
10+
test("DayOfWeek enum values are correct", function () {
11+
expect(DayOfWeek::Sunday->value)->toBe("sunday")
12+
->and(DayOfWeek::Monday->value)->toBe("monday")
13+
->and(DayOfWeek::Tuesday->value)->toBe("tuesday")
14+
->and(DayOfWeek::Wednesday->value)->toBe("wednesday")
15+
->and(DayOfWeek::Thursday->value)->toBe("thursday")
16+
->and(DayOfWeek::Friday->value)->toBe("friday")
17+
->and(DayOfWeek::Saturday->value)->toBe("saturday");
18+
});
19+
20+
test("DayOfWeek toInt returns correct zero-based values", function () {
21+
expect(DayOfWeek::Sunday->toInt())->toBe(0)
22+
->and(DayOfWeek::Monday->toInt())->toBe(1)
23+
->and(DayOfWeek::Tuesday->toInt())->toBe(2)
24+
->and(DayOfWeek::Wednesday->toInt())->toBe(3)
25+
->and(DayOfWeek::Thursday->toInt())->toBe(4)
26+
->and(DayOfWeek::Friday->toInt())->toBe(5)
27+
->and(DayOfWeek::Saturday->toInt())->toBe(6);
28+
});
29+
30+
test("DayOfWeek toInt returns correct one-based values", function () {
31+
expect(DayOfWeek::Sunday->toInt(false))->toBe(1)
32+
->and(DayOfWeek::Monday->toInt(false))->toBe(2)
33+
->and(DayOfWeek::Tuesday->toInt(false))->toBe(3)
34+
->and(DayOfWeek::Wednesday->toInt(false))->toBe(4)
35+
->and(DayOfWeek::Thursday->toInt(false))->toBe(5)
36+
->and(DayOfWeek::Friday->toInt(false))->toBe(6)
37+
->and(DayOfWeek::Saturday->toInt(false))->toBe(7);
38+
});
39+
});
40+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/*
3+
* Copyright (c) 2025. Encore Digital Group.
4+
* All Rights Reserved.
5+
*/
6+
7+
use EncoreDigitalGroup\StdLib\Objects\Calendar\Month;
8+
9+
describe("Month Tests", function () {
10+
it("next() returns the correct next month for each month", function () {
11+
expect(Month::January->next())->toBe(Month::February)
12+
->and(Month::February->next())->toBe(Month::March)
13+
->and(Month::March->next())->toBe(Month::April)
14+
->and(Month::April->next())->toBe(Month::May)
15+
->and(Month::May->next())->toBe(Month::June)
16+
->and(Month::June->next())->toBe(Month::July)
17+
->and(Month::July->next())->toBe(Month::August)
18+
->and(Month::August->next())->toBe(Month::September)
19+
->and(Month::September->next())->toBe(Month::October)
20+
->and(Month::October->next())->toBe(Month::November)
21+
->and(Month::November->next())->toBe(Month::December)
22+
->and(Month::December->next())->toBe(Month::January);
23+
});
24+
25+
it("previous() returns the correct previous month for each month", function () {
26+
expect(Month::January->previous())->toBe(Month::December)
27+
->and(Month::February->previous())->toBe(Month::January)
28+
->and(Month::March->previous())->toBe(Month::February)
29+
->and(Month::April->previous())->toBe(Month::March)
30+
->and(Month::May->previous())->toBe(Month::April)
31+
->and(Month::June->previous())->toBe(Month::May)
32+
->and(Month::July->previous())->toBe(Month::June)
33+
->and(Month::August->previous())->toBe(Month::July)
34+
->and(Month::September->previous())->toBe(Month::August)
35+
->and(Month::October->previous())->toBe(Month::September)
36+
->and(Month::November->previous())->toBe(Month::October)
37+
->and(Month::December->previous())->toBe(Month::November);
38+
});
39+
40+
it("toInt() returns the correct integer value for each month", function () {
41+
expect(Month::January->toInt())->toBe(1)
42+
->and(Month::February->toInt())->toBe(2)
43+
->and(Month::March->toInt())->toBe(3)
44+
->and(Month::April->toInt())->toBe(4)
45+
->and(Month::May->toInt())->toBe(5)
46+
->and(Month::June->toInt())->toBe(6)
47+
->and(Month::July->toInt())->toBe(7)
48+
->and(Month::August->toInt())->toBe(8)
49+
->and(Month::September->toInt())->toBe(9)
50+
->and(Month::October->toInt())->toBe(10)
51+
->and(Month::November->toInt())->toBe(11)
52+
->and(Month::December->toInt())->toBe(12);
53+
});
54+
});

0 commit comments

Comments
 (0)