Ignore:
Timestamp:
2013-12-18T03:03:14+01:00 (10 years ago)
Author:
Don-vip
Message:

update opening_hours.js

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/data/validator/opening_hours.js

    r6488 r6489  
    44        //======================================================================
    55        var holidays = {
     6                'fr': {
     7                        'PH': { // http://fr.wikipedia.org/wiki/F%C3%AAtes_et_jours_f%C3%A9ri%C3%A9s_en_France
     8                                "Jour de l'an"              : [  1,  1 ],
     9                                "Vendredi saint"            : [  'easter', -2, [ 'Moselle', 'Bas-Rhin', 'Haut-Rhin', 'Guadeloupe', 'Martinique', 'Polynésie française' ] ],
     10                                "Lundi de Pâques"           : [  'easter', 1 ],
     11                                "Saint-Pierre-Chanel"       : [  4, 28, [ 'Wallis-et-Futuna' ] ],
     12                                "Fête du Travail"           : [  5,  1 ],
     13                                "Fête de la Victoire"       : [  5,  8 ],
     14                                "Abolition de l'esclavage"  : [  5, 22, [ 'Martinique' ] ],
     15                                "Abolition de l'esclavage"  : [  5, 27, [ 'Guadeloupe' ] ],
     16                                "Jeudi de l'Ascension"      : [  'easter', 39 ],
     17                                "Lundi de Pentecôte"        : [  'easter', 50 ],
     18                                "Abolition de l'esclavage"  : [  6, 10, [ 'Guyane' ] ],
     19                                "Fête de l'autonomie"       : [  6, 29, [ 'Polynésie française' ] ],
     20                                "Fête nationale"            : [  7, 14 ],
     21                                "Fête Victor Schoelcher"    : [  7, 21, [ 'Guadeloupe', 'Martinique' ] ],
     22                                "Fête du Territoire"        : [  7, 29, [ 'Wallis-et-Futuna' ] ],
     23                                "Assomption"                : [  8, 15 ],
     24                                "Fête de la citoyenneté"    : [  9, 24, [ 'Nouvelle-Calédonie' ] ],
     25                                "Toussaint"                 : [ 11,  1 ],
     26                                "Armistice"                 : [ 11, 11 ],
     27                                "Abolition de l'esclavage"  : [ 12, 20, [ 'Réunion' ] ],
     28                                "Noël"                      : [ 12, 25 ],
     29                                "Saint-Étienne "            : [ 12, 26, [ 'Moselle', 'Bas-Rhin', 'Haut-Rhin' ] ]
     30                        }
     31                },
    632                'de': {
    733                        'PH': { // http://de.wikipedia.org/wiki/Feiertage_in_Deutschland
     
    10901116                wrong_words: {
    10911117                        'Assuming "<ok>" for "<ko>"': {
    1092                                 summer: 'May-Oct',
    1093                                 winter: 'Nov-Apr',
     1118                                spring: 'Mar-May',
     1119                                summer: 'Jun-Aug',
     1120                                autumn: 'Sep-Nov',
     1121                                winter: 'Dec-Feb',
    10941122                        }, 'Bitte benutze die englische Schreibweise "<ok>" für "<ko>".': {
    10951123                                sommer: 'summer',
    1096                         }, 'Bitte benutze "<ok>" für "<ko>". Beispiel: "Mo 08:00-12:00; Tu off"': {
    1097                                 ruhetag: 'off',
    1098                                 ruhetage: 'off',
     1124                        }, 'Bitte benutze "<ok>" für "<ko>". Beispiel: "Mo-Fr 08:00-12:00; Tu off"': {
     1125                                ruhetag:     'off',
     1126                                ruhetage:    'off',
     1127                                geschlossen: 'off',
    10991128                        }, 'Assuming "<ok>" for "<ko>". Please avoid using "workday": http://wiki.openstreetmap.org/wiki/Talk:Key:opening_hours#need_syntax_for_holidays_and_workingdays': {
    11001129                                //      // Used around 260 times but the problem is, that work day might be different in other countries.
     
    11061135                        }, 'Please ommit "<ko>".': {
    11071136                                season: '',
     1137                                hs:     '',
     1138                                hrs:    '',
     1139                                hours:  '',
    11081140                        }, 'Please ommit "<ko>". You might want to express open end which can be specified as "12:00+" for example': {
    11091141                                from: '',
    1110                         }, 'Please use notation "<ok>" for "<ko>". If the times are unsure or variate consider a comment e.g. 12:00-14:00 "only on sunshine".': {
     1142                        }, 'Please use notation "<ok>" for "<ko>". If the times are unsure or vary consider a comment e.g. 12:00-14:00 "only on sunshine".': {
    11111143                                '~':  '-',
     1144                                '~': '-',
    11121145                        }, 'Please use notation "<ok>" for "<ko>".': {
    11131146                                '–':  '-',
     1147                                'ー':  '-',
    11141148                                to:   '-',
    11151149                                till: '-',
    11161150                                and:  ',',
    11171151                                '&':  ',',
    1118                                 daily:    'Mo-Su',
    1119                                 always:   '24/7',
     1152                                ':':  ':',
     1153                                daily:     'Mo-Su',
     1154                                everyday:  'Mo-Su',
     1155                                always:    '24/7',
     1156                                nonstop:   '24/7',
    11201157                                midnight: '00:00',
     1158                                holiday:  'PH',
     1159                                holidays: 'PH',
     1160                                // summerholiday:  'SH',
     1161                                // summerholidays: 'SH',
    11211162                        }, 'Please use time format in 24 hours notation ("<ko>").': {
    11221163                                pm: '',
     
    11291170                        }, 'Bitte benutze die Schreibweise "<ok>" für "<ko>".': {
    11301171                                bis: '-',
     1172                                'täglich': 'Mo-Su',
     1173                        }, 'Bitte benutze die Schreibweise "<ok>" als Ersatz für "und" bzw. "u.".': {
    11311174                                und: ',',
     1175                                u:   ',',
    11321176                        }, 'Bitte benutze die englische Abkürzung "<ok>" für "<ko>".': {
    11331177                                feiertag:   'PH',
     1178                                feiertags:  'PH',
    11341179                                feiertage:  'PH',
    11351180                                feiertagen: 'PH'
     
    14831528                        do {
    14841529                                if (continue_at == tokens[nblock][0].length) break;
    1485                                 // Block does contain nothing useful e.g. second block of '10:00-12:00,' (empty) which needs to be handled.
     1530                                // Additional block does contain nothing useful e.g. second block of '10:00-12:00,' (empty) which needs to be handled.
    14861531
    14871532                                var selectors = {
     
    15081553                                        unknown: false,
    15091554                                        comment: undefined,
     1555                                        build_from_token_block: undefined,
    15101556                                };
    15111557
     1558                                selectors.build_from_token_block = [ nblock, continue_at ];
    15121559                                continue_at = parseGroup(tokens[nblock][0], continue_at, selectors, nblock);
    15131560                                if (typeof continue_at == 'object')
     
    15891636                                        curr_block_tokens.push([tmp[0].toLowerCase(), 'calcday', value.length ]);
    15901637                                        value = value.substr(tmp[0].length);
    1591                                 } else if (tmp = value.match(/^(&|–|~|[a-zA-ZäÄàÀéÉ]+\b)\.?/i)) {
     1638                                } else if (tmp = value.match(/^(&|–|ー|~|~|:|[a-zA-ZäÄàÀéÉ]+\b)\.?/i)) {
    15921639                                        // Handle all remaining words with error tolerance
    15931640                                        var correct_val = returnCorrectWordOrToken(tmp[1].toLowerCase(), value.length);
     
    17371784                function parseGroup(tokens, at, selectors, nblock, conf) {
    17381785                        var prettified_group_value = '';
    1739                         used_subparsers = { 'time ranges': 0 };
     1786                        used_subparsers = { 'time ranges': [ ] };
    17401787
    17411788                        // console.log(tokens); // useful for debugging of tokenize
     
    17911838                                        at = parseTimeRange(tokens, at, selectors);
    17921839
    1793                                         if (typeof used_subparsers['time ranges'] != 'number')
    1794                                                 used_subparsers['time ranges'] = 1;
    1795                                         else
    1796                                                 used_subparsers['time ranges']++;
     1840                                        used_subparsers['time ranges'].push(at);
    17971841                                } else if (matchTokens(tokens, at, 'closed')) {
    17981842                                        selectors.meaning = false;
     
    18011845                                                at = [ at + 1 ];
    18021846
    1803                                         if (typeof used_subparsers['state keywords'] != 'number')
    1804                                                 used_subparsers['state keywords'] = 1;
     1847                                        if (typeof used_subparsers['state keywords'] != 'object')
     1848                                                used_subparsers['state keywords'] = [ at ];
    18051849                                        else
    1806                                                 used_subparsers['state keywords']++;
     1850                                                used_subparsers['state keywords'].push(at);
    18071851                                } else if (matchTokens(tokens, at, 'open')) {
    18081852                                        selectors.meaning = true;
     
    18111855                                                at = [ at + 1 ];
    18121856
    1813                                         if (typeof used_subparsers['state keywords'] != 'number')
    1814                                                 used_subparsers['state keywords'] = 1;
     1857                                        if (typeof used_subparsers['state keywords'] != 'object')
     1858                                                used_subparsers['state keywords'] = [ at ];
    18151859                                        else
    1816                                                 used_subparsers['state keywords']++;
     1860                                                used_subparsers['state keywords'].push(at);
    18171861                                } else if (matchTokens(tokens, at, 'unknown')) {
    18181862                                        selectors.meaning = false;
     
    18221866                                                at = [ at + 1 ];
    18231867
    1824                                         if (typeof used_subparsers['state keywords'] != 'number')
    1825                                                 used_subparsers['state keywords'] = 1;
     1868                                        if (typeof used_subparsers['state keywords'] != 'object')
     1869                                                used_subparsers['state keywords'] = [ at ];
    18261870                                        else
    1827                                                 used_subparsers['state keywords']++;
     1871                                                used_subparsers['state keywords'].push(at);
    18281872                                } else if (matchTokens(tokens, at, 'comment')) {
    18291873                                        selectors.comment = tokens[at][0];
     
    18461890                                                at = [ at + 1 ];
    18471891
    1848                                         if (typeof used_subparsers['comments'] != 'number')
    1849                                                 used_subparsers['comments'] = 1;
     1892                                        if (typeof used_subparsers['comments'] != 'object')
     1893                                                used_subparsers['comments'] = [ at ];
    18501894                                        else
    1851                                                 used_subparsers['comments']++;
     1895                                                used_subparsers['comments'].push(at);
    18521896                                } else {
    18531897                                        var warnings = getWarnings();
     
    18691913                                                prettified_group_value = prettified_group_value.substring(0, prettified_group_value.length - 1);
    18701914
    1871                                         prettified_group_value += prettifySelector(tokens, old_at, at, conf, used_subparsers['time ranges']);
     1915                                        prettified_group_value += prettifySelector(tokens, old_at, at, conf, used_subparsers['time ranges'].length);
    18721916                                }
    18731917
     
    18801924                        if (!done_with_warnings) {
    18811925                                for (var subparser_name in used_subparsers) {
    1882                                         if (used_subparsers[subparser_name] > 1) {
    1883                                                 if (subparser_name.match(/^(?:comments|state keywords)/)) {
    1884                                                         parsing_warnings.push([nblock, at - 1, 'You have used ' + used_subparsers[subparser_name]
    1885                                                                         + ' ' + subparser_name + ' in one rule.'
     1926                                        if (used_subparsers[subparser_name].length > 1) {
     1927                                                parsing_warnings.push([nblock, used_subparsers[subparser_name][used_subparsers[subparser_name].length - 1] - 1,
     1928                                                        'You have used ' + used_subparsers[subparser_name].length
     1929                                                        + (subparser_name.match(/^(?:comments|state keywords)/) ?
     1930                                                                        ' ' + subparser_name + ' in one rule.'
    18861931                                                                        + ' You may only use one in one rule.'
    1887                                                                         + ' Rules can be separated by ";".' ]);
    1888                                                 } else {
    1889                                                         parsing_warnings.push([nblock, at - 1, 'You have used ' + used_subparsers[subparser_name]
    1890                                                                         + ' not connected ' + subparser_name + ' in one rule.'
     1932                                                                :
     1933                                                                        ' not connected ' + subparser_name + ' in one rule.'
    18911934                                                                        + ' This is probably an error.'
    18921935                                                                        + ' Equal selector types can (and should) always be written in conjunction separated by comma or something.'
    1893                                                                         + ' Example for time ranges "12:00-13:00,15:00-18:00". Rules can be separated by ";".']);
    1894                                                 }
     1936                                                                        + ' Example for time ranges "12:00-13:00,15:00-18:00".'
     1937                                                         )
     1938                                                        + ' Rules can be separated by ";".' ]
     1939                                                );
    18951940                                        }
    18961941                                }
    18971942                        }
    1898 
    18991943
    19001944                        return at;
     
    19121956                                        // relying on the fact that always *one* of them is true
    19131957
    1914                                         var is_point_in_time = false; // no time range
    1915 
    1916                                         if (has_normal_time[0])
     1958                                        var is_point_in_time = false; // default no time range
     1959                                        var has_open_end     = false; // default no open end
     1960                                        var timevar_add      = [ 0, 0 ];
     1961                                        var timevar_string  = [];     // capture timevar string like 'sunrise' to calculate it for the current date.
     1962
     1963                                        // minutes_from
     1964                                        if (has_normal_time[0]) {
    19171965                                                var minutes_from = getMinutesByHoursMinutes(tokens, nblock, at+has_time_var_calc[0]);
    1918                                         else
    1919                                                 var minutes_from = word_value_replacement[tokens[at+has_time_var_calc[0]][0]];
    1920 
    1921                                         var timevar_add = [ 0, 0 ];
    1922                                         if (has_time_var_calc[0]) {
    1923                                                 timevar_add[0] = parseTimevarCalc(tokens, at);
    1924                                                 minutes_from += timevar_add[0];
     1966                                        } else {
     1967                                                timevar_string[0] = tokens[at+has_time_var_calc[0]][0];
     1968                                                var minutes_from = word_value_replacement[timevar_string[0]];
     1969
     1970                                                if (has_time_var_calc[0]) {
     1971                                                        timevar_add[0] = parseTimevarCalc(tokens, at);
     1972                                                        minutes_from += timevar_add[0];
     1973                                                }
    19251974                                        }
    19261975
    1927                                         var has_open_end = false;
    1928                                         if (!matchTokens(tokens, at+(has_normal_time[0] ? 3 : (has_time_var_calc[0] ? 7 : 1)), '-')) {
    1929                                                 if (matchTokens(tokens, at+(has_normal_time[0] ? 3 : (has_time_var_calc[0] ? 7 : 1)), '+')) {
     1976                                        var at_end_time = at+(has_normal_time[0] ? 3 : (has_time_var_calc[0] ? 7 : 1))+1; // after '-'
     1977                                        if (!matchTokens(tokens, at_end_time - 1, '-')) { // not time range
     1978                                                if (matchTokens(tokens, at_end_time - 1, '+')) {
    19301979                                                        has_open_end = true;
    19311980                                                } else {
     
    19331982                                                                throw formatWarnErrorMessage(nblock, at+(has_normal_time[0] ? 3 : (has_time_var_calc[0] ? 2 : 1)),
    19341983                                                                        'hyphen (-) or open end (+) in time range '
    1935                                                                         + (has_time_var_calc[0] ? 'calculation ' : '')
    1936                                                                         + 'expected. For working with points in time, the mode for opening_hours.js has to be altered. Maybe wrong tag?');
     1984                                                                        + (has_time_var_calc[0] ? 'calculation ' : '') + 'expected.'
     1985                                                                        + ' For working with points in time, the mode for opening_hours.js has to be altered.'
     1986                                                                        + ' Maybe wrong tag?');
    19371987                                                        } else {
    19381988                                                                var minutes_to = minutes_from + 1;
     
    19421992                                        }
    19431993
    1944                                         var at_end_time = at+(has_normal_time[0] ? 3 : (has_time_var_calc[0] ? 7 : 1))+1; // after '-'
     1994                                        // minutes_to
    19451995                                        if (has_open_end) {
    19461996                                                if (minutes_from >= 22 * 60)
    1947                                                         var minutes_to = minutes_from + 60 * 8;
     1997                                                        var minutes_to = minutes_from +  8 * 60;
    19481998                                                else if (minutes_from >= 17 * 60)
    1949                                                         var minutes_to = minutes_from + 60 * 10;
     1999                                                        var minutes_to = minutes_from + 10 * 60;
    19502000                                                else
    19512001                                                        var minutes_to = minutes_in_day;
     
    19542004                                                has_time_var_calc[1]      = matchTokens(tokens, at_end_time, '(', 'timevar');
    19552005                                                if (!has_normal_time[1] && !matchTokens(tokens, at_end_time, 'timevar') && !has_time_var_calc[1]) {
    1956                                                         if (!is_point_in_time)
    1957                                                                 throw formatWarnErrorMessage(nblock, at_end_time, 'time range does not continue as expected');
    1958                                                 } else if (oh_mode == 1) {
    1959                                                         throw formatWarnErrorMessage(nblock, at_end_time, 'opening_hours is running in "points in time mode".'
    1960                                                                 + ' Found time range.');
     2006                                                        throw formatWarnErrorMessage(nblock, at_end_time, 'time range does not continue as expected');
    19612007                                                } else {
    1962                                                         if (has_normal_time[1])
     2008                                                        if (has_normal_time[1]) {
    19632009                                                                var minutes_to = getMinutesByHoursMinutes(tokens, nblock, at_end_time);
    1964                                                         else
    1965                                                                 var minutes_to = word_value_replacement[tokens[at_end_time+has_time_var_calc[1]][0]];
     2010                                                        } else {
     2011                                                                timevar_string[1] = tokens[at_end_time+has_time_var_calc[1]][0]
     2012                                                                var minutes_to = word_value_replacement[timevar_string[1]];
     2013                                                        }
    19662014
    19672015                                                        if (has_time_var_calc[1]) {
     
    19692017                                                                minutes_to += timevar_add[1];
    19702018                                                        }
    1971 
    1972                                                         // this shortcut makes always-open range check faster
    1973                                                         // and is also useful in tests, as it doesn't produce
    1974                                                         // extra check points which may hide errors in other
    1975                                                         // selectors
    1976                                                         // if (minutes_from == 0 && minutes_to == minutes_in_day)
    1977                                                         //      selectors.time.push(function(date) { return [true]; });
    1978                                                         // Not needed. If there is no selector it automatically matches everything.
    19792019                                                }
    19802020                                        }
    19812021
     2022                                        at = at_end_time + (is_point_in_time ? -1 :
     2023                                                        (has_normal_time[1] ? 3 : (has_time_var_calc[1] ? 7 : !has_open_end))
     2024                                                );
     2025
     2026                                        if (matchTokens(tokens, at, '/', 'number')) {
     2027                                                if (matchTokens(tokens, at + 2, 'timesep', 'number')) { // /hours:minutes
     2028                                                        var point_in_time_period = getMinutesByHoursMinutes(tokens, nblock, at + 1);
     2029                                                        at += 4;
     2030                                                } else { // /minutes
     2031                                                        var point_in_time_period = tokens[at + 1][0];
     2032                                                        at += 2;
     2033                                                        if (matchTokens(tokens, at, 'timesep'))
     2034                                                                throw formatWarnErrorMessage(nblock, at,
     2035                                                                        'Time period does not continue as expected. Exampe "/01:30".');
     2036                                                }
     2037
     2038                                                if (oh_mode == 0)
     2039                                                        throw formatWarnErrorMessage(nblock, at - 1,
     2040                                                                'opening_hours is running in "time range mode". Found point in time.');
     2041
     2042                                                is_point_in_time = true;
     2043                                        } else if (oh_mode == 1 && !is_point_in_time) {
     2044                                                throw formatWarnErrorMessage(nblock, at_end_time,
     2045                                                        'opening_hours is running in "points in time mode". Found time range.');
     2046                                        }
     2047
     2048                                        if (typeof lat != 'undefined') { // lon will also be defined (see above)
     2049                                                if (!has_normal_time[0] || !(has_normal_time[1] || has_open_end || is_point_in_time) )
     2050                                                        week_stable = false;
     2051                                        } else { // we can not calculate exact times so we use the already applied constants (word_value_replacement).
     2052                                                timevar_string = [];
     2053                                        }
     2054
    19822055                                        // normalize minutes into range
    1983                                         // XXX: what if it's further than tomorrow?
    1984                                         // XXX: this is incorrect, as it assumes the same day
    1985                                         //      should cooperate with date selectors to select the next day
    19862056                                        if (minutes_from >= minutes_in_day)
    19872057                                                throw formatWarnErrorMessage(nblock, at_end_time - 1,
     
    19932063                                                        'Time spanning more than two midnights not supported');
    19942064
    1995                                         var timevar_string = [];
    1996                                         if (typeof lat != 'undefined') { // lon will also be defined (see above)
    1997                                                 if ((!has_normal_time[0] || !has_normal_time[1]) && !has_open_end)
    1998                                                         week_stable = false;
    1999                                                 if (!has_normal_time[0])
    2000                                                         timevar_string[0] = tokens[at+has_time_var_calc[0]][0];
    2001                                                 if (!has_normal_time[1] && !has_open_end && !is_point_in_time)
    2002                                                         timevar_string[1]   = tokens[at_end_time+has_time_var_calc[1]][0]
    2003                                         } // else: we can not calculate exact times so we use the already applied constants (word_value_replacement).
    2004 
    2005                                         if (minutes_to > minutes_in_day) { // has_normal_time[1] must be true
    2006                                                 selectors.time.push(function(minutes_from, minutes_to, timevar_string, timevar_add, has_open_end, is_point_in_time) { return function(date) {
    2007                                                         var ourminutes = date.getHours() * 60 + date.getMinutes();
    2008 
    2009                                                         if (timevar_string[0]) {
    2010                                                                 var date_from = eval('SunCalc.getTimes(date, lat, lon).' + timevar_string[0]);
    2011                                                                 minutes_from  = date_from.getHours() * 60 + date_from.getMinutes() + timevar_add[0];
    2012                                                         }
    2013                                                         if (timevar_string[1]) {
    2014                                                                 var date_to = eval('SunCalc.getTimes(date, lat, lon).' + timevar_string[1]);
    2015                                                                 minutes_to  = date_to.getHours() * 60 + date_to.getMinutes() + timevar_add[1];
    2016                                                                 minutes_to += minutes_in_day;
    2017                                                                 // Needs to be added because it was added by
    2018                                                                 // normal times in: if (minutes_to < // minutes_from)
    2019                                                                 // above the selector construction.
    2020                                                         } else if (is_point_in_time) {
    2021                                                                 minutes_to = minutes_from + 1;
    2022                                                         }
    2023 
    2024                                                         if (ourminutes < minutes_from)
    2025                                                                 return [false, dateAtDayMinutes(date, minutes_from)];
    2026                                                         else
    2027                                                                 return [true, dateAtDayMinutes(date, minutes_to), has_open_end];
    2028                                                 }}(minutes_from, minutes_to, timevar_string, timevar_add, has_open_end, is_point_in_time));
    2029 
    2030                                                 selectors.wraptime.push(function(minutes_from, minutes_to, timevar_string, timevar_add, has_open_end, is_point_in_time) { return function(date) {
    2031                                                         var ourminutes = date.getHours() * 60 + date.getMinutes();
    2032 
    2033                                                         if (timevar_string[0]) {
    2034                                                                 var date_from = eval('SunCalc.getTimes(date, lat, lon).' + timevar_string[0]);
    2035                                                                 minutes_from  = date_from.getHours() * 60 + date_from.getMinutes() + timevar_add[0];
    2036                                                         }
    2037                                                         if (timevar_string[1]) {
    2038                                                                 var date_to = eval('SunCalc.getTimes(date, lat, lon).' + timevar_string[1]);
    2039                                                                 minutes_to  = date_to.getHours() * 60 + date_to.getMinutes() + timevar_add[1];
    2040                                                                 // minutes_in_day does not need to be added.
    2041                                                                 // For normal times in it was added in: if (minutes_to < // minutes_from)
    2042                                                                 // above the selector construction and
    2043                                                                 // subtracted in the selector construction call
    2044                                                                 // which returns the selector function.
    2045                                                         } else if (is_point_in_time) {
    2046                                                                 minutes_to = minutes_from + 1;
    2047                                                         }
    2048 
    2049                                                         if (ourminutes < minutes_to)
    2050                                                                 return [true, dateAtDayMinutes(date, minutes_to), has_open_end];
    2051                                                         else
     2065                                        // this shortcut makes always-open range check faster
     2066                                        if (!(minutes_from == 0 && minutes_to == minutes_in_day)) {
     2067                                                if (minutes_to > minutes_in_day) { // has_normal_time[1] must be true
     2068                                                        selectors.time.push(function(minutes_from, minutes_to, timevar_string, timevar_add, has_open_end, is_point_in_time, point_in_time_period) { return function(date) {
     2069                                                                var ourminutes = date.getHours() * 60 + date.getMinutes();
     2070
     2071                                                                if (timevar_string[0]) {
     2072                                                                        var date_from = eval('SunCalc.getTimes(date, lat, lon).' + timevar_string[0]);
     2073                                                                        minutes_from  = date_from.getHours() * 60 + date_from.getMinutes() + timevar_add[0];
     2074                                                                }
     2075                                                                if (timevar_string[1]) {
     2076                                                                        var date_to = eval('SunCalc.getTimes(date, lat, lon).' + timevar_string[1]);
     2077                                                                        minutes_to  = date_to.getHours() * 60 + date_to.getMinutes() + timevar_add[1];
     2078                                                                        minutes_to += minutes_in_day;
     2079                                                                        // Needs to be added because it was added by
     2080                                                                        // normal times: if (minutes_to < minutes_from)
     2081                                                                        // above the selector construction.
     2082                                                                } else if (is_point_in_time && typeof point_in_time_period != 'number') {
     2083                                                                        minutes_to = minutes_from + 1;
     2084                                                                }
     2085
     2086                                                                if (typeof point_in_time_period == 'number') {
     2087                                                                        if (ourminutes < minutes_from) {
     2088                                                                                return [false, dateAtDayMinutes(date, minutes_from)];
     2089                                                                        } else if (ourminutes <= minutes_to) {
     2090                                                                                for (var cur_min = minutes_from; ourminutes + point_in_time_period >= cur_min; cur_min += point_in_time_period) {
     2091                                                                                        if (cur_min == ourminutes) {
     2092                                                                                                return [true, dateAtDayMinutes(date, ourminutes + 1)];
     2093                                                                                        } else if (ourminutes < cur_min) {
     2094                                                                                                return [false, dateAtDayMinutes(date, cur_min)];
     2095                                                                                        }
     2096                                                                                }
     2097                                                                        }
     2098                                                                        return [false, dateAtDayMinutes(date, minutes_in_day)];
     2099                                                                } else {
     2100                                                                        if (ourminutes < minutes_from)
     2101                                                                                return [false, dateAtDayMinutes(date, minutes_from)];
     2102                                                                        else
     2103                                                                                return [true, dateAtDayMinutes(date, minutes_to), has_open_end];
     2104                                                                }
     2105                                                        }}(minutes_from, minutes_to, timevar_string, timevar_add, has_open_end, is_point_in_time, point_in_time_period));
     2106
     2107                                                        selectors.wraptime.push(function(minutes_from, minutes_to, timevar_string, timevar_add, has_open_end, is_point_in_time, point_in_time_period) { return function(date) {
     2108                                                                var ourminutes = date.getHours() * 60 + date.getMinutes();
     2109
     2110                                                                if (timevar_string[0]) {
     2111                                                                        var date_from = eval('SunCalc.getTimes(date, lat, lon).' + timevar_string[0]);
     2112                                                                        minutes_from  = date_from.getHours() * 60 + date_from.getMinutes() + timevar_add[0];
     2113                                                                }
     2114                                                                if (timevar_string[1]) {
     2115                                                                        var date_to = eval('SunCalc.getTimes(date, lat, lon).' + timevar_string[1]);
     2116                                                                        minutes_to  = date_to.getHours() * 60 + date_to.getMinutes() + timevar_add[1];
     2117                                                                        // minutes_in_day does not need to be added.
     2118                                                                        // For normal times in it was added in: if (minutes_to < // minutes_from)
     2119                                                                        // above the selector construction and
     2120                                                                        // subtracted in the selector construction call
     2121                                                                        // which returns the selector function.
     2122                                                                }
     2123
     2124                                                                if (typeof point_in_time_period == 'number') {
     2125                                                                        if (ourminutes <= minutes_to) {
     2126                                                                                for (var cur_min = 0; ourminutes + point_in_time_period >= cur_min; cur_min += point_in_time_period) {
     2127                                                                                        if (cur_min == ourminutes) {
     2128                                                                                                return [true, dateAtDayMinutes(date, ourminutes + 1)];
     2129                                                                                        } else if (ourminutes < cur_min) {
     2130                                                                                                return [false, dateAtDayMinutes(date, cur_min)];
     2131                                                                                        }
     2132                                                                                }
     2133                                                                        }
     2134                                                                } else {
     2135                                                                        if (ourminutes < minutes_to)
     2136                                                                                return [true, dateAtDayMinutes(date, minutes_to), has_open_end];
     2137                                                                }
    20522138                                                                return [false, undefined];
    2053                                                 }}(minutes_from, minutes_to - minutes_in_day, timevar_string, timevar_add, has_open_end, is_point_in_time));
    2054                                         } else {
    2055                                                 selectors.time.push(function(minutes_from, minutes_to, timevar_string, timevar_add, has_open_end, is_point_in_time) { return function(date) {
    2056                                                         var ourminutes = date.getHours() * 60 + date.getMinutes();
    2057 
    2058                                                         if (timevar_string[0]) {
    2059                                                                 var date_from = eval('SunCalc.getTimes(date, lat, lon).' + timevar_string[0]);
    2060                                                                 minutes_from  = date_from.getHours() * 60 + date_from.getMinutes() + timevar_add[0];
    2061                                                         }
    2062                                                         if (timevar_string[1]) {
    2063                                                                 var date_to = eval('SunCalc.getTimes(date, lat, lon).' + timevar_string[1]);
    2064                                                                 minutes_to  = date_to.getHours() * 60 + date_to.getMinutes() + timevar_add[1];
    2065                                                         } else if (is_point_in_time) {
    2066                                                                 minutes_to = minutes_from + 1;
    2067                                                         }
    2068 
    2069                                                         if (ourminutes < minutes_from)
    2070                                                                 return [false, dateAtDayMinutes(date, minutes_from)];
    2071                                                         else if (ourminutes < minutes_to)
    2072                                                                 return [true, dateAtDayMinutes(date, minutes_to), has_open_end];
    2073                                                         else
    2074                                                                 return [false, dateAtDayMinutes(date, minutes_from + minutes_in_day)];
    2075                                                 }}(minutes_from, minutes_to, timevar_string, timevar_add, has_open_end, is_point_in_time));
     2139                                                        }}(minutes_from, minutes_to - minutes_in_day, timevar_string, timevar_add, has_open_end, is_point_in_time, point_in_time_period));
     2140                                                } else {
     2141                                                        selectors.time.push(function(minutes_from, minutes_to, timevar_string, timevar_add, has_open_end, is_point_in_time, point_in_time_period) { return function(date) {
     2142                                                                var ourminutes = date.getHours() * 60 + date.getMinutes();
     2143
     2144                                                                if (timevar_string[0]) {
     2145                                                                        var date_from = eval('SunCalc.getTimes(date, lat, lon).' + timevar_string[0]);
     2146                                                                        minutes_from  = date_from.getHours() * 60 + date_from.getMinutes() + timevar_add[0];
     2147                                                                }
     2148                                                                if (timevar_string[1]) {
     2149                                                                        var date_to = eval('SunCalc.getTimes(date, lat, lon).' + timevar_string[1]);
     2150                                                                        minutes_to  = date_to.getHours() * 60 + date_to.getMinutes() + timevar_add[1];
     2151                                                                } else if (is_point_in_time && typeof point_in_time_period != 'number') {
     2152                                                                        minutes_to = minutes_from + 1;
     2153                                                                }
     2154
     2155                                                                if (typeof point_in_time_period == 'number') {
     2156                                                                        if (ourminutes < minutes_from) {
     2157                                                                                return [false, dateAtDayMinutes(date, minutes_from)];
     2158                                                                        } else if (ourminutes <= minutes_to) {
     2159                                                                                for (var cur_min = minutes_from; ourminutes + point_in_time_period >= cur_min; cur_min += point_in_time_period) {
     2160                                                                                        if (cur_min == ourminutes) {
     2161                                                                                                return [true, dateAtDayMinutes(date, ourminutes + 1)];
     2162                                                                                        } else if (ourminutes < cur_min) {
     2163                                                                                                return [false, dateAtDayMinutes(date, cur_min)];
     2164                                                                                        }
     2165                                                                                }
     2166                                                                        }
     2167                                                                        return [false, dateAtDayMinutes(date, minutes_in_day)];
     2168                                                                } else {
     2169                                                                        if (ourminutes < minutes_from)
     2170                                                                                return [false, dateAtDayMinutes(date, minutes_from)];
     2171                                                                        else if (ourminutes < minutes_to)
     2172                                                                                return [true, dateAtDayMinutes(date, minutes_to), has_open_end];
     2173                                                                        else
     2174                                                                                return [false, dateAtDayMinutes(date, minutes_from + minutes_in_day)];
     2175                                                                }
     2176                                                        }}(minutes_from, minutes_to, timevar_string, timevar_add, has_open_end, is_point_in_time, point_in_time_period));
     2177                                                }
    20762178                                        }
    2077 
    2078                                         at = at_end_time + (is_point_in_time ? -1 :
    2079                                                         (has_normal_time[1] ? 3 : (has_time_var_calc[1] ? 7 : !has_open_end))
    2080                                                         );
    20812179                                } else if (matchTokens(tokens, at, 'number', '-', 'number')) { // "Mo 09-18" -> "Mo 09:00-18:00". Please don’t use this
    20822180                                        var minutes_from = tokens[at][0]   * 60;
     
    21562254                                        if (matchTokens(tokens, at+6, ')')) {
    21572255                                                var add_or_subtract = tokens[at+2][0] == '+' ? '1' : '-1';
    2158                                                 return (tokens[at+3][0] * 60 + tokens[at+5][0]) * add_or_subtract;
     2256                                                var minutes = (tokens[at+3][0] * 60 + tokens[at+5][0]) * add_or_subtract;
     2257                                                if (minutes == 0)
     2258                                                        parsing_warnings.push([ nblock, at+5, 'Adding zero in a variable time calculation does not change the variable time.'
     2259                                                                        + ' Please omit the calculation (example: "12:00-sunset").' ]
     2260                                                                );
     2261                                                return minutes;
    21592262                                        } else {
    21602263                                                error = [ at+6, '. Missing ")".'];
     
    21762279                        if (tokens[at+2][0] > 59)
    21772280                                throw formatWarnErrorMessage(nblock, at+2,
    2178                                                 'Minutes are greter than 59.');
     2281                                                'Minutes are greater than 59.');
    21792282                        return tokens[at][0] * 60 + tokens[at+2][0];
    21802283                }
     
    23452448                        }
    23462449
    2347                         if (typeof used_subparsers['weekdays'] != 'number')
    2348                                 used_subparsers['weekdays'] = 1;
     2450                        if (typeof used_subparsers['weekdays'] != 'object')
     2451                                used_subparsers['weekdays'] = [ at ];
    23492452                        else
    2350                                 used_subparsers['weekdays']++;
     2453                                used_subparsers['weekdays'].push(at);
    23512454
    23522455                        return at;
     
    27762879                        }
    27772880
    2778                         if (typeof used_subparsers['year ranges'] != 'number')
    2779                                 used_subparsers['year ranges'] = 1;
     2881                        if (typeof used_subparsers['year ranges'] != 'object')
     2882                                used_subparsers['year ranges'] = [ at ];
    27802883                        else
    2781                                 used_subparsers['year ranges']++;
     2884                                used_subparsers['year ranges'].push(at);
    27822885
    27832886                        return at;
     
    28492952                        }
    28502953
    2851                         if (typeof used_subparsers['week ranges'] != 'number')
    2852                                 used_subparsers['week ranges'] = 1;
     2954                        if (typeof used_subparsers['week ranges'] != 'object')
     2955                                used_subparsers['week ranges'] = [ at ];
    28532956                        else
    2854                                 used_subparsers['week ranges']++;
     2957                                used_subparsers['week ranges'].push;
    28552958
    28562959                        return at;
     
    29253028                        }
    29263029
    2927                         if (typeof used_subparsers['months'] != 'number')
    2928                                 used_subparsers['months'] = 1;
     3030                        if (typeof used_subparsers['months'] != 'object')
     3031                                used_subparsers['months'] = [ at ];
    29293032                        else
    2930                                 used_subparsers['months']++;
     3033                                used_subparsers['months'].push(at);
    29313034
    29323035                        return at;
     
    32023305                        }
    32033306
    3204                         if (typeof used_subparsers['monthday ranges'] != 'number')
    3205                                 used_subparsers['monhday ranges'] = 1;
     3307                        if (typeof used_subparsers['monthday ranges'] != 'object')
     3308                                used_subparsers['monhday ranges'] = [ at ];
    32063309                        else
    3207                                 used_subparsers['monhday ranges']++;
    3208 
    3209                         // console.log(tokens[at-1], 'return');
     3310                                used_subparsers['monhday ranges'].push(at);
     3311
    32103312                        return at;
    32113313                }
     
    32183320                        var changedate;
    32193321                        var unknown = false;
    3220                         var comment = undefined;
     3322                        var comment;
    32213323                        var match_block;
    32223324
     
    33903492                                        value += (tokens[at+2][0] < 10 ? '0' : '') + tokens[at+2][0].toString();
    33913493                                        value += ':00';
    3392                                         at += 3;
     3494                                        at += 2;
    33933495                                } else if (matchTokens(tokens, at, 'comment')) {
    33943496                                        value += '"' + tokens[at][0].toString() + '"';
     
    34773579                                                var user_conf = {};
    34783580                                        for (key in default_prettify_conf) {
    3479                                                 if (typeof user_conf[key] != 'undefined')
     3581                                                if (typeof user_conf[key] == 'undefined')
    34803582                                                        user_conf[key] = default_prettify_conf[key];
    34813583                                        }
     
    34943596                                        };
    34953597
    3496                                         parseGroup(tokens[state[4]][0], 0, selectors, state[4], user_conf);
     3598                                        // token block index used to build the selectors for this block.
     3599                                        var token_block = blocks[state[4]].build_from_token_block;
     3600                                        parseGroup(tokens[token_block[0]][0], token_block[1], selectors, state[4], user_conf);
     3601
     3602                                        if (prettified_value[prettified_value.length - 1] == ',')
     3603                                                prettified_value = prettified_value.substr(0, prettified_value.length - 1);
    34973604
    34983605                                        done_with_warnings = really_done_with_warnings;
Note: See TracChangeset for help on using the changeset viewer.