def _before(
    datetime: UTCDateTime,
    event_function: Callable,
    location: LatLong = LatLong(0, 0)) -> UTCDateTime:
    if (event_function(datetime.year, location) - datetime).days < 0:
        return event_function(datetime.year, location)
    else:
        return event_function(datetime.year - 1, location)
def _after(
    datetime: UTCDateTime,
    event_function: Callable,
    location: LatLong = LatLong(0, 0)) -> UTCDateTime:
    if (event_function(datetime.year, location) - datetime).days >= 0:
        return event_function(datetime.year, location)
    else:
        return event_function(datetime.year + 1, location)
def march_equinox(year: int, location: LatLong = LatLong(0, 0)) -> UTCDateTime:
    return year_data(year).march_equinox
def winter_solstice_before(
    datetime: UTCDateTime, location: LatLong = LatLong(0, 0)) -> UTCDateTime:
    return _before(datetime, winter_solstice, location)
def fall_equinox_before(
    datetime: UTCDateTime, location: LatLong = LatLong(0, 0)) -> UTCDateTime:
    return _before(datetime, fall_equinox, location)
def summer_solstice_after(
    datetime: UTCDateTime, location: LatLong = LatLong(0, 0)) -> UTCDateTime:
    return _after(datetime, summer_solstice, location)
def spring_equinox_after(
    datetime: UTCDateTime, location: LatLong = LatLong(0, 0)) -> UTCDateTime:
    return _after(datetime, spring_equinox, location)
        self._calendar_properties = calendar_properties
        self._current_time = GardenDateTime(location, current_timestamp(),
                                            calendar_properties)
        self._year_start = self._current_time.year_start

    @property
    def current_time(self) -> GardenDateTime:
        if self._current_time is None:
            self._current_time = GardenDateTime(self.location,
                                                current_timestamp(),
                                                self._calendar_properties,
                                                _year_start=self._year_start)
            return self._current_time
        else:
            self._current_time.refresh()
            return self._current_time

    def run(self, refresh_time: float) -> None:
        print()
        while True:
            print(f'\r{self.current_time}', end='')
            sleep(refresh_time)


if __name__ == '__main__':
    calendar_properties = CalendarProperties('DS', es.december_solstice_before,
                                             0)
    print(calendar_properties)
    garden_clock = GardenClock(LatLong(34, -85), calendar_properties)
    garden_clock.run(0.432)
def december_solstice(
    year: int, location: LatLong = LatLong(0, 0)) -> UTCDateTime:
    return year_data(year).december_solstice
def winter_solstice(
    year: int, location: LatLong = LatLong(0, 0)) -> UTCDateTime:
    if location.lat >= 0:
        return december_solstice(year)
    else:
        return june_solstice(year)
def test_LatLong_init_long(init_long, after_long):
    assert LatLong(0, init_long).long == after_long
def test_LatLong_init_lat(init_lat, after_lat):
    assert LatLong(init_lat, 0).lat == after_lat
Esempio n. 13
0
        cp = CalendarProperties('FE-', es.fall_equinox_after, day_start_offset)
        clocks.append(GardenDateTime(self.location, current_timestamp(), cp))
        cp = CalendarProperties('WS-', es.winter_solstice_after, day_start_offset)
        clocks.append(GardenDateTime(self.location, current_timestamp(), cp))
        self.clocks = clocks

    def refresh_clocks(self) -> None:
        for clock in self.clocks:
            clock.refresh()
        self.clocks.sort()


    def run(self, refresh_time: float = 1) -> None:
        while True:
            self.refresh_clocks()
            for clock in self.clocks:
                print(f'{clock}')
            sleep(refresh_time)
            print('\033[F' * len(self.clocks), end='')



if __name__ == '__main__':
    from datetime import timezone, timedelta, datetime
    now = datetime.now(tz=timezone(timedelta(hours=-4)))
    partial_day = now.hour/24 + now.minute/(24*60) + now.second/(24*60*60)
    location = LatLong(34, -60)
    AllGardenClocks(location, -0.25).run(0.432)


def june_solstice(year: int, location: LatLong = LatLong(0, 0)) -> UTCDateTime:
    return year_data(year).june_solstice
def march_equinox_after(
    datetime: UTCDateTime, location: LatLong = LatLong(0, 0)) -> UTCDateTime:
    return _after(datetime, march_equinox, location)
def september_equinox(
    year: int, location: LatLong = LatLong(0, 0)) -> UTCDateTime:
    return year_data(year).september_equinox
def september_equinox_before(
    datetime: UTCDateTime, location: LatLong = LatLong(0, 0)) -> UTCDateTime:
    return _before(datetime, september_equinox, location)
def spring_equinox(
    year: int, location: LatLong = LatLong(0, 0)) -> UTCDateTime:
    if location.lat >= 0:
        return march_equinox(year)
    else:
        return september_equinox(year)
import pytest

from garden_calendar_time.utcdatetime import UTCDateTime
from garden_calendar_time.utcdatetime import UTCTime

from garden_calendar_time.location import LatLong
import garden_calendar_time.equinox_solstice as es

LOC1 = LatLong(45, 45)
LOC2 = LatLong(-45, -45)

location_data = [LOC1, LOC2]

YEAR1 = es.YearEquinoxSolsticData(2000,
                                  UTCDateTime(2000, 3, 20, 7, 35),
                                  UTCDateTime(2000, 6, 21, 1, 47),
                                  UTCDateTime(2000, 9, 22, 17, 27),
                                  UTCDateTime(2000, 12, 21, 13, 37))

YEAR2 = es.YearEquinoxSolsticData(2001,
                                  UTCDateTime(2001, 3, 20, 13, 30),
                                  UTCDateTime(2001, 6, 21, 7, 37),
                                  UTCDateTime(2001, 9, 22, 23, 4),
                                  UTCDateTime(2001, 12, 21, 19, 21))


YEAR3 = es.YearEquinoxSolsticData(2002,
                                  UTCDateTime(2002, 3, 20, 19, 16),
                                  UTCDateTime(2002, 6, 21, 13, 24),
                                  UTCDateTime(2002, 9, 23, 4, 55),
                                  UTCDateTime(2002, 12, 22, 1, 14))