fightbulc / moment.php

Parse, validate, manipulate, and display dates in PHP w/ i18n support. Inspired by moment.js
Other
973 stars 154 forks source link

Fatal error Locale string does not exist for key: months > 12 #61

Closed hirbod closed 8 years ago

hirbod commented 8 years ago

Hi @fightbulc

I did nothing - it just looks like moment.php does not like January.

Fatal error: Uncaught exception 'Moment\MomentException' with message 'Locale string does not exist for key: months > 12' in .../vendor/fightbulc/moment/src/MomentLocale.php:77 

Stack trace: 
#0 .../vendor/fightbulc/moment/src/MomentLocale.php(95): Moment\MomentLocale::getLocaleString(Array) 

#1 .../vendor/vendor/fightbulc/moment/src/MomentLocale.php(155): Moment\MomentLocale::renderLocaleString(Array) 

#2 .../vendor/fightbulc/moment/src/Moment.php(149): Moment\MomentLocale::renderSpecialLocaleTags('03. 12__0001') 

#3 .../class.Chat.inc.php(668): Moment\Moment->format('d. F') 

#4 .../vendor/fightbulc/moment/src/MomentLocale.php on line 77
hirbod commented 8 years ago

This caused the problem:

(new \Moment\Moment($message['createdate'], 'Europe/Berlin'))->subtractMonths(1)->format('d. F');

Looks like subtractMonths don't work when in Janurary. But also a short remember why I have to use it like this: #50

hirbod commented 8 years ago

After I've remove subtractMonths(1) the fatal error is gone, but my string is converted into 03. Februar again, instead of 03. Januar. As you could never fix this problem, could you have a look why subtractMonths is not working right now?

Edit: I also tried

$messages[$key]['date'] = date("d. F", strtotime($message['createdate']));

and this works correctly. There is a bug inside of your code.

fightbulc commented 8 years ago

Hey there. Whats inside of $message['createdate'] ?

hirbod commented 8 years ago

2016-01-03 16:17:07

fightbulc commented 8 years ago

Hirbod, I added a test for your issue but all comes out fine on my end as well as on travis' end. I am not having much time at the moment so that I can dig deeper but I am afraid something is off with your environment.

Have a look at the simple test: https://github.com/fightbulc/moment.php/blob/master/tests/unit/Moment/MomentGermanLocaleTest.php#L84

Did you try running this on another setup?

hirbod commented 8 years ago

I'm on Debian with PHP 5.4.45. Just tested on my test system (also Debian) with 5.5.31 - same problem. Maybe there is some Debian-Patched problem. No suhosin. I use XCache as cache for 5.4.45 - maybe this cause some problems. PHP 5.5 has APC as Caching-system by default. Which version did you test?

fightbulc commented 8 years ago

Yo. Follow the link to see which versions I am testing against: https://travis-ci.org/fightbulc/moment.php

I'd love to figure out the issue but I simply cannot make any time to try to setup your system. So the closest I can try to replicate is travis and my work environments which includes also different systems with some of my clients.

danhunsaker commented 8 years ago

It's interesting that running the equivalent of (new DateTime('2016-01-03 16:17:07', 'Europe/Berlin'))->modify('-1 month') would return a DateTime object with a month number of 13... Because that's the only situation that would cause this specific error to be raised, based on what I see in the code... What situations could cause that?

fightbulc commented 8 years ago

Hey there.

Running the following code either on my Mac or a Gentoo-Server returns the correct result of 2015-12-03T16:17:07+01:00

$d = (new Moment\Moment('2016-01-03 16:17:07', 'Europe/Berlin'))->modify('-1 month');
$d->format('c'); // 2015-12-03T16:17:07+01:00

I am running php56 on both machines.

hirbod commented 8 years ago

So I guess Debian / Gentoois the problem. Debian ships own patched PHP Versions, I guess somewhere there is the problem. Any chance to test on Debian ?