Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
DateInvalidTimeZoneException example
/** * @throws \DateInvalidTimeZoneException When $timezone is invalid */
public
function
withTimeZone
(
\DateTimeZone|string
$timezone
)
:
static
{
if
(
\PHP_VERSION_ID >= 80300 && \
is_string
(
$timezone
)
)
{
$timezone
=
new
\
DateTimeZone
(
$timezone
)
;
}
elseif
(
\
is_string
(
$timezone
)
)
{
try
{
$timezone
=
new
\
DateTimeZone
(
$timezone
)
;
}
catch
(
\Exception
$e
)
{
throw
new
\
DateInvalidTimeZoneException
(
$e
->
getMessage
(
)
,
$e
->
getCode
(
)
,
$e
)
;
}
}
$clone
=
clone
$this
;
$clone
->timezone =
$timezone
;
return
$clone
;
}
}
/** * @throws \DateInvalidTimeZoneException When $timezone is invalid */
public
function
withTimeZone
(
\DateTimeZone|string
$timezone
)
:
static
{
if
(
\PHP_VERSION_ID >= 80300 && \
is_string
(
$timezone
)
)
{
$timezone
=
new
\
DateTimeZone
(
$timezone
)
;
}
elseif
(
\
is_string
(
$timezone
)
)
{
try
{
$timezone
=
new
\
DateTimeZone
(
$timezone
)
;
}
catch
(
\Exception
$e
)
{
throw
new
\
DateInvalidTimeZoneException
(
$e
->
getMessage
(
)
,
$e
->
getCode
(
)
,
$e
)
;
}
}
$clone
=
clone
$this
;
$clone
->timezone =
$timezone
;
return
$clone
;
}
}
public
function
__construct
(
\DateTimeImmutable|string
$now
= 'now', \DateTimeZone|string
$timezone
= null
)
{
if
(
\PHP_VERSION_ID >= 80300 && \
is_string
(
$timezone
)
)
{
$timezone
=
new
\
DateTimeZone
(
$timezone
)
;
}
elseif
(
\
is_string
(
$timezone
)
)
{
try
{
$timezone
=
new
\
DateTimeZone
(
$timezone
)
;
}
catch
(
\Exception
$e
)
{
throw
new
\
DateInvalidTimeZoneException
(
$e
->
getMessage
(
)
,
$e
->
getCode
(
)
,
$e
)
;
}
}
if
(
\
is_string
(
$now
)
)
{
$now
=
new
DatePoint
(
$now
,
$timezone
??
new
\
DateTimeZone
(
'UTC'
)
)
;
}
elseif
(
!
$now
instanceof DatePoint
)
{
$now
= DatePoint::
createFromInterface
(
$now
)
;
}
$this
->now = null !==
$timezone
?
$now
->
setTimezone
(
$timezone
)
:
$now
;
}
/** * @throws \DateInvalidTimeZoneException When $timezone is invalid */
public
function
withTimeZone
(
\DateTimeZone|string
$timezone
)
:
static
{
if
(
\PHP_VERSION_ID >= 80300 && \
is_string
(
$timezone
)
)
{
$timezone
=
new
\
DateTimeZone
(
$timezone
)
;
}
elseif
(
\
is_string
(
$timezone
)
)
{
try
{
$timezone
=
new
\
DateTimeZone
(
$timezone
)
;
}
catch
(
\Exception
$e
)
{
throw
new
\
DateInvalidTimeZoneException
(
$e
->
getMessage
(
)
,
$e
->
getCode
(
)
,
$e
)
;
}
}
$clone
=
clone
$this
;
$clone
->timezone =
$timezone
;
return
$clone
;
}
}
return
parent::
setTime
(
$hour
,
$minute
,
$second
,
$microsecond
)
;
}
public
function
setTimezone
(
\DateTimeZone
$timezone
)
:
static
{
return
parent::
setTimezone
(
$timezone
)
;
}
public
function
getTimezone
(
)
: \DateTimeZone
{
return
parent::
getTimezone
(
)
?:
throw
new
\
DateInvalidTimeZoneException
(
'The DatePoint object has no timezone.'
)
;
}
}