Changeset 7537 in josm


Ignore:
Timestamp:
2014-09-14T23:35:46+02:00 (10 years ago)
Author:
Don-vip
Message:

see #10513 - opening_hours: replace prototype definition by standard function as a workaround to Java 7 / Webstart incompatibility

File:
1 edited

Legend:

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

    r7514 r7537  
    41974197
    41984198                                                selectors.week.push(function(week_from, week_to, is_range, period) { return function(date) {
    4199                                                         var ourweek = date.getWeekNumber();
     4199                                                        var ourweek = getWeekNumber(date);
    42004200
    42014201                                                        // console.log("week_from: %s, week_to: %s", week_from, week_to);
     
    42424242
    42434243                // http://stackoverflow.com/a/6117889
    4244                 Date.prototype.getWeekNumber = function(){
    4245                         var d = new Date(+this);
    4246                         d.setHours(0,0,0);
    4247                         d.setDate(d.getDate()+4-(d.getDay()||7));
    4248                         return Math.ceil((((d-new Date(d.getFullYear(),0,1))/8.64e7)+1)/7);
    4249                 };
     4244                /* For a given date, get the ISO week number
     4245                 *
     4246                 * Based on information at:
     4247                 *
     4248                 *    http://www.merlyn.demon.co.uk/weekcalc.htm#WNR
     4249                 *
     4250                 * Algorithm is to find nearest thursday, it's year
     4251                 * is the year of the week number. Then get weeks
     4252                 * between that date and the first day of that year.
     4253                 *
     4254                 * Note that dates in one year can be weeks of previous
     4255                 * or next year, overlap is up to 3 days.
     4256                 *
     4257                 * e.g. 2014/12/29 is Monday in week  1 of 2015
     4258                 *      2012/1/1   is Sunday in week 52 of 2011
     4259                 */
     4260                function getWeekNumber(d) {
     4261                    // Copy date so don't modify original
     4262                    d = new Date(+d);
     4263                    d.setHours(0,0,0);
     4264                    // Set to nearest Thursday: current date + 4 - current day number
     4265                    // Make Sunday's day number 7
     4266                    d.setDate(d.getDate() + 4 - (d.getDay()||7));
     4267                    // Get first day of year
     4268                    var yearStart = new Date(d.getFullYear(),0,1);
     4269                    // Calculate full weeks to nearest Thursday
     4270                    return Math.ceil(( ( (d - yearStart) / 86400000) + 1)/7)
     4271                }
    42504272                // http://stackoverflow.com/a/16591175
    42514273                function getDateOfISOWeek(w, y) {
Note: See TracChangeset for help on using the changeset viewer.