1/*globals livewhale: true */ 2 3/* 4 * Dependency: livewhale.lib.DateFormatter 5 * 6 * Handles the conversion and output of a timestamp in a specified timezone 7 */ 8 9if (typeof livewhale === 'undefined') { 10 window.livewhale = {}; 11} 12if (!livewhale.lib) livewhale.lib = {}; 13 14(function() { 15 var Timezone = function(timestamp, tz_offset) { 16 this._date = new Date((parseInt(timestamp, 10) * 1000) + (parseInt(tz_offset, 10) * 1000)); 17 this._formatter = new livewhale.lib.DateFormatter(this); 18 }; 19 20 // static methods and properties for gettting/setting time and date formats 21 Timezone.time_format = { 22 us: null, // livewhale.time_format_us, 23 euro: null // livewhale.time_format_euro 24 }; 25 Timezone.date_format = { 26 us: null, // livewhale.time_format_us, 27 euro: null // livewhale.time_format_euro 28 }; 29 Timezone.user_format_zone = 'us'; // default format zone 30 Timezone.setUserFormatZone = function(format_zone) { 31 Timezone.user_format_zone = format_zone; 32 }; 33 Timezone.getUserFormatZone = function() { 34 return Timezone.user_format_zone; 35 }; 36 Timezone.getUserTimeFormat = function() { 37 return (Timezone.time_format[Timezone.user_format_zone]) ? Timezone.time_format[Timezone.user_format_zone] : 'm/d/Y'; 38 }; 39 Timezone.getUserDateFormat = function() { 40 return (Timezone.date_format[Timezone.user_format_zone]) ? Timezone.date_format[Timezone.user_format_zone] : 'g:ia'; 41 }; 42 Timezone.prototype = { 43 month_names: [ 44 "January", "February", "March", "April", "May", "June",
45 "July", "August", "September", "October", "November", "December" 46 ], 47 month_names_short: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], 48 day_names: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'], 49 getFormattedDate: function(format) { 50 return this._formatter.format(format); 51 }, 52 getDateObject: function() { 53 return this._date; 54 }, 55 // uses user time format if no format zone param 56 getTimeString: function(format_zone) { 57 var format = (format_zone && Timezone.time_format[format_zone]) 58 ? Timezone.time_format[format_zone] 59 : Timezone.getUserTimeFormat(); 60 61 return this._formatter.format(format); 62 }, 63 // uses user date format if no format zone param 64 getShortDateString: function(format_zone) { 65 var format = (format_zone && Timezone.date_format[format_zone]) 66 ? Timezone.date_format[format_zone] 67 : Timezone.getUserDateFormat(); 68 69 return this._formatter.format(format); 70 }, 71 getDateTimeString: function() { 72 return this.month_names_short[ this._date.getUTCMonth() ] + ' ' 73 + this._date.getUTCDate() + ', ' 74 + this.getTimeString(); 75 }, 76 isDayStart: function() { 77 return (0 === this.getHours() && 0 === this.getMinutes()); 78 }, 79 // We use UTC because we've already made the 80 // offset adjustment for local time 81 getHours: function() { 82 return this._date.getUTCHours(); 83 }, 84 getMinutes: function() { 85 return this._date.getUTCMinutes(); 86 }, 87 getSeconds: function() { 88 return this._date.getUTCSeconds(); 89 }, 90 getMilliseconds: function() { 91 return this._date.getUTCMilliseconds(); 92 }, 93 getFullYear: function() { 94 return this._date.getUTCFullYear(); 95 }, 96 getMonth: function() { 97 return this._date.getUTCMonth(); 98 }, 99 getDate: function() { 100 return this._date.getUTCDate(); 101 }, 102 getDay: function() { 103 return this._date.getUTCDay(); 104 }, 105 getTime: function() { 106 return this._date.getTime(); 107 }, 108 setTimeToZero: function() { 109 this._date.setUTCHours(0); 110 this._date.setUTCMinutes(0); 111 this._date.setUTCSeconds(0); 112 } 113 }; 114 livewhale.lib.DateTimezone = Timezone; 115}());
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.