Example #1
0
def test_hours_difference():
    function_result_1 = a1.hours_difference(1800.0, 3600.0)
    function_result_2 = a1.hours_difference(3600.0, 1800.0)
    function_result_3 = a1.hours_difference(1800.0, 2160.0)
    function_result_4 = a1.hours_difference(1800.0, 1800.0)
    assert type(function_result_1) is float
    assert function_result_1 == 0.5
    assert function_result_2 == -0.5
    assert function_result_3 == 0.1
    assert function_result_4 == 0.0
    def __init__(self, tk, zone=None, **kargs):
        '''A 200x200 pixel clock in a particular time zone. tk is the tkiner
        instance; kargs contains the x and y location of the clock in the main
        window.'''

        self.width = 200
        self.height = 200
        self.internal_frame = tkinter.Frame(tk,
                                            borderwidth=3,
                                            relief=tkinter.GROOVE)

        self.canvas = tkinter.Canvas(self.internal_frame,
                                     width=self.width,
                                     height=self.height)
        self.canvas.grid()

        self.canvas.after(300, self.refresh)

        if time.daylight:
            dlt = time.altzone
        else:
            dlt = time.timezone

        self.diff = a1.hours_difference(dlt, 0)

        self.local_offset = self.diff
        self.now = time.time()  # Allow fast-forwarding
        self.interval = 500

        self.var = tkinter.StringVar(self.internal_frame)
        self.var.set('local')
        option = tkinter.OptionMenu(self.internal_frame, self.var, *REAL_ZONES)
        option.grid(sticky='ew')
        self.internal_frame.grid(**kargs)
        self.time_scale = 1

        def callback(*args):
            if self.var.get() == 'local':
                self.diff = self.local_offset
            else:
                try:
                    self.diff = float(self.var.get()[3:])
                except:
                    self.diff = 0

        self.var.trace("w", callback)
        self.var.set(zone)
    def __init__(self, tk, zone=None, **kargs):
        '''A 200x200 pixel clock in a particular time zone. tk is the tkiner
        instance; kargs contains the x and y location of the clock in the main
        window.'''

        self.width = 200
        self.height = 200
        self.internal_frame = Tkinter.Frame(
            tk, borderwidth=3, relief=Tkinter.GROOVE)

        self.canvas = Tkinter.Canvas(
            self.internal_frame, width=self.width, height=self.height)
        self.canvas.grid()

        self.canvas.after(300, self.refresh)

        if time.daylight:
            dlt = time.altzone
        else:
            dlt = time.timezone

        self.diff = a1.hours_difference(dlt, 0)

        self.local_offset = self.diff
        self.now = time.time()          # Allow fast-forwarding
        self.interval = 500

        self.var = Tkinter.StringVar(self.internal_frame)
        self.var.set('local')
        option = Tkinter.OptionMenu(self.internal_frame, self.var, *REAL_ZONES)
        option.grid(sticky='ew')
        self.internal_frame.grid(**kargs)
        self.time_scale = 1

        def callback(*args):
            if self.var.get() == 'local':
                self.diff = self.local_offset
            else:
                try:
                    self.diff = float(self.var.get()[3:])
                except:
                    self.diff = 0

        self.var.trace("w", callback)
        self.var.set(zone)
Example #4
0
 def test_hours_difference(self):
     self.assertEqual(a1.hours_difference(1800.0, 3600.0), 0.5)
     self.assertEqual(a1.hours_difference(3600.0, 1800.0), -0.5)
     self.assertEqual(a1.hours_difference(1800.0, 2160.0), 0.1)
     self.assertEqual(a1.hours_difference(1800.0, 1800.0), 0.0)
Example #5
0
import a1

print(a1.seconds_difference(1800.0, 3600.0))
print(a1.seconds_difference(3600.0, 1800.0))
print(a1.seconds_difference(1800.0, 2160.0))
print(a1.seconds_difference(1800.0, 1800.0))

print(a1.hours_difference(1800.0, 3600.0))
print(a1.hours_difference(3600.0, 1800.0))
print(a1.hours_difference(1800.0, 2160.0))
print(a1.hours_difference(1800.0, 1800.0))

print(a1.to_float_hours(0, 15, 0))
print(a1.to_float_hours(2, 45, 9))
print(a1.to_float_hours(1, 0, 36))

print(a1.get_hours(3800))
print(a1.get_minutes(3800))
print(a1.get_seconds(3800))

print(a1.time_to_utc(+0.5, 12.0))
print(a1.time_to_utc(+1, 12.0))
print(a1.time_to_utc(-1, 12.0))
print(a1.time_to_utc(-11, 18.0))
print(a1.time_to_utc(-1, 0.0))
print(a1.time_to_utc(-1, 23.0))
# ^ last test in time_to_utc