Skip to content

Commit

Permalink
-- work in progress --
Browse files Browse the repository at this point in the history
  * Added some zones to the period javascript.
  * Corrected a strange bug that cause negative times to not be
    returned as empty strings in the _TimeToSecond method.
  • Loading branch information
nzlosh committed Feb 17, 2013
1 parent 3a93d50 commit a3561c2
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 7 deletions.
32 changes: 30 additions & 2 deletions periods.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@
*/


function htmlLine(msg)
function htmlLine(msg, tag)
{
document.write("<p>",msg,"</p>");
if (tag == undefined)
{
tag = "p"
}
document.write("<"+tag+">",msg,"</"+tag+">");
}

function periods()
Expand Down Expand Up @@ -167,3 +171,27 @@ millisecond = msThisMinute % 1000;

htmlLine( hour +":"+ minute +":"+ second +":"+ millisecond);
htmlLine( (now.getTime() - msToday) / msPerYear );


/* Test Date object with tz data values" */
function tzDate(tz) {
d = new Date();

htmlLine(tz.area + "/" + tz.location , "h2");

htmlLine("UTC Time : " + d.getTime() + " is " + d.toUTCString() );

d.setTime( d.getTime() + (tz.gmt_off*1000) );
htmlLine(d.getTime() + " is " + d.toUTCString() + " with zone as " + tz.zone_format + " and refers to rule " + tz.rules);
}

tzDate(zones["Africa"]["Algiers"][0]);
tzDate(zones["Antarctica"]["Casey"][0]);
tzDate(zones["Asia"]["Kabul"][0]);
tzDate(zones["Australia"]["Darwin"][0]);
tzDate(zones["Europe"]["London"][0]);
/* 2 examples for America */
tzDate(zones["EST"]["null"][0]);
tzDate(zones["America"]["New_York"][0]);

tzDate(zones["America"]["Argentina/Buenos_Aires"][0]);
28 changes: 23 additions & 5 deletions tz2js.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def toJSON(self):

class TimeZoneBase(object):
def __init__(self):
pass
raise NotImplemented

def _TimeToSeconds(self, _time):
"""
Expand All @@ -101,15 +101,20 @@ def _TimeToSeconds(self, _time):
tmp = _time.split("-",1)
if len(tmp) == 2: # A 2 subscript array means a negative digit.
signed = -1
gmt_off = tmp[1]
_time = tmp[1]

logging.debug("Post sign treatment %s is a %s %s" % (_time, type(_time), signed) )

# Calculate time in seconds.
for x, v in enumerate(_time.split(":")):
offset_time += int(v) * time_factor[x]

logging.debug("Post time treatment %s is a %s and %s is a %s" % (offset_time, type(offset_time), signed, type(signed)) )

# Apply sign to conversion
logging.debug("\t == %s" % offset_time * signed)
return offset_time * signed
res = offset_time * signed # BUGFIX: negative numbers weren't
logging.debug("\t == %s" % res )
return res


class TimeZoneRule(TimeZoneBase):
Expand All @@ -124,7 +129,7 @@ def __init__(self, name, year_from, year_to, rule_type, month_in, day_on, time_a
self.setMonthIn(month_in) # day_on are used to calculate
self.setDayOn(day_on) # lastDay/firstDay entries correctly.
self.setTimeAt(time_at)
self.rule_type = rule_type
self.setRuleType(rule_type)
self.save = save
self.setLetters(letters)

Expand Down Expand Up @@ -186,6 +191,9 @@ def getMonthIn(self):


def setDayOn(self, day_on):
"""
TODO: Fix bugs in the function and verify the logic.
"""
# Initialise a temporary array with will hold the follow subscripts:
# [day of the week, comparrison operator, day of the month]
tmp = [None, None, None]
Expand Down Expand Up @@ -254,6 +262,16 @@ def getLetters(self):
return self.letters


def setRuleType(self, rule_type):
if rule_type == "-":
rule_type = None
self.rule_type = rule_type


def getRuleType(self, rule_type):
return self.rule_type


def __str__(self):
return "Rule: %s %s -> %s/%s/%s@%s Type: %s Save: %s Letter: %s" % (
self.name,
Expand Down

0 comments on commit a3561c2

Please sign in to comment.