This repository has been archived by the owner on Apr 11, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c6a87df
commit 7fb0274
Showing
2 changed files
with
20 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,8 @@ final class DateFormat | |
|
||
const REGEXP_MYSQL_DATE_TIME = '/[0-9]{4}-[0-9]{1,2}-[0-9]{1,2} [0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}$/'; | ||
|
||
const REGEXP_ElASTICSEARCH_DATE_TIME = '/[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}T[0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}$/'; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
eddiejaoude
Author
Contributor
|
||
|
||
const REGEXP_BANKTEC_FORMAT = '/^\d{8}$/'; | ||
/** | ||
* @var string | ||
|
@@ -33,6 +35,11 @@ final class DateFormat | |
*/ | ||
protected static $DateTimeSqlExport = 'Y-m-d H:i:s'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected static $DateTimeElasticSearch = 'Y-m-d\TH:i:s'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
|
@@ -62,6 +69,14 @@ public static function getSqlDateTimeFormat() | |
return self::$DateTimeSqlExport; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public static function getElasticSearchDateTimeFormat() | ||
{ | ||
return self::$DateTimeElasticSearch; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
|
@@ -95,6 +110,10 @@ public static function createDateTime($strDateTime) | |
return \DateTime::createFromFormat(self::getBanktecFormat(), $strDateTime); | ||
} | ||
|
||
if(preg_match(self::REGEXP_ElASTICSEARCH_DATE_TIME, trim($strDateTime))) { | ||
return \DateTime::createFromFormat(self::getElasticSearchDateTimeFormat(), $strDateTime); | ||
} | ||
|
||
throw new InvalidDateFormatException( | ||
"'{$strDateTime}' was not in the expected format " . self::getDateTimeFormat() | ||
); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 comment
on commit 7fb0274
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@brettminnie Added this to fix build for the changes src/Opg/Common/Model/Entity/Traits/Time.php:71
return $this->setCreatedTime(OPGDateFormat::createDateTime($createdTime));
Could we not rather make the T optional and then just reuse the REGEXP_MYSQL_DATE_TIME , something like
'/[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}(\s|T)[0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}$/
Haven't tested if this works but it should :)