1( function ( root, undefined ) { 2 "use strict"; 3 4 // Create the local library object, to be exported or referenced globally later 5 var lib = {}; 6 7 var formatNumber = function ( value ) { 8 var num = '' + value; 9 if ( value < 10 ) { 10 num = '0' + num; 11 } 12 return num; 13 }; 14 15 lib.DAY_IN_SECONDS = 60 * 60 * 24; 16 lib.DAY_IN_MILLISECONDS = lib.DAY_IN_SECONDS * 1000; 17 18 lib.formatDate = function ( date ) { 19 return [ 20 date.getFullYear(), 21 formatNumber( date.getMonth() + 1 ), 22 formatNumber( date.getDate() ) 23 ].join( '-' ); 24 }; 25 26 lib.add_days_to_date = function ( date, days ) { 27 if ( typeof date === 'object' ) { 28 date = lib.formatDate( date ); 29 } 30 31 // Add time to get the date at midnight in the current timezone (to prevent issues with negative timezones). 32 date = date + 'T00:00:00'; 33 34 date = new Date( date ); 35 date.setDate( date.getDate() + days ); 36 return date; 37 }; 38 39 lib.date_diff = function ( dateA, dateB, type ) { 40 //support for iOS devices 41 if ( typeof dateA === 'string' ) { 42 dateA = dateA.replace( /-/g, '/' ); 43 } 44 45 if ( typeof dateB === 'string' ) { 46 dateB = dateB.replace( /-/g, '/' ); 47 } 48 49 dateA = new Date( dateA ); 50 dateB = new Date( dateB ); 51 type = ( typeof type !== 'undefined' ) ? type : 'seconds'; 52 var interval = 0, 53 t1, t2; 54 55 switch ( type ) { 56 case 'days': 57 // subtract timezone offset in milliseconds to retrieve the UTC time: to prevent issues with Daylight Saving Time 58 t2 = dateA.getTime() - ( dateA.getTimezoneOffset() * 60 * 1000 ); 59 t1 = dateB.getTime() - ( dateB.getTimezoneOffset() * 60 * 1000 ); 60 61 interval = parseInt( ( t2 - t1 ) / ( 24 * 3600 * 1000 ) ); 62 break; 63 case 'months': 64 var d2Y = dateA.getFullYear(), 65 d1Y = dateB.getFullYear(), 66 d2M = dateA.getMonth(), 67 d1M = dateB.getMonth(); 68 69 interval = ( d2M + 12 * d2Y ) - ( d1M + 12 * d1Y ); 70 break; 71 default: 72 // subtract timezone offset in milliseconds to retrieve the UTC time: to prevent issues with Daylight Saving Time 73 t2 = dateA.getTime() - ( dateA.getTimezoneOffset() * 60 * 1000 ); 74 t1 = dateB.getTime() - ( dateB.getTimezoneOffset() * 60 * 1000 ); 75 76 interval = parseInt( ( t2 - t1 ), 10 ); 77 break; 78 } 79 80 return isNaN( interval ) ? 0 : interval; 81 }; 82 83 // Declare `fx` on the root (global/window) object: 84 root[ 'yith_wcbk_dates' ] = lib; 85 86 // Root will be `window` in browser or `global` on the server: 87}( this ) );
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.