Skip to content
Browse files

Fix date formatting for IE7

  • Loading branch information...
1 parent 95a6903 commit 8f4968367e6ea456c8c74d0433b273e13570b785 @kneath committed
Showing with 38 additions and 20 deletions.
  1. +21 −1 spec/specs.js
  2. +17 −19 src/timeframe.js
View
22 spec/specs.js
@@ -229,4 +229,24 @@ describe("Ranges", {
value_of(Instance.range.get('start')).should_be(DateMiddle);
value_of(Instance.range.get('end')).should_be(DateLatest);
}
-});
+});
+
+describe("Formatting", {
+ 'before all': function(){
+ setupHTML();
+ Instance = new Timeframe('calendar', { format:"%m/%d/%Y" });
+ FirstDate = new Date(2008, 10, 5, 12);
+ LastDate = new Date(2008, 10, 8, 12);
+ },
+ 'after all': function(){
+ teardownHTML();
+ },
+
+ 'should show the format in the start and end dates': function(){
+ Instance.range.empty()
+ Instance.markEndPoint(FirstDate);
+ Instance.markEndPoint(LastDate);
+ value_of(Instance.fields.start.value).should_be("11/05/2008");
+ value_of(Instance.fields.end.value).should_be("11/08/2008");
+ }
+})
View
36 src/timeframe.js
@@ -452,25 +452,23 @@ $extend(Date.prototype, {
var day = this.getDay(), month = this.getMonth();
var hours = this.getHours(), minutes = this.getMinutes();
function pad(num) { return num.toString().pad(2, '0');};
- return format.replace(/\%([aAbBcdHImMpSwyY])/g, function(part) {
- switch(part[1]) {
- case 'a': return Locale.get('dayNames')[day].substr(0, 3); break;
- case 'A': return Locale.get('dayNames')[day]; break;
- case 'b': return Locale.get('monthNames')[month].substr(0, 3); break;
- case 'B': return Locale.get('monthNames')[month].escapeHTML(); break;
- case 'c': return this.toString(); break;
- case 'd': return pad(this.getDate()); break;
- case 'H': return pad(hours); break;
- case 'I': return (hours % 12 == 0) ? 12 : pad(hours % 12); break;
- case 'm': return pad(month + 1); break;
- case 'M': return pad(minutes); break;
- case 'p': return hours >= 12 ? 'PM' : 'AM'; break;
- case 'S': return pad(this.getSeconds()); break;
- case 'w': return day; break;
- case 'y': return pad(this.getFullYear() % 100); break;
- case 'Y': return this.getFullYear().toString(); break;
- }
- }.bind(this));
+ return format.replace(/\%([aAbBcdHImMpSwyY])/g, "{$1}").substitute({
+ 'a': Locale.get('dayNames')[day].substr(0, 3),
+ 'A': Locale.get('dayNames')[day],
+ 'b': Locale.get('monthNames')[month].substr(0, 3),
+ 'B': Locale.get('monthNames')[month],
+ 'c': this.toString(),
+ 'd': pad(this.getDate()),
+ 'H': pad(hours),
+ 'I': (hours % 12 == 0) ? 12 : pad(hours % 12),
+ 'm': pad(month + 1),
+ 'M': pad(minutes),
+ 'p': hours >= 12 ? 'PM' : 'AM',
+ 'S': pad(this.getSeconds()),
+ 'w': day,
+ 'y': pad(this.getFullYear() % 100),
+ 'Y': this.getFullYear().toString()
+ });
},
neutral: function() {

0 comments on commit 8f49683

Please sign in to comment.
Something went wrong with that request. Please try again.