Skip to content

Commit 52bfaad

Browse files
committed
first commit
0 parents  commit 52bfaad

File tree

5 files changed

+68
-0
lines changed

5 files changed

+68
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace FernandoFauth\DateTime\Framework\Stdlib\DateTime\Filter;
7+
8+
use Magento\Framework\Stdlib\DateTime\Filter\Date;
9+
10+
/**
11+
* Date/Time filter. Converts datetime from localized to internal format.
12+
*
13+
* @api
14+
*/
15+
class DateTime extends Date
16+
{
17+
/**
18+
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
19+
*
20+
*/
21+
public function __construct(\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate)
22+
{
23+
parent::__construct($localeDate);
24+
$this->_localToNormalFilter = new \Zend_Filter_LocalizedToNormalized(
25+
[
26+
'date_format' => $this->_localeDate->getDateTimeFormat(
27+
\IntlDateFormatter::SHORT
28+
),
29+
]
30+
);
31+
$this->_normalToLocalFilter = new \Zend_Filter_NormalizedToLocalized(
32+
['date_format' => \Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT]
33+
);
34+
}
35+
36+
/**
37+
* Convert date from localized to internal format
38+
*
39+
* @param string $value
40+
* @return string
41+
* @throws \Exception
42+
* @since 100.1.0
43+
*/
44+
public function filter($value)
45+
{
46+
try {
47+
$dateTime = $this->_localeDate->date($value, null, false, false);
48+
return $dateTime->format('Y-m-d H:i:s');
49+
} catch (\Exception $e) {
50+
throw new \Exception("Invalid input datetime format of value '$value'", $e->getCode(), $e);
51+
}
52+
}
53+
}

FernandoFauth/DateTime/etc/di.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0"?>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
3+
<preference for="Magento\Framework\Stdlib\DateTime\Filter\DateTime" type="FernandoFauth\DateTime\Framework\Stdlib\DateTime\Filter\DateTime" />
4+
</config>

FernandoFauth/DateTime/etc/module.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?xml version="1.0"?>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
3+
<module name="FernandoFauth_DateTime" setup_version="0.0.1"/></config>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
\Magento\Framework\Component\ComponentRegistrar::register(
3+
\Magento\Framework\Component\ComponentRegistrar::MODULE,
4+
'FernandoFauth_DateTime',
5+
__DIR__
6+
);

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This module fix the date format bug ( Invalid input datetime format of value ).
2+
When the format is Day, Month and Year. dd\mm\YY .

0 commit comments

Comments
 (0)