[ 7 posts ]

Cristian Ciobanu

  • Username: cioby23
  • Joined: Fri Feb 26, 2010 12:50 am
  • Posts: 4
  • Offline
  • Profile

Change Date format on YUI 2 calendar

Post Posted: Fri Feb 26, 2010 1:06 am
+0-
Hi I tried to modify the dates for the YUI calendar in the format DD/MM/YYYY but it still displays as MM/DD/YYYY
I used the examples frrom the localized calendars.
Here is the script:
http://www.sabina-ferien.de/templates/vj-08/script/cal2.js

Could you tell me please what am I doing wrong ?

Thanks,

Matt Parker

YUI Contributor

  • Username: mattatlamplight
  • Joined: Mon Apr 20, 2009 12:03 pm
  • Posts: 466
  • Location: London UK
  • GitHub: mattparker
  • Gists: mattparker
  • Offline
  • Profile

Re: Change Date format on YUI 2 calendar

Post Posted: Fri Feb 26, 2010 1:36 am
+0-
Is the problem that they're not displaying right on the calendar, or when you select a date it displays wrong in the form input field?

If it's the first, I've no idea: it looks OK.

If it's the second, your getDate function is returning the date as mm/dd/yyyy:

calDate =(calDate.getMonth() + 1) + '/' + calDate.getDate() + '/' + calDate.getFullYear();

and you should be able to just swap the getMonth() bit and getDate() bit.

Matt

Cristian Ciobanu

  • Username: cioby23
  • Joined: Fri Feb 26, 2010 12:50 am
  • Posts: 4
  • Offline
  • Profile

Re: Change Date format on YUI 2 calendar

Post Posted: Fri Feb 26, 2010 3:06 am
+0-
Hi Matt,

I swapped the bits as you advised and it worked.

Thanks a lot,

Cristian Ciobanu

  • Username: cioby23
  • Joined: Fri Feb 26, 2010 12:50 am
  • Posts: 4
  • Offline
  • Profile
Tags:

Re: Change Date format on YUI 2 calendar

Post Posted: Tue Mar 02, 2010 2:25 am
+0-
Hi,
I found an error.

The calendar is attached to a text input and when I click it it displays the calendar fine. Then when I select a date it displays the date correctly in the text input. I observed if suppose I entered a wrong date and I try to select another date from the calendar without delete the text input content it displays random months or years.(ex: June 2011)

Now the function to display the date is set like this:

calDate = calDate.getDate() + '/' + (calDate.getMonth() + 1) + '/' + calDate.getFullYear(); // -> DD/MM/YYYY

If I swap getDate with getMonth is works fine.
calDate =(calDate.getMonth() + 1) + '/' + calDate.getDate() + '/' + calDate.getFullYear(); // -> MM/DD/YYYY

Could somenone please give me a solution to this ?

Thanks and kind regards,

Satyen Desai

YUI Developer

  • Username: sdesai
  • Joined: Tue Dec 09, 2008 4:17 pm
  • Posts: 302
  • GitHub: sdesai
  • Gists: sdesai
  • YUI Developer
  • Offline
  • Profile

Re: Change Date format on YUI 2 calendar

Post Posted: Wed Mar 03, 2010 12:13 pm
+0-
Not sure I follow how the string construction you mention fits in with displaying the calendar, but based on your js file...


var xy = Dom.getXY(tar),
date = Dom.get(tar).value;
if (date) {

cal1.cfg.setProperty('selected', date);
cal1.cfg.setProperty('pagedate', new Date(date), true);

1. There's no date validation going on when you pass the value to the calendar's selected or pagedate properties. The calendar will attempt to parse string dates passed in to selected and page date based on DATE_FIELD_DELIMITER, MDY_DATE_POSITION, MDY_MONTH_POSITION and MDY_YEAR_POSITION values.

2. There's also no validation going on when you pass "date" to new Date(date), which is probably not resulting in a valid Date object (e.g. new Date("foo")). The Date constructor expects epoch values, or strings defined by https://developer.mozilla.org/en/Core_J ... Date/parse.

It seems like it would be a good idea to make public the _parseDate, _parseDates etc. methods which the Calendar has, so these can be used to validate string input, before passing it to Calendar, but in the interim, you'd need to do the validation yourself.

Hope that helps,
Satyen

Matt Parker

YUI Contributor

  • Username: mattatlamplight
  • Joined: Mon Apr 20, 2009 12:03 pm
  • Posts: 466
  • Location: London UK
  • GitHub: mattparker
  • Gists: mattparker
  • Offline
  • Profile

Re: Change Date format on YUI 2 calendar

Post Posted: Wed Mar 03, 2010 12:14 pm
+0-
Hi,

Is the problem now that you're trying to tell the calendar what the date is, rather than getting the date from the calendar, and it's going wrong? Calendar will expect dates as MM/DD/YYYY so you'll need to swap days and months back if you're taking the date from the text input.

But I'm not sure if that is your problem. Do you have a link to see it working (or not)?

Matt


... I've just had another look at your code. And yes, you'll need to put the date back into mm/dd/yyyy format in showCal. I pretty sure (but not certain) js always thinks dates are mm/dd (a pain for us Europeans!). So in showCal I think you'll need to split up the string you're getting from the text input:

Code:
var dateBits = date.split("/");


and then

Code:
cal1.cfg.setProperty('pagedate', new Date( dateBits[2], dateBits[1], dateBits[0] ), true);


and you'll prob want to do a bit of checking (and maybe regex-ing) to cope with people typing in dates with other punctuation etc.

I don't know Calendar well enough to know what the DateMath has in it and whether that might save you some trouble... might be worth looking.




... Third edit: you might want to listen to Satyen more than me!

Matt

Satyen Desai

YUI Developer

  • Username: sdesai
  • Joined: Tue Dec 09, 2008 4:17 pm
  • Posts: 302
  • GitHub: sdesai
  • Gists: sdesai
  • YUI Developer
  • Offline
  • Profile

Re: Change Date format on YUI 2 calendar

Post Posted: Wed Mar 03, 2010 12:47 pm
+0-
> ... Third edit: you might want to listen to Satyen more than me!

I've come across a number of Matt's responses in working through the forum list today, and he's a perfectly good person to listen to. So don't listen to him telling you to listen to me more than listening to him. Guess it's time for lunch.
  [ 7 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum