Long story short, using date/date_pop with a date_format of 'Ymd' generate 'Year not valid'. After tracing through the code the culprit seems to be in date_api.module. function date_format_patters returns '-?\d{1,6}' for the key of 'Y'. I can't think of any instance where a year should be 6 digits. For my install I changed this to 'Y' => '-?\d{1,4}' and it works fine. I've tested it with 'Ymd' and 'Y-m-d' and both instances work. I have not tested with any other format so if this will break something else, please let me know. Also just as a side note, 'Y-m-d' works fine. it's only if there is no separator that I see this issue.
not working (for Ymd)
'Y' => '-?\d{1,6}'
working (for Ymd)
'Y' => '-?\d{1,4}'
UPDATE: patches included for date-7.x-2.6, date-7.x-2.8 and current dev (gngn, 2014-12-12)
Comment | File | Size | Author |
---|---|---|---|
#12 | Screenshot 2018-11-14 at 13.30.38.png | 44.89 KB | steinmb |
#12 | Screenshot 2018-11-14 at 13.29.58.png | 19.74 KB | steinmb |
#8 | date-7.x-2.8-Y-format-error-2053955-6.patch | 403 bytes | gngn |
#4 | date-Y-format-error-2053955-4.patch | 403 bytes | gngn |
#3 | date-Y-format-error-2053955-3.patch | 403 bytes | hauruck |
Comments
Comment #1
itsekhmistro CreditAttribution: itsekhmistro commentedI came up with the same patch for date_format_patters() :
'Y' => '-?\d{1,4}'
Could someone clarify in which case a six-digit long Year number ('Y' => '-?\d{1,6}') is possible?
Or its a long-live bug ? (seems it was originally posted https://drupal.org/node/1086240 but closed)
Comment #2
vijaycs85Back to active as per http://drupal.org/node/156119
Comment #3
hauruck CreditAttribution: hauruck commentedSame problem here, such a small change I could not resist trying to make a patch for the first time :-)
Comment #4
gngn CreditAttribution: gngn at Computer Manufaktur GmbH commentedThe same problem still occurs in 7.x-2.8 and current dev version.
And the same solution helped me.
So here is a patch for current dev.
btw: the issue is for 7.x-2.6 - so should I open a new issue with the patch?
Comment #5
gngn CreditAttribution: gngn commentedComment #8
gngn CreditAttribution: gngn at Computer Manufaktur GmbH commentedAnd another one for the current stable release 7.x-2.8
I also putting this to "Needs review".
I think the automatic test failedbecause of the wrong version number, so I'm also changing this to 7.x-2.8.
Or should I change the version back, create another issue for dev and/or current stable or...?
And I'm also interested if a six-digit long Year number makes sense anywhere ;)
Comment #9
gngn CreditAttribution: gngn commentedComment #10
awolfey CreditAttribution: awolfey commentedWorks for me. Thanks.
Comment #11
steinmb CreditAttribution: steinmb as a volunteer commentedComment #12
steinmb CreditAttribution: steinmb as a volunteer commentedPatch still apply cleanly
Before applying patch
Goto /admin/config/regional/date-time/formats and add the custom formats: Y.m.d, Y-m-d and Ymd
Both Y.m.d and Y-m-d works without the patch. Ymd does now.
After applying the patch all three works. RTBC from me. Not sure if there should be tests for these formats?
Comment #13
DamienMcKennaI think some brief test coverage would be useful for this.