Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ e224e927dabcd3046455985118ed424c43aba054
20e2de4b44af7511cb0eb6e6f71676253b4c2667
e85fae4f7290329ac9cfae159e19c1bb55062e4b
10daa978ac4beebdbc8e9dcc6fa07657001fd91e
5bd6cc77c40f19059dbdda4704d2f380099b29e3
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,4 @@ fabric.properties
######## MacOS ########
##################################
.DS_Store
/.idea/copilotDiffState.xml
1 change: 1 addition & 0 deletions .idea/php-test-framework.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions src/Objects/Calendar/DayOfWeek.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/*
* Copyright (c) 2025. Encore Digital Group.
* All Rights Reserved.
*/

namespace EncoreDigitalGroup\StdLib\Objects\Calendar;

use EncoreDigitalGroup\StdLib\Objects\Support\Traits\HasEnumValue;

enum DayOfWeek: string
{
use HasEnumValue;

case Sunday = "sunday";
case Monday = "monday";
case Tuesday = "tuesday";
case Wednesday = "wednesday";
case Thursday = "thursday";
case Friday = "friday";
case Saturday = "saturday";

public function toInt(bool $zero = true): int
{
$int = match ($this->value) {
self::Sunday->value => 0,
self::Monday->value => 1,
self::Tuesday->value => 2,
self::Wednesday->value => 3,
self::Thursday->value => 4,
self::Friday->value => 5,
self::Saturday->value => 6,
};

if (!$zero) {
$int++;
}

return $int;
}
}
82 changes: 82 additions & 0 deletions src/Objects/Calendar/Month.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

/*
* Copyright (c) 2025. Encore Digital Group.
* All Rights Reserved.
*/

namespace EncoreDigitalGroup\StdLib\Objects\Calendar;

use EncoreDigitalGroup\StdLib\Objects\Support\Traits\HasEnumValue;

enum Month: string
{
use HasEnumValue;

case January = "january";
case February = "february";
case March = "march";
case April = "april";
case May = "may";
case June = "june";
case July = "july";
case August = "august";
case September = "september";
case October = "october";
case November = "november";
case December = "december";

public function toInt(): int
{
return match ($this) {
self::January => 1,
self::February => 2,
self::March => 3,
self::April => 4,
self::May => 5,
self::June => 6,
self::July => 7,
self::August => 8,
self::September => 9,
self::October => 10,
self::November => 11,
self::December => 12,
};
}

public function next(): self
{
return match ($this) {
self::January => self::February,
self::February => self::March,
self::March => self::April,
self::April => self::May,
self::May => self::June,
self::June => self::July,
self::July => self::August,
self::August => self::September,
self::September => self::October,
self::October => self::November,
self::November => self::December,
self::December => self::January,
};
}

public function previous(): self
{
return match ($this) {
self::January => self::December,
self::February => self::January,
self::March => self::February,
self::April => self::March,
self::May => self::April,
self::June => self::May,
self::July => self::June,
self::August => self::July,
self::September => self::August,
self::October => self::September,
self::November => self::October,
self::December => self::November,
};
}
}
40 changes: 40 additions & 0 deletions tests/Unit/CalendarTests/DayOfWeekTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/*
* Copyright (c) 2025. Encore Digital Group.
* All Rights Reserved.
*/

use EncoreDigitalGroup\StdLib\Objects\Calendar\DayOfWeek;

describe("DayOfWeek Tests", function () {
test("DayOfWeek enum values are correct", function () {
expect(DayOfWeek::Sunday->value)->toBe("sunday")
->and(DayOfWeek::Monday->value)->toBe("monday")
->and(DayOfWeek::Tuesday->value)->toBe("tuesday")
->and(DayOfWeek::Wednesday->value)->toBe("wednesday")
->and(DayOfWeek::Thursday->value)->toBe("thursday")
->and(DayOfWeek::Friday->value)->toBe("friday")
->and(DayOfWeek::Saturday->value)->toBe("saturday");
});

test("DayOfWeek toInt returns correct zero-based values", function () {
expect(DayOfWeek::Sunday->toInt())->toBe(0)
->and(DayOfWeek::Monday->toInt())->toBe(1)
->and(DayOfWeek::Tuesday->toInt())->toBe(2)
->and(DayOfWeek::Wednesday->toInt())->toBe(3)
->and(DayOfWeek::Thursday->toInt())->toBe(4)
->and(DayOfWeek::Friday->toInt())->toBe(5)
->and(DayOfWeek::Saturday->toInt())->toBe(6);
});

test("DayOfWeek toInt returns correct one-based values", function () {
expect(DayOfWeek::Sunday->toInt(false))->toBe(1)
->and(DayOfWeek::Monday->toInt(false))->toBe(2)
->and(DayOfWeek::Tuesday->toInt(false))->toBe(3)
->and(DayOfWeek::Wednesday->toInt(false))->toBe(4)
->and(DayOfWeek::Thursday->toInt(false))->toBe(5)
->and(DayOfWeek::Friday->toInt(false))->toBe(6)
->and(DayOfWeek::Saturday->toInt(false))->toBe(7);
});
});

54 changes: 54 additions & 0 deletions tests/Unit/CalendarTests/MonthTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
/*
* Copyright (c) 2025. Encore Digital Group.
* All Rights Reserved.
*/

use EncoreDigitalGroup\StdLib\Objects\Calendar\Month;

describe("Month Tests", function () {
it("next() returns the correct next month for each month", function () {
expect(Month::January->next())->toBe(Month::February)
->and(Month::February->next())->toBe(Month::March)
->and(Month::March->next())->toBe(Month::April)
->and(Month::April->next())->toBe(Month::May)
->and(Month::May->next())->toBe(Month::June)
->and(Month::June->next())->toBe(Month::July)
->and(Month::July->next())->toBe(Month::August)
->and(Month::August->next())->toBe(Month::September)
->and(Month::September->next())->toBe(Month::October)
->and(Month::October->next())->toBe(Month::November)
->and(Month::November->next())->toBe(Month::December)
->and(Month::December->next())->toBe(Month::January);
});

it("previous() returns the correct previous month for each month", function () {
expect(Month::January->previous())->toBe(Month::December)
->and(Month::February->previous())->toBe(Month::January)
->and(Month::March->previous())->toBe(Month::February)
->and(Month::April->previous())->toBe(Month::March)
->and(Month::May->previous())->toBe(Month::April)
->and(Month::June->previous())->toBe(Month::May)
->and(Month::July->previous())->toBe(Month::June)
->and(Month::August->previous())->toBe(Month::July)
->and(Month::September->previous())->toBe(Month::August)
->and(Month::October->previous())->toBe(Month::September)
->and(Month::November->previous())->toBe(Month::October)
->and(Month::December->previous())->toBe(Month::November);
});

it("toInt() returns the correct integer value for each month", function () {
expect(Month::January->toInt())->toBe(1)
->and(Month::February->toInt())->toBe(2)
->and(Month::March->toInt())->toBe(3)
->and(Month::April->toInt())->toBe(4)
->and(Month::May->toInt())->toBe(5)
->and(Month::June->toInt())->toBe(6)
->and(Month::July->toInt())->toBe(7)
->and(Month::August->toInt())->toBe(8)
->and(Month::September->toInt())->toBe(9)
->and(Month::October->toInt())->toBe(10)
->and(Month::November->toInt())->toBe(11)
->and(Month::December->toInt())->toBe(12);
});
});