コード例 #1
0
    def test_spring_forward(self):
        d = datetime.date(2015,3,29)
        t = datetime.time(0,55)

        assert(timezone_for_date_and_time(d,t) == pytz.timezone("Etc/GMT"))

        d = datetime.date(2015,3,29)
        t = datetime.time(2,5)

        assert(timezone_for_date_and_time(d,t) == pytz.timezone("Etc/GMT-1"))
コード例 #2
0
    def test_uncontroversial_times(self):
        d = datetime.date(2015,1,5)
        t = datetime.time(18,30)

        assert(timezone_for_date_and_time(d,t) == pytz.timezone("Etc/GMT"))

        d = datetime.date(2015,6,5)
        t = datetime.time(21,00)

        assert(timezone_for_date_and_time(d,t) == pytz.timezone("Etc/GMT-1"))
コード例 #3
0
    def test_fall_back(self):
        d = datetime.date(2015,10,25)
        t = datetime.time(0,30)

        assert(timezone_for_date_and_time(d,t) == pytz.timezone("Etc/GMT-1"))

        d = datetime.date(2015,10,25)
        t = datetime.time(1,15)

        assert(timezone_for_date_and_time(d,t) == pytz.timezone("Etc/GMT"))

        d = datetime.date(2015,10,25)
        t = datetime.time(2,10)

        assert(timezone_for_date_and_time(d,t) == pytz.timezone("Etc/GMT"))
コード例 #4
0
    def build(raw, containing_message, xml):
        m = ScheduleMessage()

        m.uid = raw.uid
        m.rid = raw.rid
        m.headcode = raw.trainId
        m.start_date = raw.ssd.date()
        m.toc_code = raw.toc
        m.passenger_service = bool(raw.isPassengerSvc)
        m.status = raw.status
        m.category = raw.trainCat
        m.active = bool(raw.isActive)
        m.deleted = bool(raw.deleted)
        try:
            m.charter = bool(raw.charter)
        except AttributeError:
            m.charter = False
        if raw.cancelReason is not None:
            m.cancel_reason_code = raw.cancelReason.value()
            m.cancel_reason_tiploc = raw.cancelReason.tiploc
            m.cancel_reason_near = bool(raw.cancelReason.near)
        else:
            m.cancel_reason_code = None
            m.cancel_reason_tiploc = None
            m.cancel_reason_near = None

        # Loop through all the points in the order they appear in the XML, instantiate the
        # appropriate object for them, and add them to the appropriate list.
        m.origins = []
        m.operational_origins = []
        m.intermediate_points = []
        m.operational_intermediate_points = []
        m.passing_points = []
        m.destinations = []
        m.operational_destinations = []
        m.all_points = []

        for r in raw.orderedContent():
            v = r.value
            if type(v) == DisruptionReasonType:
                pass
            elif type(v) == OR:
                p = f.build_point(v, Origin)
                m.origins.append(p)
            elif type(v) == OPOR:
                p = f.build_point(v, OperationalOrigin)
                m.operational_origins.append(p)
            elif type(v) == IP:
                p = f.build_point(v, IntermediatePoint)
                m.intermediate_points.append(p)
            elif type(v) == OPIP:
                p = f.build_point(v, OperationalIntermediatePoint)
                m.operational_intermediate_points.append(p)
            elif type(v) == PP:
                p = f.build_point(v, PassingPoint)
                m.passing_points.append(p)
            elif type(v) == DT:
                p = f.build_point(v, Destination)
                m.destinations.append(p)
            elif type(v) == OPDT:
                p = f.build_point(v, OperationalDestination)
                m.operational_destinations.append(p)
            else:
                raise Exception("Type of point is {}.".format(type(v)))

            m.all_points.append(p)

        first_point = m.all_points[0]
        if first_point.raw_working_arrival_time is not None:
            t = first_point.raw_working_arrival_time
        elif first_point.raw_working_pass_time is not None:
            t = first_point.raw_working_pass_time
        elif first_point.raw_working_departure_time is not None:
            t = first_point.raw_working_departure_time
        else:
            raise Exception()

        tz = timezone_for_date_and_time(m.start_date, t)

        day_incrementor = 0
        o = None
        for p in m.all_points:
            day_incrementor = f.build_times(day_incrementor, o, p, m.start_date, tz)
            o = p

        m._raw = raw
        m._containing_message = containing_message
        m._xml = xml

        return m