Changeset 6489 in josm for trunk/data/validator
- Timestamp:
- 2013-12-18T03:03:14+01:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/data/validator/opening_hours.js
r6488 r6489 4 4 //====================================================================== 5 5 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 }, 6 32 'de': { 7 33 'PH': { // http://de.wikipedia.org/wiki/Feiertage_in_Deutschland … … 1090 1116 wrong_words: { 1091 1117 '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', 1094 1122 }, 'Bitte benutze die englische Schreibweise "<ok>" für "<ko>".': { 1095 1123 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', 1099 1128 }, 'Assuming "<ok>" for "<ko>". Please avoid using "workday": http://wiki.openstreetmap.org/wiki/Talk:Key:opening_hours#need_syntax_for_holidays_and_workingdays': { 1100 1129 // // Used around 260 times but the problem is, that work day might be different in other countries. … … 1106 1135 }, 'Please ommit "<ko>".': { 1107 1136 season: '', 1137 hs: '', 1138 hrs: '', 1139 hours: '', 1108 1140 }, 'Please ommit "<ko>". You might want to express open end which can be specified as "12:00+" for example': { 1109 1141 from: '', 1110 }, 'Please use notation "<ok>" for "<ko>". If the times are unsure or var iateconsider 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".': { 1111 1143 '~': '-', 1144 '~': '-', 1112 1145 }, 'Please use notation "<ok>" for "<ko>".': { 1113 1146 '–': '-', 1147 'ー': '-', 1114 1148 to: '-', 1115 1149 till: '-', 1116 1150 and: ',', 1117 1151 '&': ',', 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', 1120 1157 midnight: '00:00', 1158 holiday: 'PH', 1159 holidays: 'PH', 1160 // summerholiday: 'SH', 1161 // summerholidays: 'SH', 1121 1162 }, 'Please use time format in 24 hours notation ("<ko>").': { 1122 1163 pm: '', … … 1129 1170 }, 'Bitte benutze die Schreibweise "<ok>" für "<ko>".': { 1130 1171 bis: '-', 1172 'täglich': 'Mo-Su', 1173 }, 'Bitte benutze die Schreibweise "<ok>" als Ersatz für "und" bzw. "u.".': { 1131 1174 und: ',', 1175 u: ',', 1132 1176 }, 'Bitte benutze die englische Abkürzung "<ok>" für "<ko>".': { 1133 1177 feiertag: 'PH', 1178 feiertags: 'PH', 1134 1179 feiertage: 'PH', 1135 1180 feiertagen: 'PH' … … 1483 1528 do { 1484 1529 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. 1486 1531 1487 1532 var selectors = { … … 1508 1553 unknown: false, 1509 1554 comment: undefined, 1555 build_from_token_block: undefined, 1510 1556 }; 1511 1557 1558 selectors.build_from_token_block = [ nblock, continue_at ]; 1512 1559 continue_at = parseGroup(tokens[nblock][0], continue_at, selectors, nblock); 1513 1560 if (typeof continue_at == 'object') … … 1589 1636 curr_block_tokens.push([tmp[0].toLowerCase(), 'calcday', value.length ]); 1590 1637 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)) { 1592 1639 // Handle all remaining words with error tolerance 1593 1640 var correct_val = returnCorrectWordOrToken(tmp[1].toLowerCase(), value.length); … … 1737 1784 function parseGroup(tokens, at, selectors, nblock, conf) { 1738 1785 var prettified_group_value = ''; 1739 used_subparsers = { 'time ranges': 0};1786 used_subparsers = { 'time ranges': [ ] }; 1740 1787 1741 1788 // console.log(tokens); // useful for debugging of tokenize … … 1791 1838 at = parseTimeRange(tokens, at, selectors); 1792 1839 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); 1797 1841 } else if (matchTokens(tokens, at, 'closed')) { 1798 1842 selectors.meaning = false; … … 1801 1845 at = [ at + 1 ]; 1802 1846 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 ]; 1805 1849 else 1806 used_subparsers['state keywords'] ++;1850 used_subparsers['state keywords'].push(at); 1807 1851 } else if (matchTokens(tokens, at, 'open')) { 1808 1852 selectors.meaning = true; … … 1811 1855 at = [ at + 1 ]; 1812 1856 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 ]; 1815 1859 else 1816 used_subparsers['state keywords'] ++;1860 used_subparsers['state keywords'].push(at); 1817 1861 } else if (matchTokens(tokens, at, 'unknown')) { 1818 1862 selectors.meaning = false; … … 1822 1866 at = [ at + 1 ]; 1823 1867 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 ]; 1826 1870 else 1827 used_subparsers['state keywords'] ++;1871 used_subparsers['state keywords'].push(at); 1828 1872 } else if (matchTokens(tokens, at, 'comment')) { 1829 1873 selectors.comment = tokens[at][0]; … … 1846 1890 at = [ at + 1 ]; 1847 1891 1848 if (typeof used_subparsers['comments'] != ' number')1849 used_subparsers['comments'] = 1;1892 if (typeof used_subparsers['comments'] != 'object') 1893 used_subparsers['comments'] = [ at ]; 1850 1894 else 1851 used_subparsers['comments'] ++;1895 used_subparsers['comments'].push(at); 1852 1896 } else { 1853 1897 var warnings = getWarnings(); … … 1869 1913 prettified_group_value = prettified_group_value.substring(0, prettified_group_value.length - 1); 1870 1914 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); 1872 1916 } 1873 1917 … … 1880 1924 if (!done_with_warnings) { 1881 1925 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.' 1886 1931 + ' 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.' 1891 1934 + ' This is probably an error.' 1892 1935 + ' 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 ); 1895 1940 } 1896 1941 } 1897 1942 } 1898 1899 1943 1900 1944 return at; … … 1912 1956 // relying on the fact that always *one* of them is true 1913 1957 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]) { 1917 1965 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 } 1925 1974 } 1926 1975 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, '+')) { 1930 1979 has_open_end = true; 1931 1980 } else { … … 1933 1982 throw formatWarnErrorMessage(nblock, at+(has_normal_time[0] ? 3 : (has_time_var_calc[0] ? 2 : 1)), 1934 1983 '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?'); 1937 1987 } else { 1938 1988 var minutes_to = minutes_from + 1; … … 1942 1992 } 1943 1993 1944 var at_end_time = at+(has_normal_time[0] ? 3 : (has_time_var_calc[0] ? 7 : 1))+1; // after '-'1994 // minutes_to 1945 1995 if (has_open_end) { 1946 1996 if (minutes_from >= 22 * 60) 1947 var minutes_to = minutes_from + 60 * 8;1997 var minutes_to = minutes_from + 8 * 60; 1948 1998 else if (minutes_from >= 17 * 60) 1949 var minutes_to = minutes_from + 60 * 10;1999 var minutes_to = minutes_from + 10 * 60; 1950 2000 else 1951 2001 var minutes_to = minutes_in_day; … … 1954 2004 has_time_var_calc[1] = matchTokens(tokens, at_end_time, '(', 'timevar'); 1955 2005 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'); 1961 2007 } else { 1962 if (has_normal_time[1]) 2008 if (has_normal_time[1]) { 1963 2009 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 } 1966 2014 1967 2015 if (has_time_var_calc[1]) { … … 1969 2017 minutes_to += timevar_add[1]; 1970 2018 } 1971 1972 // this shortcut makes always-open range check faster1973 // and is also useful in tests, as it doesn't produce1974 // extra check points which may hide errors in other1975 // selectors1976 // 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.1979 2019 } 1980 2020 } 1981 2021 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 1982 2055 // normalize minutes into range 1983 // XXX: what if it's further than tomorrow?1984 // XXX: this is incorrect, as it assumes the same day1985 // should cooperate with date selectors to select the next day1986 2056 if (minutes_from >= minutes_in_day) 1987 2057 throw formatWarnErrorMessage(nblock, at_end_time - 1, … … 1993 2063 'Time spanning more than two midnights not supported'); 1994 2064 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 } 2052 2138 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 } 2076 2178 } 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 );2081 2179 } else if (matchTokens(tokens, at, 'number', '-', 'number')) { // "Mo 09-18" -> "Mo 09:00-18:00". Please don’t use this 2082 2180 var minutes_from = tokens[at][0] * 60; … … 2156 2254 if (matchTokens(tokens, at+6, ')')) { 2157 2255 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; 2159 2262 } else { 2160 2263 error = [ at+6, '. Missing ")".']; … … 2176 2279 if (tokens[at+2][0] > 59) 2177 2280 throw formatWarnErrorMessage(nblock, at+2, 2178 'Minutes are gre ter than 59.');2281 'Minutes are greater than 59.'); 2179 2282 return tokens[at][0] * 60 + tokens[at+2][0]; 2180 2283 } … … 2345 2448 } 2346 2449 2347 if (typeof used_subparsers['weekdays'] != ' number')2348 used_subparsers['weekdays'] = 1;2450 if (typeof used_subparsers['weekdays'] != 'object') 2451 used_subparsers['weekdays'] = [ at ]; 2349 2452 else 2350 used_subparsers['weekdays'] ++;2453 used_subparsers['weekdays'].push(at); 2351 2454 2352 2455 return at; … … 2776 2879 } 2777 2880 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 ]; 2780 2883 else 2781 used_subparsers['year ranges'] ++;2884 used_subparsers['year ranges'].push(at); 2782 2885 2783 2886 return at; … … 2849 2952 } 2850 2953 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 ]; 2853 2956 else 2854 used_subparsers['week ranges'] ++;2957 used_subparsers['week ranges'].push; 2855 2958 2856 2959 return at; … … 2925 3028 } 2926 3029 2927 if (typeof used_subparsers['months'] != ' number')2928 used_subparsers['months'] = 1;3030 if (typeof used_subparsers['months'] != 'object') 3031 used_subparsers['months'] = [ at ]; 2929 3032 else 2930 used_subparsers['months'] ++;3033 used_subparsers['months'].push(at); 2931 3034 2932 3035 return at; … … 3202 3305 } 3203 3306 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 ]; 3206 3309 else 3207 used_subparsers['monhday ranges']++; 3208 3209 // console.log(tokens[at-1], 'return'); 3310 used_subparsers['monhday ranges'].push(at); 3311 3210 3312 return at; 3211 3313 } … … 3218 3320 var changedate; 3219 3321 var unknown = false; 3220 var comment = undefined;3322 var comment; 3221 3323 var match_block; 3222 3324 … … 3390 3492 value += (tokens[at+2][0] < 10 ? '0' : '') + tokens[at+2][0].toString(); 3391 3493 value += ':00'; 3392 at += 3;3494 at += 2; 3393 3495 } else if (matchTokens(tokens, at, 'comment')) { 3394 3496 value += '"' + tokens[at][0].toString() + '"'; … … 3477 3579 var user_conf = {}; 3478 3580 for (key in default_prettify_conf) { 3479 if (typeof user_conf[key] != 'undefined')3581 if (typeof user_conf[key] == 'undefined') 3480 3582 user_conf[key] = default_prettify_conf[key]; 3481 3583 } … … 3494 3596 }; 3495 3597 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); 3497 3604 3498 3605 done_with_warnings = really_done_with_warnings;
Note:
See TracChangeset
for help on using the changeset viewer.