Closed Bug 185394 Opened 22 years ago Closed 21 years ago

Date picker format does not respect local settings

Categories

(Calendar :: General, defect)

x86
Windows 98
defect
Not set
minor

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: kenn, Assigned: mostafah)

References

Details

Attachments

(5 files, 1 obsolete file)

User-Agent:       Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.2.1) Gecko/20021130
Build Identifier: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.2.1) Gecko/20021130

Calender uses US date format when setting an appointment, Suggestion, pick up
the date format from the machine default for use in tis section of the program.
It appears to be correct in the preferences section but not when creating
appointments.

Reproducible: Always

Steps to Reproduce:
1. Create new appointment with system set to Australian or English Date format
2.
3.

Actual Results:  
Date in appointment is 12/15/2002 (us format)

Expected Results:  
Displayed the date format as 15/12/2002 (International Australian/english
I can also confirm this for the latest builds under XP... 

Only relief by using ISO 8601 instead of local US.
This method should use dateUtils.js dateFormater.getShortFormatedDate()
instead, but i don't know how to implement it.
I also don't know how to implement it, but this is a known bug.
Status: UNCONFIRMED → NEW
Ever confirmed: true
dupe of bug 179102? or vice versa considering that this one has a patch?
*** Bug 179102 has been marked as a duplicate of this bug. ***
*** Bug 192545 has been marked as a duplicate of this bug. ***
Summary: Date format for international countries in Calender → Date picker format does not respect local settings
Same problem under Linux. The current locale should be used.
*** Bug 197930 has been marked as a duplicate of this bug. ***
New contact from mikep@oeone.com to mostafah@oeone.com
Filter on string OttawaMBA to get rid of these messages. 
Sorry for the spam.
Assignee: mikep → mostafah
still occurs with 
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6a) Gecko/20031001
This applies to Sunbird as well
To fix, in the date picker constructor, give it a DateFormater() [sic] :

Mozilla/chrome/calendar/content/datepicker/datepicker.xml:39
+    this.formatter= new DateFormater();

Then in its getPrettyDate method, replace the expression with a call to formatter:

Mozilla/chrome/calendar/content/datepicker/datepicker.xml:78
-    return (aValue.getMonth()+1) + "/" + aValue.getDate() + "/" +
aValue.getFullYear();
+    return this.formatter.getShortFormatedDate(aValue);

This fixes it for me (on w2k with control panel / regional options / date set to
yyyy-mm-dd, Moz1.5, 2003092614-cal).  If you want, you can get rid of the
getPrettyDate method and call the formatter directly.

(How did I find DateFormater?  I searched for "dateFormat" at
http://lxr.mozilla.org/mozilla/ and noticed in the list results that under the
calendar directory in dateUtils.js there is likely sounding DateFormater, so I
tried it out by making the above changes, restarted Mozilla, and it worked.  I
wonder if the misspelling has slowed down finding the solution of this bug,
should it be changed to DateFormatter ?)
Under Linux/ppc, I get the date correctly written (yyyy-mm-dd), but if I modify
it,  the change isn't taken into account.
Ok, here's a function to probe the current date format and parse date accordingly:

Mozilla/chrome/calendar/content/dateUtils.js:284

DateFormater.prototype.parseShortDate = function ( dateString )
{ 
  // probe for date format -- this part could be in constructor
  // probe result state:
  var parseShortDateRegex = /^\s*(\d+)\D(\d+)\D(\d+)\s*$/; //digits & nonDigits
  var parsedYearIndex = -1, parsedMonthIndex = -1, parsedDayIndex = -1;
  { // do probe 
    var probeDate = new Date(2002,3-1,4); // month is 0-based
    var probeString = this.getShortFormatedDate(probeDate);

    var probeArray = parseShortDateRegex.exec(probeString);
    for (var i = 1; i <= 3; i++) { 
      switch (Number(probeArray[i])) {
      case 2002: case 02: parsedYearIndex = i;  break;
      case 3:             parsedMonthIndex = i; break;
      case 4:             parsedDayIndex = i;   break;
      }
    }
    // all three parsed indexes are now set (no longer -1)
  }
  // parse dateString
  var dateNumbersArray = parseShortDateRegex.exec(dateString);
  if (dateNumbersArray != null) { 
    return new Date(Number(dateNumbersArray[parsedYearIndex]),
		    Number(dateNumbersArray[parsedMonthIndex]) - 1, // 0-based
		    Number(dateNumbersArray[parsedDayIndex]));
  } else return null; // did not match regex, not a valid date
}

In the definition of the datePicker textBox, replace "new Date(this.value)" with
"new DateFormater().parseShortDate(this.value)".  

Mozilla/chrome/calendar/content/datepicker/datePicker.xml:11-13

<xul:textbox id="textbox"
 onkeypress="if (event.keyCode == 13) this.parentNode.parentNode.update(new
DateFormater().parseShortDate(this.value));"
 onblur="this.parentNode.parentNode.parentNode.parentNode.update(new
DateFormater().parseShortDate(this.value),true);"/>

(If you can figure out how to access this.formatter from this code, you can
avoid creating a new formatter each time.)
OK, I confirm that works here.
Attachment #135273 - Flags: first-review?(mostafah)
Attachment #135274 - Flags: first-review?(mostafah)
Comment on attachment 135273 [details] [diff] [review]
part 1 of 2:  datepicker.xml changes

Checked into CVS.
Attachment #135273 - Flags: first-review?(mostafah) → first-review+
Comment on attachment 135274 [details] [diff] [review]
part 2 of 2: dateUtils.js --- parseShortDate

Checked into CVS.
Attachment #135274 - Flags: first-review?(mostafah) → first-review+
Fixes to datePicker to restore date after failed parse
(need to set textBox.value property, not attribute).

Also introduced parseTextDate method which reuses this.formatter.
Attached patch Fix parseShortDate to parse 2-digit years (obsolete) β€” β€” Splinter Review
Fix parseShortDate so if short date format shows 2-digit years, will parse them

as year in interval from 69 previous years to 30 future years
(covers most working people's birthdate, and 30-year mortgages).
Years outside this interval can be specified by typing four digit year.
Should this bug be marked as FIXED now that the patch has been checked into CVS?
previous version left out check for 2 digit year < currentYear - 69
Attachment #135364 - Attachment is obsolete: true
Attachment #135361 - Flags: first-review?
Attachment #135398 - Flags: first-review?
Comment on attachment 135361 [details] [diff] [review]
Fix datePicker to restore date after failed parse

Checked into CVS.
Attachment #135361 - Flags: first-review? → first-review+
Comment on attachment 135398 [details] [diff] [review]
Fix parseShortDate to parse 2-digit years

Checked into CVS.
Attachment #135398 - Flags: first-review? → first-review+
Re: comment 22: Windows XP (and possibly other OSes) allows the user to specify
between which dates a two-digit year should be interpreted as. This might
conflict with an internal setting in the calendar.

I don't suppose the calendar could easily query the OS, but I thought it should
be mentioned.
*** Bug 201116 has been marked as a duplicate of this bug. ***
*** Bug 200887 has been marked as a duplicate of this bug. ***
*** Bug 227038 has been marked as a duplicate of this bug. ***
Using -
moz 1.5
en-gb locale 
en-gb lang

At present ive manually changed datepicker and everything displays correctly -
but if you add an event/task it looks fine but reverses it in the actual
calendar . if you then copy and paste it - it stays where it is . 

The following lines of patch id 135398
http://bugzilla.mozilla.org/attachment.cgi?id=135398&action=view

!       if (year < currentYear - 69)
!         year += 100;

are currently missing from cvs version according to 
http://lxr.mozilla.org/mozilla/source/calendar/resources/content/dateUtils.js#319
(maybe overridden version, id 135364, was merged by mistake?)
Yes that was probably what happened. My fault and my apologies.
Checked the rest into CVS.
The applied patches should've fixed the problem.
Status: NEW → RESOLVED
Closed: 21 years ago
Resolution: --- → FIXED
It would be great if we could change the format of the date to overwrite the
local preferences...
(Maybe I should open a new RFE, or maybe it has allready be done, but I've found
nothing)
The bugspam monkeys have been set free and are feeding on Calendar :: General. Be afraid for your sanity!
QA Contact: gurganbl → general
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: