Datepicker doesn't understand format "%d.%m.%Y" #111

Open
DyaGa opened this Issue Mar 5, 2012 · 3 comments

Projects

None yet

4 participants

@DyaGa
DyaGa commented Mar 5, 2012

Example:

http://gyazo.com/3f27e0f9bc34dc80aa2d4911dea4cf98.png?1330963702

The date is 04.02.2010 (February 04, 2010) but Datepicker show this as 02.04.2010 (April 02, 2010).

Here is the code from example:

<input type="text" name="date" id="ctrl_date" class="tl_text" value="04.02.2010" onfocus="Backend.getScrollOffset()"> <img src="plugins/datepicker/icon.gif" width="20" height="20" alt="" id="toggle_date" style="vertical-align:-6px">
  <script>
  window.addEvent("domready", function() {
    new Picker.Date($$("#ctrl_date"), {
      draggable:false,
      toggle:$$("#toggle_date"),
      format:"%d.%m.%Y",
      positionOffset:{x:-197,y:-182},
      pickerClass:"datepicker_dashboard",
      useFadeInOut:!Browser.ie,
      startDay:0,
      titleFormat:"%B %d%o, %Y"
    });
  });
  </script>

P.S. Sorry for my bad English.

@jonjhiggins

Whilst maybe the format should work independently of it, I got %d.%m.%Y to work by changing MooTools's Locale (http://mootools.net/docs/more/Locale/Date) to one that supports %d.%m.%Y by default, in my case 'en-GB'.

@newbie78

Hi!
I have similar problem.
As i have found out that "format" option in this extension uses only in case the user selects the date in calendar.

The datepiker uses mootools Date.parse method to parse string with date (see http://mootools.net/docs/more/Types/Date#Date:parse). In that method it is used the parsePatterns array of patterns. But I was surprised when i now: That there is no possibility to add new pattern to the beginning to this array. Only to the end of array (see Date.defineParser() method). And this array is out of the variable scope.

When datepicker runs Date.parse it skipping through the parsePatterns.
And third pattern match the our string.
But as our pattern is at the end of array it can't match our string.

That's all :*(

@iperatoner

For me, the following workaround did the trick. It moves the newly defined date parser to the beginning of the Date.parsePatterns array:

Date.defineParser("%d.%m.%Y");
var definedParser = Date.parsePatterns.pop();
Date.parsePatterns.unshift(definedParser);

Hope it helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment