Comments (2)
Hey Jarek. Can u create a pull request? I'll have a look later and merge it
in if all seems fine.
Thanks.
Cheers
Tino
On Wednesday, October 1, 2014, jarekkozak [email protected] wrote:
Hi again,
I'm wondering why Moment accepts ISO8601 format in limited way, only
YYYY-MM-DDTHH:mm:ss?
It would be more useful if Moment would accept full ISO8601. DateTime
accepts all ISO formats,
I investigated a bit code and found that isValid method is responsible for
that.
I have rewrited it and now it works as I would like it to do. If you find
it interesting , you can use it.protected function isValidDate()
{
$rawDateTime = $this->getRawDateTimeString();if (strpos($rawDateTime, '-') === false) { return true; } // ---------------------------------- // time with indicator "T" if (strpos($rawDateTime, 'T') !== false) { //We remove fraction if any ... DateTime holds only seconds $rawDateTime = preg_replace('/\.[0-9][0-9][0-9]/', '', $rawDateTime); $rawTimeZone = substr($rawDateTime, 19); if ($rawTimeZone && strpos($rawTimeZone, '+') !== FALSE) { if (substr_count($rawTimeZone, ':') > 0) { $momentDateTime = $this->format('Y-m-d\TH:i:sP'); } else { $momentDateTime = $this->format('Y-m-d\TH:i:sO'); } } elseif ($rawTimeZone) { $momentDateTime = $this->format('Y-m-d\TH:i:se'); } else { $momentDateTime = $this->format('Y-m-d\TH:i:s'); } } // time without indicator "T" elseif (strpos($rawDateTime, ':') !== false) { if (substr_count($rawDateTime, ':') === 2) { // with seconds $momentDateTime = $this->format('Y-m-d H:i:s'); } else { $momentDateTime = $this->format('Y-m-d H:i'); } } // without time else { $momentDateTime = $this->format('Y-m-d'); } return $rawDateTime === $momentDateTime; }
and tests
public function testMoment(){ $data = '1923-12-31 12:30:00'; $m = new Moment($data); $this->assertEquals('1923-12-31T12:30:00+0000', $m->format()); $data = '1923-12-31T12:30:00.000'; $m = new Moment($data); $this->assertEquals('1923-12-31T12:30:00+0000', $m->format()); $data = '1923-12-31T12:30:00.123'; $m = new Moment($data); $this->assertEquals('1923-12-31T12:30:00+0000', $m->format()); $data = '1923-12-31T12:30:00.123+02:00'; $m = new Moment($data); $this->assertEquals('1923-12-31T12:30:00+0200', $m->format()); $data = '1923-12-31T12:30:00.123+0200'; $m = new Moment($data); $this->assertEquals('1923-12-31T12:30:00+0200', $m->format()); $data = '1923-12-31T12:30:00.123Z'; $m = new Moment($data); $this->assertEquals('1923-12-31T12:30:00+0000', $m->format()); $data = '1923-12-31T12:30:00.123Europe/Warsaw'; $m = new Moment($data); $this->assertEquals('1923-12-31T12:30:00+0100', $m->format()); $data = '1923-12-31T12:30:00.123Europe/Warsaw'; $m = new Moment($data,'UTC'); $this->assertEquals('1923-12-31T12:30:00+0100', $m->format()); $data = '1923-12-31T12:30:00.123UTC'; $m = new Moment($data,'Europe/Warsaw'); $this->assertEquals('1923-12-31T12:30:00+0000', $m->format()); $this->tester->printVar($m->format()); //$this->assertEquals('1923-12-31T12:30:Z', $m->format()); }
Best regards,
Jarek—
Reply to this email directly or view it on GitHub
#17.
Tino Ehrich
EFIDES E-SERVICES
web solutions powered by experience
{ "Beauty doesn't mean to be caught
by the eye but rather to be kept in mind." }
Giorgio Armani
from moment.php.
note to myself: http://en.wikipedia.org/wiki/ISO_8601
from moment.php.
Related Issues (20)
- getRelative time is broken in many cases HOT 5
- Seemingly valid RFC2822 returned as invalid HOT 1
- fix missing getRelative 'ss' in many locales HOT 1
- we need a proper date validation HOT 2
- need to fix relativeTime strings for Hungarian
- Declaration warning - PHP 7.1.22 HOT 1
- Lost functions vs moment js HOT 1
- getRelative() returns "0 years ago"
- IsBetween error function HOT 2
- Slovak Translation HOT 2
- Incorrect timezone parsing W3C + DTS
- builds failing due to PHP 5.x errors HOT 1
- Please add support all the way to Microseconds
- MomentJS format needs locale based adjustments
- Get unrounded date diff
- PHP Deprecated
- fetchSimilarLocales: All-lowercase Accept-Language header doesn't work
- ADD recognize weeks
- createFromFormat not compatible - PHP 8 HOT 2
- Moving to 2.0.0 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from moment.php.