Fix bug 872694 - Merge "Add numericDayToIcalDay method" from upstream. r=lightsofapollo,a=philipp
authorPhilipp Kewisch <mozilla@kewis.ch>
Wed, 15 May 2013 22:03:09 +0200
changeset 15536 ca558379591d04f0c96dfa0875e0f400a6f5fb81
parent 15535 4037e43679e8058039ee641f4aeeb2d47a792b55
child 15537 efb9e5d15ffd648f64673e3fd820c179b8e2eab3
push idunknown
push userunknown
push dateunknown
reviewerslightsofapollo, philipp
bugs872694
Fix bug 872694 - Merge "Add numericDayToIcalDay method" from upstream. r=lightsofapollo,a=philipp
calendar/base/modules/ical.js
--- a/calendar/base/modules/ical.js
+++ b/calendar/base/modules/ical.js
@@ -4321,17 +4321,26 @@ ICAL.TimezoneService = (function() {
    */
   ICAL.Recur.icalDayToNumericDay = function toNumericDay(string) {
     //XXX: this is here so we can deal
     //     with possibly invalid string values.
 
     return DOW_MAP[string];
   };
 
+  /**
+   * Convert a numeric day value into its ical representation (SU, MO, etc..)
+   *
+   * @param {Numeric} numeric value of given day.
+   * @return {String} day ical day.
+   */
   ICAL.Recur.numericDayToIcalDay = function toIcalDay(num) {
+    //XXX: this is here so we can deal with possibly invalid number values.
+    //     Also, this allows consistent mapping between day numbers and day
+    //     names for external users.
     return REVERSE_DOW_MAP[num];
   };
 
   var VALID_DAY_NAMES = /^(SU|MO|TU|WE|TH|FR|SA)$/;
   var VALID_BYDAY_PART = /^([+-])?(5[0-3]|[1-4][0-9]|[1-9])?(SU|MO|TU|WE|TH|FR|SA)$/
   var ALLOWED_FREQ = ['SECONDLY', 'MINUTELY', 'HOURLY',
                       'DAILY', 'WEEKLY', 'MONTHLY', 'YEARLY'];
 
@@ -4559,18 +4568,18 @@ ICAL.RecurIterator = (function() {
           var pos = parts[0];
           var rule_dow = parts[1];
           var dow = rule_dow - this.last.dayOfWeek();
           if ((this.last.dayOfWeek() < rule_dow && dow >= 0) || dow < 0) {
             // Initial time is after first day of BYDAY data
             this.last.day += dow;
           }
         } else {
-          var wkMap = icalrecur_iterator._wkdayMap[this.dtstart.dayOfWeek()];
-          parts.BYDAY = [wkMap];
+          var dayName = ICAL.Recur.numericDayToIcalDay(this.dtstart.dayOfWeek());
+          parts.BYDAY = [dayName];
         }
       }
 
       if (this.rule.freq == "YEARLY") {
         for (;;) {
           this.expand_year_days(this.last.year);
           if (this.days.length > 0) {
             break;
@@ -5558,17 +5567,17 @@ ICAL.RecurIterator = (function() {
     check_contracting_rules: function check_contracting_rules() {
       var dow = this.last.dayOfWeek();
       var weekNo = this.last.weekNumber(this.rule.wkst);
       var doy = this.last.dayOfYear();
 
       return (this.check_contract_restriction("BYSECOND", this.last.second) &&
               this.check_contract_restriction("BYMINUTE", this.last.minute) &&
               this.check_contract_restriction("BYHOUR", this.last.hour) &&
-              this.check_contract_restriction("BYDAY", icalrecur_iterator._wkdayMap[dow]) &&
+              this.check_contract_restriction("BYDAY", ICAL.Recur.numericDayToIcalDay(dow)) &&
               this.check_contract_restriction("BYWEEKNO", weekNo) &&
               this.check_contract_restriction("BYMONTHDAY", this.last.day) &&
               this.check_contract_restriction("BYMONTH", this.last.month) &&
               this.check_contract_restriction("BYYEARDAY", doy));
     },
 
     setup_defaults: function setup_defaults(aRuleType, req, deftime) {
       var indexMapValue = icalrecur_iterator._indexMap[aRuleType];
@@ -5602,18 +5611,16 @@ ICAL.RecurIterator = (function() {
       result.by_indices = this.by_indices;
       result.occurrence_number = this.occurrence_number;
 
       return result;
     }
 
   };
 
-  icalrecur_iterator._wkdayMap = ["", "SU", "MO", "TU", "WE", "TH", "FR", "SA"];
-
   icalrecur_iterator._indexMap = {
     "BYSECOND": 0,
     "BYMINUTE": 1,
     "BYHOUR": 2,
     "BYDAY": 3,
     "BYMONTHDAY": 4,
     "BYYEARDAY": 5,
     "BYWEEKNO": 6,