Skip to content

Commit

Permalink
main
Browse files Browse the repository at this point in the history
  • Loading branch information
6562680 committed Dec 5, 2024
1 parent d5b899c commit 2ab376a
Show file tree
Hide file tree
Showing 22 changed files with 2,077 additions and 570 deletions.
351 changes: 232 additions & 119 deletions README.md

Large diffs are not rendered by default.

249 changes: 134 additions & 115 deletions src/Calendar.php

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions src/CalendarFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Gzhegow\Calendar;

class CalendarFactory implements CalendarFactoryInterface
{
public function newCalendar() : CalendarInterface
{
return new Calendar();
}
}
8 changes: 8 additions & 0 deletions src/CalendarFactoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Gzhegow\Calendar;

interface CalendarFactoryInterface
{
public function newCalendar() : CalendarInterface;
}
100 changes: 97 additions & 3 deletions src/CalendarInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,103 @@

namespace Gzhegow\Calendar;

/**
* @mixin Calendar
*/
interface CalendarInterface
{
/**
* @param callable|null $fnDateFormatter
*/
public function setFnDateFormatter(?callable $fnDateFormatter) : void;

/**
* @param callable|null $fnDateIntervalFormatter
*/
public function setFnDateIntervalFormatter(?callable $fnDateIntervalFormatter) : void;


/**
* @param string|\DateTimeZone $timezoneDefault
*/
public function setTimezoneDefault($timezoneDefault) : void;

/**
* @param array|string[] $parseFormatsDefault
*/
public function setParseFormatsDefault(array $parseFormatsDefault) : void;



public function dateTime($datetime = 'now', $timezone = null) : \DateTime;

public function dateTimeImmutable($datetime = 'now', $timezone = null) : \DateTimeImmutable;

public function dateTimeZone($timezone = 'UTC') : \DateTimeZone;

public function dateInterval($duration = 'P0D') : \DateInterval;


public function now($timezone = null) : \DateTime;

public function nowImmutable($timezone = null) : \DateTimeImmutable;


public function parseDateTime($datetime, array $formats = null, $timezoneIfParsed = null) : ?\DateTime;

public function parseDateTimeImmutable($datetime, array $formats = null, $timezoneIfParsed = null) : ?\DateTimeImmutable;

public function parseDateTimeZone($timezone) : ?\DateTimeZone;

public function parseDateInterval($interval, array $formats = null) : ?\DateInterval;


public function diff(\DateTimeInterface $from, \DateTimeInterface $to, bool $absolute = null) : \DateInterval;


public function formatHuman(?\DateTimeInterface $dateTime) : ?string;

public function formatDay(?\DateTimeInterface $dateTime) : ?string;

public function formatAgo(?\DateTimeInterface $dateTime, \DateTimeInterface $from = null) : ?string;


public function formatTimestamp(?\DateTimeInterface $dateTime) : ?string;

public function formatTimestampUTC(?\DateTimeInterface $dateTime) : ?string;


public function formatMilliseconds(?\DateTimeInterface $dateTime) : ?string;

public function formatMillisecondsUTC(?\DateTimeInterface $dateTime) : ?string;


public function formatMicroseconds(?\DateTimeInterface $dateTime) : ?string;

public function formatMicrosecondsUTC(?\DateTimeInterface $dateTime) : ?string;


public function formatSql(?\DateTimeInterface $dateTime) : ?string;

public function formatSqlUTC(?\DateTimeInterface $dateTime) : ?string;


public function formatSqlMicroseconds(?\DateTimeInterface $dateTime) : ?string;

public function formatSqlMicrosecondsUTC(?\DateTimeInterface $dateTime) : ?string;


public function formatSqlMilliseconds(?\DateTimeInterface $dateTime) : ?string;

public function formatSqlMillisecondsUTC(?\DateTimeInterface $dateTime) : ?string;


public function formatJavascript(?\DateTimeInterface $dateTime) : ?string;

public function formatJavascriptUTC(?\DateTimeInterface $dateTime) : ?string;


public function formatJavascriptMilliseconds(?\DateTimeInterface $dateTime) : ?string;

public function formatJavascriptMillisecondsUTC(?\DateTimeInterface $dateTime) : ?string;


public function formatIntervalISO(?\DateInterval $dateInterval) : ?string;
}
27 changes: 16 additions & 11 deletions src/Type.php → src/CalendarType.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@

namespace Gzhegow\Calendar;

use Gzhegow\Calendar\Struct\DateTime;
use Gzhegow\Calendar\Struct\DateInterval;
use Gzhegow\Calendar\Struct\DateTimeZone;
use Gzhegow\Calendar\Struct\DateTimeImmutable;


class Type
class CalendarType
{
/**
* @return class-string<\DateInterval>
Expand Down Expand Up @@ -48,31 +43,39 @@ public static function dateTimeZone() : string
*/
protected function _dateInterval() : string
{
return DateInterval::class;
return PHP_VERSION_ID >= 80000
? \Gzhegow\Calendar\Struct\PHP8\DateInterval::class
: \Gzhegow\Calendar\Struct\PHP7\DateInterval::class;
}

/**
* @return class-string<\DateTime>
*/
protected function _dateTime() : string
{
return DateTime::class;
return PHP_VERSION_ID >= 80000
? \Gzhegow\Calendar\Struct\PHP8\DateTime::class
: \Gzhegow\Calendar\Struct\PHP7\DateTime::class;
}

/**
* @return class-string<\DateTimeImmutable>
*/
protected function _dateTimeImmutable() : string
{
return DateTimeImmutable::class;
return PHP_VERSION_ID >= 80000
? \Gzhegow\Calendar\Struct\PHP8\DateTimeImmutable::class
: \Gzhegow\Calendar\Struct\PHP7\DateTimeImmutable::class;
}

/**
* @return class-string<\DateTimeZone>
*/
protected function _dateTimeZone() : string
{
return DateTimeZone::class;
return PHP_VERSION_ID >= 80000
? \Gzhegow\Calendar\Struct\PHP8\DateTimeZone::class
: \Gzhegow\Calendar\Struct\PHP7\DateTimeZone::class;
}


Expand All @@ -81,7 +84,9 @@ protected function _dateTimeZone() : string
*/
public static function getInstance() : self
{
return static::$instance = static::$instance ?? new static();
return static::$instance = null
?? static::$instance
?? new static();
}

public static function setInstance(self $instance) : void
Expand Down
81 changes: 81 additions & 0 deletions src/Exception/Exception.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

namespace Gzhegow\Calendar\Exception;


class Exception extends \Exception
implements ExceptionInterface
{
/**
* @var string
*/
public $file;
/**
* @var int
*/
public $line;

/**
* @var \Throwable
*/
public $previous;

/**
* @var string
*/
protected $message;
/**
* @var int
*/
protected $code;


public function __construct(...$errors)
{
foreach ( \Gzhegow\Calendar\Lib::php_throwable_args(...$errors) as $k => $v ) {
if (property_exists($this, $k)) {
$this->{$k} = $v;
}
}

parent::__construct($this->message, $this->code, $this->previous);
}


/**
* @var \Throwable[]
*/
protected $previousList = [];

/**
* @return \Throwable[]
*/
public function getPreviousList() : array
{
return $this->previousList;
}

/**
* @return static
*/
public function setPreviousList(array $previousList)
{
$this->previousList = [];

foreach ( $previousList as $previous ) {
$this->addPrevious($previous);
}

return $this;
}

/**
* @return static
*/
public function addPrevious(\Throwable $previous) // : static
{
$this->previousList[] = $previous;

return $this;
}
}
8 changes: 8 additions & 0 deletions src/Exception/ExceptionInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Gzhegow\Calendar\Exception;

interface ExceptionInterface
{

}
81 changes: 81 additions & 0 deletions src/Exception/LogicException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

namespace Gzhegow\Calendar\Exception;


class LogicException extends \LogicException
implements ExceptionInterface
{
/**
* @var string
*/
public $file;
/**
* @var int
*/
public $line;

/**
* @var \Throwable
*/
public $previous;

/**
* @var string
*/
protected $message;
/**
* @var int
*/
protected $code;


public function __construct(...$errors)
{
foreach ( \Gzhegow\Calendar\Lib::php_throwable_args(...$errors) as $k => $v ) {
if (property_exists($this, $k)) {
$this->{$k} = $v;
}
}

parent::__construct($this->message, $this->code, $this->previous);
}


/**
* @var \Throwable[]
*/
protected $previousList = [];

/**
* @return \Throwable[]
*/
public function getPreviousList() : array
{
return $this->previousList;
}

/**
* @return static
*/
public function setPreviousList(array $previousList)
{
$this->previousList = [];

foreach ( $previousList as $previous ) {
$this->addPrevious($previous);
}

return $this;
}

/**
* @return static
*/
public function addPrevious(\Throwable $previous) // : static
{
$this->previousList[] = $previous;

return $this;
}
}
Loading

0 comments on commit 2ab376a

Please sign in to comment.