PonteIneptique / simile-widgets

Automatically exported from code.google.com/p/simile-widgets
0 stars 0 forks source link

TIMELINE. time zone in event popup bubble is incorrect #176

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I initialized my timeline bands to my local time zone, and the times in the
event data use my local time zone, and the times shown in the event popup
bubbles are correct but they always show GMT as the time zone. IE:

<event start="Mar 15 2007 15:02:00 CDT" end="Mar 15 2007 15:02:00 CDT"
isDuration="false" title="Actual Start Time">ACTUAL_START</event>

In the popup bubble will show Mar 15 2007 15:02:00 GMT.

firefox 2.0.0.3, mac osx 

[Submitted by Alex McCarrier on simile.mit.edu]

Ben Ostrowsky - 23/Apr/07 11:53 AM
We're having the same problem too. Our event source is JSON, and our time
information looks like this:
      "start" : "2004-10-29T09:00:00-0400",
      "end" : "2004-10-29T16:00:00-0400"

[ Show » ]
Ben Ostrowsky - 23/Apr/07 11:53 AM We're having the same problem too. Our
event source is JSON, and our time information looks like this:      
"start" : "2004-10-29T09:00:00-0400",       "end" : "2004-10-29T16:00:00-0400"

[ Permlink | « Hide ]
Frank Spangenberg - 24/Sep/07 08:46 AM
Was someone able to fix this?
[ Show » ]
Frank Spangenberg - 24/Sep/07 08:46 AM Was someone able to fix this?

[ Permlink | « Hide ]
David F. Huynh - 24/Sep/07 01:46 PM
I will try to fix it in version 2.0. For the time being, please try to add
this script after you include timeline-api.js:

<script>
Timeline.DefaultEventSource.Event.prototype.fillTime = function(elmt,
labeller) {
        if (this._instant) {
            if (this.isImprecise()) {

elmt.appendChild(elmt.ownerDocument.createTextNode(this.getProperty("start")));
                elmt.appendChild(elmt.ownerDocument.createElement("br"));

elmt.appendChild(elmt.ownerDocument.createTextNode(this.getProperty("end")));
            } else {

elmt.appendChild(elmt.ownerDocument.createTextNode(this.getProperty("start")));
            }
        } else {
            if (this.isImprecise()) {
                elmt.appendChild(elmt.ownerDocument.createTextNode(
                    this.getProperty("start") + " ~ " +
this.getProperty("latestStart")));
                elmt.appendChild(elmt.ownerDocument.createElement("br"));
                elmt.appendChild(elmt.ownerDocument.createTextNode(
                    this.getProperty("earliestEnd") + " ~ " +
this.getProperty("end")));
            } else {

elmt.appendChild(elmt.ownerDocument.createTextNode(this.getProperty("start")));
                elmt.appendChild(elmt.ownerDocument.createElement("br"));

elmt.appendChild(elmt.ownerDocument.createTextNode(this.getProperty("end")));
            }
        }
    };
</script>

Let me know if that helps.
[ Show » ]
David F. Huynh - 24/Sep/07 01:46 PM I will try to fix it in version 2.0.
For the time being, please try to add this script after you include
timeline-api.js: <script>
Timeline.DefaultEventSource.Event.prototype.fillTime = function(elmt,
labeller) {         if (this._instant) {             if
(this.isImprecise()) {                
elmt.appendChild(elmt.ownerDocument.createTextNode(this.getProperty("start")));
                elmt.appendChild(elmt.ownerDocument.createElement("br")); 

elmt.appendChild(elmt.ownerDocument.createTextNode(this.getProperty("end")));
            } else {                
elmt.appendChild(elmt.ownerDocument.createTextNode(this.getProperty("start")));
            }         } else {             if (this.isImprecise()) {      
          elmt.appendChild(elmt.ownerDocument.createTextNode(             
       this.getProperty("start") + " ~ " +
this.getProperty("latestStart")));                
elmt.appendChild(elmt.ownerDocument.createElement("br"));                
elmt.appendChild(elmt.ownerDocument.createTextNode(                    
this.getProperty("earliestEnd") + " ~ " + this.getProperty("end")));      
      } else {                
elmt.appendChild(elmt.ownerDocument.createTextNode(this.getProperty("start")));
                elmt.appendChild(elmt.ownerDocument.createElement("br")); 

elmt.appendChild(elmt.ownerDocument.createTextNode(this.getProperty("end")));
            }         }     }; </script> Let me know if that helps.

[ Permlink | « Hide ]
Frank Spangenberg - 25/Sep/07 02:57 AM
Thank you for your fast response and the fix!
It helps very well!
[ Show » ]
Frank Spangenberg - 25/Sep/07 02:57 AM Thank you for your fast response and
the fix! It helps very well!

[ Permlink | « Hide ]
Oleg Krapilsky - 29/Oct/07 05:19 PM
I made the following changes to date-time.js and labellers.js; now,
setIso8601Time() makes use of time zone information present in ISO
timestamps instead of discarding it, labelPrecise() displays GMT offset,
and parseGregorianDateTime() no longer defaults to your local time zone
when dealing with timestamps without any time zone info.

<pre>
&lt;script&gt;

Timeline.DateTime.setIso8601Time = function (dateObject, string) {
    var timezone = "Z|(([-+])([0-9]{2})(:?([0-9]{2}))?)$";
    var d = string.match(new RegExp(timezone));

    var offset = 0;
    if (d) {
        if (d[0] != 'Z') {
            offset = (Number(d[3]) * 60) + Number(d[5]);
            offset *= ((d[2] == '-') ? 1 : -1);
        }
        string = string.substr(0, string.length - d[0].length);
    }

    var regexp = "^([0-9]{2})(:?([0-9]{2})(:?([0-9]{2})(\.([0-9]+))?)?)?$";
    var d = string.match(new RegExp(regexp));
    if(!d) {
        dojo.debug("invalid time string: " + string);
        return false;
    }
    var hours = d[1];
    var mins = Number((d[3]) ? d[3] : 0);
    var secs = (d[5]) ? d[5] : 0;
    var ms = d[7] ? (Number("0." + d[7]) * 1000) : 0;

    dateObject.setUTCHours(hours);
    dateObject.setUTCMinutes(mins);
    dateObject.setUTCSeconds(secs);
    dateObject.setUTCMilliseconds(ms);

    // This part was missing from dojo prior to v0.4.3, causing all sorts
of trouble.

    if (offset !== 0) {
        dateObject.setTime(dateObject.getTime() + offset * 60000);
    }

    return dateObject;
};

Timeline.GregorianDateLabeller.prototype.labelPrecise = function(date) {
    return ((Timeline.DateTime.removeTimeZoneOffset(
        date,
        this._timeZone
    ).toUTCString()) + (this._timeZone < 0 ? "" : "+" ) + this._timeZone);
};

Timeline.DateTime.parseGregorianDateTime = function(o) {
    if (o == null) {
        return null;
    } else if (o instanceof Date) {
        return o;
    }

    var s = o.toString();
    if (s.length > 0 && s.length < 8) {
        var space = s.indexOf(" ");
        if (space > 0) {
            var year = parseInt(s.substr(0, space));
            var suffix = s.substr(space + 1);
            if (suffix.toLowerCase() == "bc") {
                year = 1 - year;
            }
        } else {
            var year = parseInt(s);
        }

        var d = new Date(0);
        d.setUTCFullYear(year);

        return d;
    }

    // I miss in_array() so much.

    var appendGMT0 = true;
    var timeZoneCodes = ["GMT", "UTC", "PST", "MST", "CST", "EST"];
    for (var i = 0; i < timeZoneCodes.length; i++) {
     if((s.match(timeZoneCodes[i])) != null) {
     appendGMT0 = false;
     break;
     }
    }

    if (appendGMT0 == true)
     s = s + " GMT+0000";

    try {
        return new Date(Date.parse(s));
    } catch (e) {
        return null;
    }
};

&lt;/script&gt;
</pre>

Original issue reported on code.google.com by GabrielR...@googlemail.com on 7 Apr 2009 at 7:31

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I modified the code to get the events from sharepoint list instead of from an 
xml
file.  The code shown above didn't work for me. The date time in the event popup
bubble said "GMT" or "UTC" depending on the browser.  So I came up with this
workaround: Add the following code right after I include the timeline-api.js.  
The
date in the event popup bubble would then be in locale convention.  You can use
.toLocaleString() instead if you want to show both date and time. 

<script>    
    // To change .ToUTCString() to .ToLocaleDateString() so the date time would be in
locale convention.
    Timeline.GregorianDateLabeller.prototype.labelPrecise = function(date) {
        return SimileAjax.DateTime.removeTimeZoneOffset(
            date, 
            this._timeZone //+ (new Date().getTimezoneOffset() / 60)
        ).toLocaleDateString();
    };
</script> 

Original comment by lo.cori...@gmail.com on 2 Feb 2010 at 6:32