OpenLayers OpenLayers

Changeset 6328

Show
Ignore:
Timestamp:
02/20/08 12:01:07 (11 months ago)
Author:
achipa
Message:

WiP

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/achipa/openlayers/lib/OpenLayers/BaseTypes/DateTime.js

    r6310 r6328  
    77 * 
    88 */ 
    9 OpenLayers.DateTime = OpenLayers.Class({ 
    10  
    11     /** 
    12      * Property: from 
    13      * {Number} 
    14      */ 
    15     from: new Date(), 
     9OpenLayers.DateTime = OpenLayers.Class(Date, { 
    1610 
    1711    /** 
     
    1913     * {Number} 
    2014     */ 
    21     to: new Date(), 
    22  
    23     /** 
    24      * Property: interval 
    25      * {Number} 
    26      */ 
    27     interval: true, 
     15    to: null, 
    2816 
    2917    /** 
     
    3826     * 
    3927     * 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. 
    4631     */ 
    4732    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)); 
    5033        if (begin != null) { 
    51             this.from = begin
     34            this.prototype.setTime(begin)
    5235        } 
    5336        if (end != null) { 
     
    6548 
    6649    /** 
    67      * Method: setDateTime 
     50     * Method: setTime 
    6851     * Set time 
    6952     * 
    7053     */ 
    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; 
    7560    }, 
    7661 
    7762    /** 
    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 
    9664     * Set time 
    9765     * 
    9866     */ 
    9967    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; 
    10878        } 
    10979    }, 
     
    11585     */ 
    11686    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 
    11889                return true; 
    11990 
     
    130101            if (targetdate > this.to) 
    131102        return 1; 
    132             else if (targetdate <= this.from) // using <= to accomodate for non-interval datetimes 
     103            else if (targetdate <= this) // using <= to accomodate for non-interval datetimes 
    133104                return 0; 
    134105 
    135         return (targetdate - this.from) / (this.to - this.from) ; 
     106        return (targetdate - this) / (this.to - this) ; 
    136107        } 
    137108        return -1; 
     
    141112        if (this.from == dateTime.from && this.to == dateTime.to) return true; 
    142113        return false; 
     114    }, 
     115 
     116    isInterval: function() { 
     117        if (to) 
     118        return true; 
     119     
     120    return false; 
    143121    }, 
    144122