Changeset 6328
- Timestamp:
- 02/20/08 12:01:07 (11 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
sandbox/achipa/openlayers/lib/OpenLayers/BaseTypes/DateTime.js
r6310 r6328 7 7 * 8 8 */ 9 OpenLayers.DateTime = OpenLayers.Class({ 10 11 /** 12 * Property: from 13 * {Number} 14 */ 15 from: new Date(), 9 OpenLayers.DateTime = OpenLayers.Class(Date, { 16 10 17 11 /** … … 19 13 * {Number} 20 14 */ 21 to: new Date(), 22 23 /** 24 * Property: interval 25 * {Number} 26 */ 27 interval: true, 15 to: null, 28 16 29 17 /** … … 38 26 * 39 27 * Parameters: 40 * left - {Number} The left bounds of the box. Note that for width 41 * calculations, this is assumed to be less than the right value. 42 * bottom - {Number} The bottom bounds of the box. Note that for height 43 * calculations, this is assumed to be more than the top value. 44 * right - {Number} The right bounds. 45 * top - {Number} The top bounds. 28 * begin - {Date} The start bounds. 29 * end - {Date} The end bounds. 30 * zone - {String} Time zone. 46 31 */ 47 32 initialize: function(begin, end, zone) { 48 this.from.setTime(Date.UTC(1970,1,1));49 this.to.setTime(Date.UTC(2038,1,19,3,14,7));50 33 if (begin != null) { 51 this. from = begin;34 this.prototype.setTime(begin); 52 35 } 53 36 if (end != null) { … … 65 48 66 49 /** 67 * Method: set DateTime50 * Method: setTime 68 51 * Set time 69 52 * 70 53 */ 71 setDateTime:function(targetdate) { 72 this.setBegin(targetdate); 73 this.setEnd(targetdate); 74 this.interval = false; 54 setTime:function(targetdate) { 55 this.prototype.setTime(targetdate.getTime()); 56 if (targetdate.isInterval()) 57 this.setEnd(targetdate.to); 58 else 59 this.to = null; 75 60 }, 76 61 77 62 /** 78 * Method: setDateTime 79 * Set time 80 * 81 */ 82 setBegin:function(targetdate) { 83 if (typeof targetdate == "Date") { 84 if (targetdate >= end) { // we got them swapped 85 this.to = targetdate; 86 this.from = targetdate; 87 this.interval = false; 88 } else { 89 this.from = targetdate; 90 } 91 } 92 }, 93 94 /** 95 * Method: setDateTime 63 * Method: setEnd 96 64 * Set time 97 65 * 98 66 */ 99 67 setEnd:function(targetdate) { 100 if (typeof targetdate == "Date") { 101 if (targetdate <= from) { // we got them swapped 102 this.to = targetdate; 103 this.from = targetdate; 104 this.interval = false; 105 } else { 106 this.to = targetdate; 107 } 68 if (targetdate.isInterval()) 69 this.to = new Date(targetdate.to); 70 else 71 this.to = new Date(targetdate); 72 73 if (this > this.to) { // we got them swapped 74 this.tmp = this.to.getTime(); 75 this.to.setTime(this.getTime()); 76 this.prototype.setTime(this.tmp); 77 delete this.tmp; 108 78 } 109 79 }, … … 115 85 */ 116 86 contains:function(targetdate) { 117 if (targetdate >= this.from && targetdate <= this.to) 87 if (targetdate >= this && targetdate <= this.to && // start date within range 88 (!targetdate.isInterval()) || (targetdate.to >= this && targetdate.to <= this.to)) // and both dates in range if it's an interval 118 89 return true; 119 90 … … 130 101 if (targetdate > this.to) 131 102 return 1; 132 else if (targetdate <= this .from) // using <= to accomodate for non-interval datetimes103 else if (targetdate <= this) // using <= to accomodate for non-interval datetimes 133 104 return 0; 134 105 135 return (targetdate - this .from) / (this.to - this.from) ;106 return (targetdate - this) / (this.to - this) ; 136 107 } 137 108 return -1; … … 141 112 if (this.from == dateTime.from && this.to == dateTime.to) return true; 142 113 return false; 114 }, 115 116 isInterval: function() { 117 if (to) 118 return true; 119 120 return false; 143 121 }, 144 122
