PDA

View Full Version : Ext.Date monthNames, monthNumbers, getMonthNumber



smaria.crisan
24 Nov 2011, 7:35 AM
Hello Forum,

this is my first post. I'm learning ExtJS4 and I can not get Ext.Date.getMonthNumber work after i changend Ext.Date.monthNames and Ext.Date.monthNumbers. The same with Ext.Date.getSuffix.

Do I miss something? Thank you for your help.



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Learning ExtJS4</title>
<link rel="stylesheet" type="text/css" href="../ext/resources/css/ext-all.css" />
<script type="text/javascript" src="../ext/ext-all-debug.js"></script>
<script>
Ext.onReady(function() {
var today = new Date();
Ext.Date.dayNames = ['luni', 'marti', 'miercuri', 'joi', 'vineri', 'sambata', 'duminica'];
Ext.Date.monthNames = ['ianuarie', 'februarie', 'martie', 'aprilie', 'mai', 'iunie', 'iulie', 'august', 'septembrie', 'octombrie', 'noiembrie', 'decembrie'];
Ext.Date.monthNumbers = {
'ianuarie' : 1,
'februarie' : 2,
'martie' : 3,
'aprilie' : 4,
'mai' : 5,
'iunie' : 6,
'iulie' : 7,
'august' : 8,
'septembrie' : 9,
'octombrie' : 10,
'noiembrie' : 11,
'decembrie' : 12
};
console.log('getMonthNumber(S name) : %d', Ext.Date.getMonthNumber('noiembrie')); // nothing
console.log('getSuffix(D date): %s', Ext.Date.getSuffix(today)); // the english suffix

});

</script>
</head>
<body></body>
</html>


Maria

mitchellsimoens
24 Nov 2011, 8:35 AM
You Ext.Date.monthNumbers needs to be 3 characters long and the first letter should be capitalized:


Ext.Date.monthNumbers = {
Ian : 1,
Feb : 2,
Mar : 3,
Apr : 4,
Mai : 5,
Iun : 6,
Iul : 7,
Aug : 8,
Sep : 9,
Oct : 10,
Noi : 11,
Dec : 12
};

No the getSuffix, it doesn't look like it will do any localization... here is the code for getSuffix:


getSuffix : function(date) {
switch (date.getDate()) {
case 1:
case 21:
case 31:
return "st";
case 2:
case 22:
return "nd";
case 3:
case 23:
return "rd";
default:
return "th";
}
}

You will need to override this method like you are doing with you days and months but only do a function:


Ext.Date.getSuffix = function(date) {
//do your stuff here
}

smaria.crisan
25 Nov 2011, 4:38 AM
Thank you mitchellsimoens,

yes you have right and the documentation is also ok, I didn't see it right :




Ext.Date.monthNumbers = { 'ShortJanNameInYourLang':0, 'ShortFebNameInYourLang':1, ... };

And now I understand getSuffix also :)

Thank you, Maria