Skip to content

Commit

Permalink
feat(core): Add a DataTime to Zulu time format util
Browse files Browse the repository at this point in the history
  • Loading branch information
medz committed Jul 23, 2018
1 parent e6b9dd4 commit bfba02d
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions app/Utils/DateTimeToIso8601ZuluString.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2018 Chengdu ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to version 2.0 of the Apache license, |
* | that is bundled with this package in the file LICENSE, and is |
* | available through the world-wide-web at the following url: |
* | http://www.apache.org/licenses/LICENSE-2.0.html |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/

namespace Zhiyi\Plus\Utils;

use Carbon\Carbon;

trait DateTimeToIso8601ZuluString
{
/**
* DateTime to ISO 8601 Zulu time.
*
* @param {\DateTime|string|null} $dateTime
* @return string
*/
protected function dateTimeToIso8601ZuluString($dateTime = null): ?string
{
if (is_null($dateTime) || empty($dateTime)) {
return null;
} elseif (!($dateTime instanceof Carbon)) {
$dateTime = new Carbon($dateTime);
}

return $dateTime->toIso8601ZuluString();
}
}

0 comments on commit bfba02d

Please sign in to comment.