Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Mootools Datepicker d.m.y #7831

Open
fjacobi opened this issue May 19, 2015 · 5 comments
Open

Mootools Datepicker d.m.y #7831

fjacobi opened this issue May 19, 2015 · 5 comments
Labels

Comments

@fjacobi
Copy link

fjacobi commented May 19, 2015

When setting the backend date format to "d.m.y" the datepicker will show 1970 instead of the actual value.

Tested on the demo.
Reproducible:
Logging into the backend, going to Settings and changing date format to "d.m.y" and try to change the default value (not empty) of an datepicker field.

@fritzmg
Copy link
Contributor

fritzmg commented May 22, 2015

Changing the date format in the System Settings is not recommended in general. If you want to change the frontend output, you should do that in the page root settings.

@fjacobi
Copy link
Author

fjacobi commented May 22, 2015

Yes, but this is about data maintenance in the backend.
Customer wants to streamline date formats between data input in Contao and his internal software, so the editor can copy & paste.

And even if it isn't recommended, I don't think a feature, which has been around for years, should break other features.

@dmolineus
Copy link
Contributor

The date picker requires the year with 4 numbers as far as I remember. You have to use Y. Then you can use the German date format in the backend as well.

@fjacobi
Copy link
Author

fjacobi commented May 23, 2015

Then the date picker is faulty, because it states Mootools More as a dependency and the More/Date can definitely parse german dates.

https://jsfiddle.net/jvase62t/

Imho there is a bug somewhere - not in Contao though.
But this should be documented somewhere.

@Aybee
Copy link
Contributor

Aybee commented May 24, 2015

Datepicker uses MooTools Date.parse() function. This parses a date from a string and can only work correct if the appropriate Locale is loaded and the parsers are defined correctly.
http://mootools.net/more/docs/1.5.1/Types/Date#Date:Date-defineParser
http://mootools.net/more/docs/1.5.1/Types/Date#Date:Date-defineParsers

But even this will be faulty as long as we have the choice to set back end language format as we like e.g. m.y.d

In Contao we don't load the Locales. We use en-US with all languages and define it according to the back end language.

// back end language de
Locale.define("en-US", "Date", {
    months: ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"],
    days: ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"],
    months_abbr: ["Jan", "Feb", "Mär", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"],
    days_abbr: ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"]
});
Locale.define("en-US", "DatePicker", {
    select_a_time: "Uhrzeit auswählen",
    use_mouse_wheel: "Ändern Sie die Werte mit Hilfe des Mausrads",
    time_confirm_button: "OK",
    apply_range: "Anwenden",
    cancel: "Abbrechen",
    week: "W"
});

Additionaly the parsers in the Contao MooTools more are patched.
https://github.com/contao/core/blob/master/assets/mootools/core/1.5.1/mootools-more-uncompressed.js as parsers can not be deleted on the fly and then newly get defined.

Look at your fiddle example - it's not correct. You want april as month but it is january.

We can do some things to repair back end JS date from string parsing. (this is an OR list)

  • Use UTC format (YYYY.dd.mmT00:00) in all languages and make language format settings in back end only to work for front end output.
  • Add new parsers for 2 digits year https://jsfiddle.net/Andreas/f80rvgkv/ I think this is not save.
  • Set the dateOrder to d m y https://jsfiddle.net/Andreas/75fLfdxk/ I think this is not save.
  • Remove all parsers from mootools more and add a parser on the fly respecting the back end date format setting.
  • Patch the Datepicker with a new option that tells datepicker the format of the string that has to be parsed to a date. http://jsfiddle.net/Andreas/w3ux24qs/ But then how should datepicker know if you want 1916 or 2016 if you have 31.12.16?

I think this has to be discussed. IMHO setting one parser on the fly with appropriate dateOrder setting or using only UTC will work.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants