[Solved] Data Structure for keeping time and day of the week PHP


Untested and probably not the best way

class TimeWeekday {
    private $hour;
    private $minute;
    private $day;

    private $days = array('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday');

    public function __construct($hour, $minute, $day) {
        $this->hour = $hour;
        $this->minute = $minute;
        $this->day = $day;
    }

    public function add($hours, $minutes, $days = 0) {
        $newMinutes = $this->minute + $minutes;
        $this->minute = $newMinutes % 60;
        if ($this->minute < 0) {
            $this->minute += 60;
        }
        $newHours = $this->hour + $hours + floor($newMinutes / 60);
        $this->hour = $newHours % 24;
        if ($this->hour < 0) {
            $this->hour += 24;
        }
        $newDay = $this->day + $days + floor($newHours / 60);
        $this->day = $newDay % 7;
        if ($this->day < 0) {
            $this->day += 7;
        }
    }

    public function substract($hours, $minurtes, $days = 0) {
        $this->add(-$hours, -$minurtes, -$days);
    }

    public function getValue() {
        return sprintf('%02d:%02d %s', $this->hour, $this->minute, $this->days[$this->day]);
    }
}

.

$x = new TimeWeekday(22, 3, 6);
$x->add(3,0);
echo $x->getValue();

solved Data Structure for keeping time and day of the week PHP