Exemple #1
0
    def test_02(self):
        dt_now = datetime.now(pytz.utc)
        dt_from = dt_now - timedelta(seconds=60)
        dt_result = DatetimeTool.from_pivot_period2next(
            dt_from, dt_now, timedelta(days=1))

        self.assertEqual(dt_result, dt_from + timedelta(days=1))
Exemple #2
0
    def server2datetime_nanban(
        cls,
        server_codename,
        dt_pivot,
    ):
        server_doc = ServerDoc.codename2doc(server_codename)
        if not server_doc:
            return None

        nanban_prev = ServerDoc.doc2nanban(server_doc)
        nanban_datetime_prev = ServerNanban.nanban2datetime(nanban_prev)
        # dt_nanban_raw
        # utc_now = datetime.now(tz=pytz.utc)

        nanban_datetime_this = DatetimeTool.from_pivot_period2next(
            nanban_datetime_prev, dt_pivot, NanbanTimedelta.period())

        if nanban_datetime_this != nanban_datetime_prev:
            nanban = DictTool.filter(
                lambda k, v: v is not None, {
                    ServerNanban.Field.DATETIME:
                    nanban_datetime_this,
                    ServerNanban.Field.COMMAND_IN:
                    ServerNanban.nanban2command_in(nanban_prev),
                })
            doc = {
                ServerDoc.Field.CODENAME: server_codename,
                ServerDoc.Field.NANBAN: nanban,
            }
            ServerDoc.docs2upsert([doc])

        return nanban_datetime_this