Page MenuHomePhabricator

Dateformat-Problems with field date
Open, Needs TriagePublic


If I use the date-field in a form, everything works fine if I give day, month and year or just the year. In the first case the form formats the date to YYYY/MM/DD and in the second case it uses just YYYY.
But it is also possible to give just month and year. In that case the date-field had to format it to YYYY/MM. But this is not the case, it formats the month to its name in local language and after that the year. Also, it does not parse the format YYYY/MM anyway as semantic Mediawiki does correctly.

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald TranscriptSep 20 2017, 3:21 PM

Does it mean to change date format when inputting date field while creating pages using forms?, if so should the changed one display YYYY/MM instead of MONTH YYYY?

made few small change it looked in the following manner before and after changes

and after change, I created a different page looked in following manner

I think this would solve this issue, uploading a patch to it

Change 409647 had a related patch set uploaded (by Rammanojpotla; owner: Rammanoj):
[mediawiki/extensions/PageForms@master] Change date format with month and year as input to forms

@redrooster - can you explain the problem with the current "Month YYYY" format?

@Yaron_Koren : The Problem is, that the Dateformat is inconsistent. If you pick day, month, year the format is YYYY/MM/DD, which is perfect. But if you pick just month and year, the format changes to Month YYYY (instead of YYYY/MM). That makes it hard to parse the date, because you never know if the month is a two-digit-integer or a word (it depends on what the user typed into the datefield). And if the Month is a word, it depends on the language how that specific date is named. If the Format would be YYYY/MM then I knew for sure, that the two digits after the first "/" stand for the month.

Ok, that patch worked for the output-part of the datepicker. But the Problem now is, that the datepicker still can not parse the YYYY/MM Format.

@redrooster thankyou for the reply but as the output is getting displayed in YYYY/MM format can you say what else is the problem with datepicker and about which parse are doesn't parse in YYYY/MM format?

The datepicker should be able to show its own date. But this does not work if the datefield is filled with a date in the YYYY/MM format. The datepicker only shows the correct date, if the date-field is filled with the old format (Monthname YYYY).

This comment was removed by Rammanojpotla.

@redrooster can you specify how to give only year and month as input without manually editing date field? because unless I manually edit I can't able to edit date while I am using datepicker as input type

In semantic Mediawiki you just have a Template which holds the date and if you call "Edit with Form" the right datepicker shows the given date. But the PageForms datepicker can not read the new dateformat YYYY/MM, just the old one like "Monthname YYYY".

@redrooster - what do you mean by "hard to parse the date"? Do you have your own code that tries to parse dates contained in template calls?

@Yaron_Koren - Exactly, I parse the dates to create user friendly templates that work together with semantic mediawiki. SMW already perfectly understands the dateformat YYYY/MM, your patch managed that the datepicker returns that dateformat, now I need the datepicker to use this format as input, too (if the date-value is already given).

@redrooster - you parse templates in order to create other templates? Sorry, there must be something I'm missing.

Are you saying that Semantic MediaWiki does not understand the "Month YYYY" format?

Also, just to clarify, I'm not sure yet if that recent patch should be merged in or not.

redrooster added a comment.EditedFeb 12 2018, 4:49 PM

Semantic Mediawiki understands the "Month YYYY" format, that's not the Problem. But SMW also understands "YYYY/MM". But the datepicker only understands "Month YYYY" and not "YYYY/MM", which should be fixed.

I don't parse templates, I parse the date-values in the template-arguments. And because of that I need a consistent, language independent dateformat like "YYYY/MM".

To explain that a little closer: If you already have "YYYY/MM/DD" for year, month and day and you already have "YYYY" for just the year, why do we not have "YYYY/MM" for year and month? That "Monthname YYYY"-format is simply inconsistent compared to the others.

But what's missing in your patch is the ability of the datepicker to also read that YYYY/MM dateformat. At this time, I manually edit the datepicker to, let's say "February 2016". The PageForm saves that as 2016/02 to my template (which is perfect), but it cannot read that date by itself and shows January 1970 in my case.

I know it's inconsistent, but, in written language, "Month YYYY" is much more common than "YYYY/MM".

I still don't understand what it is that your code does. Why can't it just take the date as-is?

@Rammanojpotla: Could you answer the last question please? :)

In wikis with chronic you have one page for every day, for example "3. Juli" and also a page for every year, say "2008". To link that pages properly to the semantic dates i have written a little date-parser with the onboard parser functions of mediawiki that simply parses the date-data from "2018/07/03" down to "[[3. Juli]] [[2018]]". But in the case you just give month and year you get "July 2018" as output, which should be transformed "Juli [[2018]]", which is not easy because of the different dateformat for that case.

@Aklapper - actually the question was directed to redrooster (but he figured that out).

@redrooster - okay, now I understand. What you're doing is a hack - and though hacks are sometimes necessary (I do them all the time), this hack doesn't seem like a good enough reason to change the month formatting. In this case, the problem is that SMW doesn't let you query on just part of a date, which is a limitation of SMW. I should note that, if you use the Cargo extension, it lets you be much more flexible about querying parts of a date, using SQL date functions. So that's an option.

Let me also note that I'm still open to the idea of changing the month formatting; I just don't think this by itself is enough of a reason to do it.

I figured the problem out myself now. The problem is, that the strtotime-function of php can not figure out the dateformat "YYYY/MM". So I added a little workaround in the PF_DateInput.php that solves that Problem:

$seconds = strtotime( $date );
$year = date( 'Y', $seconds );
$month = date( 'm', $seconds );
// Determine if there's a month but no day. There's no ideal
// way to do this, so: we'll just look for the total
// number of spaces, slashes and dashes, and if there's
// exactly one altogether, we'll guess that it's a month only.
$numSpecialChars = substr_count( $date, ' ' ) + substr_count( $date, '/' ) + substr_count( $date, '-' );
if ( $numSpecialChars == 1 ) {
  if ( substr_count( $date, '/' ) == 1) {
    $year = explode('/', $date)[0];
      $month = explode('/', $date)[1];
  return array( $year, $month, null );

Can you please test ancient dates with this?

62/04/25 - this is indeed the 25th of April in the year 62. SMW can correctly handle it, but if I click on edit with form, it show the 1st of January 1970 (in PF verson 4.2) and nothing is shown in the date form (as if no date was there) in PF 4.8:

however, if the date ist just "5" (birth date in year 5, no other dates known), thatn it shows 5 correctly in the field year.

you can see it here:

@Krabina - is that related to this issue, or is this a different bug?

I don't know. I was about to write a bug report when I encounterred this one that seems at least to be very related.

I would make it a separate bug report - these might be related, but I doubt there's one fix for both of them.