Changeset 6420 in josm for trunk/data/opening_hours.js


Ignore:
Timestamp:
2013-11-28T18:51:43+01:00 (10 years ago)
Author:
simon04
Message:

fix #9367 - opening_hours - upgrade validator so that it will can fix missing minutes in automatic way

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/data/opening_hours.js

    r6370 r6420  
    11021102                                weekday:  'Mo-Fr',
    11031103                                weekdays: 'Mo-Fr',
     1104                        }, 'Please ommit "<ko>" or use a colon instead: "12:00-14:00".': {
     1105                                h: '',
    11041106                        }, 'Please ommit "<ko>".': {
    1105                                 h: '',
    11061107                                season: '',
    11071108                        }, 'Please ommit "<ko>". You might want to express open end which can be specified as "12:00+" for example': {
    11081109                                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".': {
     1111                                '~':  '-',
    11091112                        }, 'Please use notation "<ok>" for "<ko>".': {
    11101113                                '–':  '-',
     
    11551158                                nov: 10,
    11561159                                dec: 11,
    1157                         }, 'Please use the englisch abbreviation "<ok>" for "<ko>".': {
     1160                        }, 'Please use the English abbreviation "<ok>" for "<ko>".': {
    11581161                                january:    0,
    11591162                                february:   1,
     
    12151218                                fr: 5,
    12161219                                sa: 6,
     1220                        }, 'Assuming "<ok>" for "<ko>"': {
     1221                                m:          1,
     1222                                w:          3,
     1223                                f:          5,
    12171224                        }, 'Please use the abbreviation "<ok>" for "<ko>".': {
    12181225                                sun:        0,
    12191226                                sunday:     0,
    12201227                                sundays:    0,
    1221                                 m:          1,
    12221228                                mon:        1,
    12231229                                monday:     1,
     
    12261232                                tuesday:    2,
    12271233                                tuesdays:   2,
    1228                                 w:          3,
    12291234                                wed:        3,
    12301235                                wednesday:  3,
     
    12331238                                thursday:   4,
    12341239                                thursdays:  4,
    1235                                 f:          5,
    12361240                                fri:        5,
    12371241                                friday:     5,
     
    12401244                                saturday:   6,
    12411245                                saturdays:  6,
     1246                        }, 'Bitte benutze die englische Abkürzung "<ok>" für "<ko>". Could also mean Saturday in Polish …': {
     1247                                so:         0,
    12421248                        }, 'Bitte benutze die englische Abkürzung "<ok>" für "<ko>".': {
    1243                                 so:         0,
    1244                                 son:        0,
    1245                                 sonntag:    0,
    1246                                 montag:     1,
    1247                                 di:         2,
    1248                                 die:        2,
    1249                                 dienstag:   2,
    1250                                 mi:         3,
    1251                                 mit:        3,
    1252                                 mittwoch:   3,
    1253                                 'do':       4,
    1254                                 don:        4,
    1255                                 donnerstag: 4,
    1256                                 fre:        5,
    1257                                 freitag:    5,
    1258                                 sam:        6,
    1259                                 samstag:    6,
     1249                                son:         0,
     1250                                sonntag:     0,
     1251                                sonntags:    0,
     1252                                montag:      1,
     1253                                montags:     1,
     1254                                di:          2,
     1255                                die:         2,
     1256                                dienstag:    2,
     1257                                dienstags:   2,
     1258                                mi:          3,
     1259                                mit:         3,
     1260                                mittwoch:    3,
     1261                                mittwochs:   3,
     1262                                'do':        4,
     1263                                don:         4,
     1264                                donnerstag:  4,
     1265                                donnerstags: 4,
     1266                                fre:         5,
     1267                                freitag:     5,
     1268                                freitags:    5,
     1269                                sam:         6,
     1270                                samstag:     6,
     1271                                samstags:    6,
    12601272                        }, 'S\'il vous plaît utiliser l\'abréviation "<ok>" pour "<ko>".': {
    12611273                                dim:      0,
     
    12911303                                zat:       6,
    12921304                                zaterdag:  6,
    1293                         }, 'Please use the englisch abbreviation "<ok>" for "<ko>".': { // FIXME: Translate to Czech.
     1305                        }, 'Please use the English abbreviation "<ok>" for "<ko>".': { // FIXME: Translate to Czech.
    12941306                                'neděle':  0,
    12951307                                'ne':      0,
     
    13051317                                'pá':      5,
    13061318                                'sobota':  6,
    1307                         }, 'Please use the englisch abbreviation "<ok>" for "<ko>".': {
     1319                        }, 'Please use the English abbreviation "<ok>" for "<ko>".': {
    13081320                                // Spanish.
    13091321                                'martes':    0,
     
    13311343                                'fredag':  5,
    13321344                                'lördag':  6,
     1345                                // Polish
     1346                                'niedziela': 0, 'niedz': 0, 'n': 0, 'ndz': 0,
     1347                                'poniedziałek': 1, 'poniedzialek': 1, 'pon': 1, 'pn': 1,
     1348                                'wtorek': 2, 'wt': 2,
     1349                                'środa': 3, 'sroda': 3, 'śr': 3, 'sr': 3,
     1350                                'czwartek': 4, 'czw': 4, 'cz': 4,
     1351                                'piątek': 5, 'piatek': 5, 'pt': 5,
     1352                                'sobota': 6, 'sob': 6, // 'so': 6 // abbreviation also used in German
    13331353                        },
    13341354                },
     
    15691589                                        curr_block_tokens.push([tmp[0].toLowerCase(), 'calcday', value.length ]);
    15701590                                        value = value.substr(tmp[0].length);
    1571                                 } else if (tmp = value.match(/^(&|–|[a-zA-ZäÄàÀéÉ]+\b)\.?/i)) {
     1591                                } else if (tmp = value.match(/^(&|–|~|[a-zA-ZäÄàÀéÉ]+\b)\.?/i)) {
    15721592                                        // Handle all remaining words with error tolerance
    15731593                                        var correct_val = returnCorrectWordOrToken(tmp[1].toLowerCase(), value.length);
     
    17401760                                                || matchTokens(tokens, at, 'year', 'event')
    17411761                                                || matchTokens(tokens, at, 'event')) {
    1742                                         at = parseMonthdayRange(tokens, at);
     1762                                        at = parseMonthdayRange(tokens, at, nblock);
    17431763                                        week_stable = false;
    17441764                                } else if (matchTokens(tokens, at, 'year')) {
     
    17511771                                        at = parseWeekRange(tokens, at + 1);
    17521772                                        week_stable = false;
     1773
     1774                                        // if (prettified_group_value[-1] != ' ')
     1775                                        //      prettified_group_value = prettified_group_value.substring(0, prettified_group_value.length - 1);
    17531776                                } else if (at != 0 && at != tokens.length - 1 && tokens[at][0] == ':') {
    17541777                                        // Ignore colon if they appear somewhere else than as time separator.
     1778                                        // Except the start or end of the value.
    17551779                                        // This provides compatibility with the syntax proposed by Netzwolf:
    1756                                         // http://www.netzwolf.info/en/cartography/osm/time_domain/specification
     1780                                        // http://wiki.openstreetmap.org/wiki/Key:opening_hours:specification
    17571781                                        if (!done_with_warnings && matchTokens(tokens, at-1, 'weekday') || matchTokens(tokens, at-1, 'holiday'))
    17581782                                                parsing_warnings.push([nblock, at, 'Please don’t use ":" after ' + tokens[at-1][1] + '.']);
     
    17631787                                } else if (matchTokens(tokens, at, 'number', 'timesep')
    17641788                                                || matchTokens(tokens, at, 'timevar')
    1765                                                 || matchTokens(tokens, at, '(', 'timevar')) {
     1789                                                || matchTokens(tokens, at, '(', 'timevar')
     1790                                                || matchTokens(tokens, at, 'number', '-')) {
    17661791                                        at = parseTimeRange(tokens, at, selectors);
    17671792
     
    18331858
    18341859                                if (typeof conf != 'undefined') {
     1860
     1861                                        // 'Mo: 12:00-13:00' -> 'Mo 12:00-13:00'
     1862                                        if (used_subparsers['time ranges'] && old_at > 1 && tokens[old_at-1][0] == ':'
     1863                                                        && matchTokens(tokens, old_at - 2, 'weekday'))
     1864                                                prettified_group_value = prettified_group_value.substring(0, prettified_group_value.length - 2) + ' ';
     1865
     1866                                        // 'week 1, week 3' -> 'week 1,week 3'
     1867                                        if (prettified_group_value.substr(prettified_group_value.length -2, 2) == ', '
     1868                                                        && matchTokens(tokens, old_at, 'week'))
     1869                                                prettified_group_value = prettified_group_value.substring(0, prettified_group_value.length - 1);
     1870
    18351871                                        prettified_group_value += prettifySelector(tokens, old_at, at, conf, used_subparsers['time ranges']);
    18361872                                }
     
    20432079                                                        (has_normal_time[1] ? 3 : (has_time_var_calc[1] ? 7 : !has_open_end))
    20442080                                                        );
     2081                                } else if (matchTokens(tokens, at, 'number', '-', 'number')) { // "Mo 09-18" -> "Mo 09:00-18:00". Please don’t use this
     2082                                        var minutes_from = tokens[at][0]   * 60;
     2083                                        var minutes_to   = tokens[at+2][0] * 60;
     2084                                        if (!done_with_warnings)
     2085                                                parsing_warnings.push([nblock, at + 2,
     2086                                                        'Time range without minutes specified. Not very explicit! Please use this syntax instead e.g. "12:00-14:00".']);
     2087
     2088                                        if (minutes_from >= minutes_in_day)
     2089                                                throw formatWarnErrorMessage(nblock, at,
     2090                                                        'Time range starts outside of the current day');
     2091                                        if (minutes_to < minutes_from)
     2092                                                minutes_to += minutes_in_day;
     2093                                        if (minutes_to > minutes_in_day * 2)
     2094                                                throw formatWarnErrorMessage(nblock, at + 2,
     2095                                                        'Time spanning more than two midnights not supported');
     2096
     2097                                        if (minutes_to > minutes_in_day) {
     2098                                                selectors.time.push(function(minutes_from, minutes_to) { return function(date) {
     2099                                                        var ourminutes = date.getHours() * 60 + date.getMinutes();
     2100
     2101                                                        if (ourminutes < minutes_from)
     2102                                                                return [false, dateAtDayMinutes(date, minutes_from)];
     2103                                                        else
     2104                                                                return [true, dateAtDayMinutes(date, minutes_to)];
     2105                                                }}(minutes_from, minutes_to));
     2106
     2107                                                selectors.wraptime.push(function(minutes_from, minutes_to) { return function(date) {
     2108                                                        var ourminutes = date.getHours() * 60 + date.getMinutes();
     2109
     2110                                                        if (ourminutes < minutes_to)
     2111                                                                return [true, dateAtDayMinutes(date, minutes_to)];
     2112                                                        else
     2113                                                                return [false, undefined];
     2114                                                }}(minutes_from, minutes_to - minutes_in_day));
     2115                                        } else {
     2116                                                selectors.time.push(function(minutes_from, minutes_to) { return function(date) {
     2117                                                        var ourminutes = date.getHours() * 60 + date.getMinutes();
     2118
     2119                                                        if (ourminutes < minutes_from)
     2120                                                                return [false, dateAtDayMinutes(date, minutes_from)];
     2121                                                        else if (ourminutes < minutes_to)
     2122                                                                return [true, dateAtDayMinutes(date, minutes_to), has_open_end];
     2123                                                        else
     2124                                                                return [false, dateAtDayMinutes(date, minutes_from + minutes_in_day)];
     2125                                                }}(minutes_from, minutes_to));
     2126                                        }
     2127
     2128                                        at += 3;
    20452129                                } else { // additional block
    20462130                                        if (matchTokens(tokens, at, '('))
     
    26332717                                                var is_range   = true;
    26342718                                                var has_period = true;
    2635                                                 if (tokens[at+4][0] == 1 && !done_with_warnings)
     2719                                                if (!done_with_warnings && tokens[at+4][0] == 1)
    26362720                                                        parsing_warnings.push([nblock, at+1+3, 'Please don’t use year ranges with period equals one (see README)']);
    26372721                                        } else {
     
    27582842                                if (!matchTokens(tokens, at, ','))
    27592843                                        break;
     2844
     2845                                if (!matchTokens(tokens, at+1, 'number')) {
     2846                                        at++; // we don‘t need the comma in parseGroup
     2847                                        break;
     2848                                }
    27602849                        }
    27612850
     
    28892978                // Month day range parser (Jan 26-31; Jan 26-Feb 26)
    28902979                //======================================================================
    2891                 function parseMonthdayRange(tokens, at) {
     2980                function parseMonthdayRange(tokens, at, nblock) {
    28922981                        for (; at < tokens.length; at++) {
    28932982                                var has_year = [], has_month = [], has_event = [], has_calc = [], has_constrained_weekday = [], has_calc = [];
     
    30553144                                                        return [true, to_date];
    30563145
    3057                                                 var period = tokens[at+5][0];
     3146                                                var period = tokens[at+has_year+5][0];
     3147                                                if (!done_with_warnings && period == 1)
     3148                                                        parsing_warnings.push([nblock, at+has_year+5, 'Please don’t use day ranges with period equals one (see README)']);
    30583149                                                var nday = Math.floor((date.getTime() - from_date.getTime()) / msec_in_day);
    30593150                                                var in_period = nday % period;
     
    30633154                                                else
    30643155                                                        return [false, new Date(date.getFullYear(), date.getMonth(), date.getDate() + period - in_period)];
     3156
    30653157                                        }}(tokens, at, is_range, has_period, has_year[0]));
    30663158
     
    32753367                        var start_at = at;
    32763368                        while (at < last_at) {
    3277                                 if (matchTokens(tokens, at, 'weekday')) {
     3369                                if (matchTokens(tokens, at, 'weekday')) { // FIXME
    32783370                                        if (!conf.leave_weekday_sep_one_day_betw
    32793371                                                && at - start_at > 1 && (matchTokens(tokens, at-1, ',') || matchTokens(tokens, at-1, '-'))
     
    32843376                                        value += weekdays[tokens[at][0]];
    32853377                                } else if (at - start_at > 0 && used_parseTimeRange > 0 && matchTokens(tokens, at-1, 'timesep')
    3286                                                 && matchTokens(tokens, at, 'number')) {
     3378                                                && matchTokens(tokens, at, 'number')) { // '09:0' -> '09:00'
    32873379                                        value += (tokens[at][0] < 10 ? '0' : '') + tokens[at][0].toString();
    32883380                                } else if (used_parseTimeRange > 0 && conf.leading_zero_hour && at != tokens.length
    3289                                                 && matchTokens(tokens, at+1, 'timesep')) {
     3381                                                && matchTokens(tokens, at, 'number')
     3382                                                && matchTokens(tokens, at+1, 'timesep')) { // '9:00' -> '19:00'
    32903383                                        value += (tokens[at][0] < 10 ? (tokens[at][0] == 0 && conf.one_zero_if_hour_zero ? '' : '0') : '') + tokens[at][0].toString();
     3384                                } else if (used_parseTimeRange > 0 && at + 2 < last_at
     3385                                                && matchTokens(tokens, at, 'number')
     3386                                                && matchTokens(tokens, at+1, '-')
     3387                                                && matchTokens(tokens, at+2, 'number')) { // '9-18' -> '09:00-18:00'
     3388                                        value += (tokens[at][0] < 10 ? (tokens[at][0] == 0 && conf.one_zero_if_hour_zero ? '' : '0') : '') + tokens[at][0].toString();
     3389                                        value += ':00-';
     3390                                        value += (tokens[at+2][0] < 10 ? '0' : '') + tokens[at+2][0].toString();
     3391                                        value += ':00';
     3392                                        at += 3;
    32913393                                } else if (matchTokens(tokens, at, 'comment')) {
    32923394                                        value += '"' + tokens[at][0].toString() + '"';
     
    33073409                                        value += months[[tokens[at][0]]];
    33083410                                        if (at + 1 < last_at && matchTokens(tokens, at+1, 'weekday'))
    3309                                         value += ' ';
     3411                                                value += ' ';
    33103412                                } else if (at + 2 < last_at
    33113413                                                && (matchTokens(tokens, at, '-') || matchTokens(tokens, at, '+'))
Note: See TracChangeset for help on using the changeset viewer.