Пример #1
0
def now(text):
    _n = datetime.now()
    print("t :", text)
    if 'พรุ่งนี้' in text:
        text = "วันพรุ่งนี้เป็น" + thai_strftime(_n + timedelta(days=1),
                                                 "%A %d %B %Y ") + "ค่ะ"
    elif "วัน" in text and "เวลา" in text:
        text = "วันนี้" + thai_strftime(
            _n, "%A %d %B %Y ") + "เวลา " + thai_time(
                str(_n.strftime('%H:%M')), "6h") + "ค่ะ"
    elif "วัน" in text:
        text = "วันนี้" + thai_strftime(_n, "%A %d %B %Y ") + "ค่ะ"
    elif 'เวลา' in text or 'เพลา' in text or 'โมง' in text:
        text = "ขณะนี้เวลา " + thai_time(str(_n.strftime('%H:%M')),
                                         "6h") + "ค่ะ"  #นาฬิกา
    else:
        text = "ระบบบอกเวลา ยังไม่รองรับคำสั่งนี้ค่ะ"
    return text
Пример #2
0
    def test_time_to_thaiword(self):
        self.assertEqual(time_to_thaiword("8:17"), time_to_thaiword("08:17"))
        self.assertEqual(time_to_thaiword("8:17"), "แปดนาฬิกาสิบเจ็ดนาที")
        self.assertEqual(time_to_thaiword("8:17", "6h"),
                         "สองโมงเช้าสิบเจ็ดนาที")
        self.assertEqual(time_to_thaiword("8:17", "m6h"), "แปดโมงสิบเจ็ดนาที")
        self.assertEqual(time_to_thaiword("13:30:01", "6h", "m"),
                         "บ่ายโมงครึ่ง")
        self.assertEqual(time_to_thaiword(time(12, 3, 0)),
                         "สิบสองนาฬิกาสามนาที")
        self.assertEqual(
            time_to_thaiword(time(12, 3, 1)),
            "สิบสองนาฬิกาสามนาทีหนึ่งวินาที",
        )
        self.assertEqual(
            time_to_thaiword(datetime(2014, 5, 22, 12, 3, 0), precision="s"),
            "สิบสองนาฬิกาสามนาทีศูนย์วินาที",
        )
        self.assertEqual(
            time_to_thaiword(datetime(2014, 5, 22, 12, 3, 1), precision="m"),
            "สิบสองนาฬิกาสามนาที",
        )
        self.assertEqual(
            time_to_thaiword(datetime(1976, 10, 6, 12, 30, 1), "6h", "m"),
            "เที่ยงครึ่ง",
        )
        self.assertEqual(time_to_thaiword("18:30"), "สิบแปดนาฬิกาสามสิบนาที")
        self.assertEqual(time_to_thaiword("18:30:00"),
                         "สิบแปดนาฬิกาสามสิบนาที")
        self.assertEqual(time_to_thaiword("18:30:01"),
                         "สิบแปดนาฬิกาสามสิบนาทีหนึ่งวินาที")
        self.assertEqual(
            time_to_thaiword("18:30:01", precision="m"),
            "สิบแปดนาฬิกาสามสิบนาที",
        )
        self.assertEqual(
            time_to_thaiword("18:30:01", precision="s"),
            "สิบแปดนาฬิกาสามสิบนาทีหนึ่งวินาที",
        )
        self.assertEqual(
            time_to_thaiword("18:30:01", fmt="m6h", precision="m"),
            "หกโมงครึ่ง",
        )
        self.assertEqual(
            time_to_thaiword("18:30:01", fmt="m6h"),
            "หกโมงสามสิบนาทีหนึ่งวินาที",
        )
        self.assertEqual(
            time_to_thaiword("18:30:01", fmt="m6h", precision="m"),
            "หกโมงครึ่ง",
        )
        self.assertIsNotNone(time_to_thaiword("0:30"))
        self.assertIsNotNone(time_to_thaiword("0:30", "6h"))
        self.assertIsNotNone(time_to_thaiword("0:30", "m6h"))
        self.assertIsNotNone(time_to_thaiword("4:30"))
        self.assertIsNotNone(time_to_thaiword("4:30", "6h"))
        self.assertIsNotNone(time_to_thaiword("4:30", "m6h"))
        self.assertIsNotNone(time_to_thaiword("12:30"))
        self.assertIsNotNone(time_to_thaiword("12:30", "6h"))
        self.assertIsNotNone(time_to_thaiword("12:30", "m6h"))
        self.assertIsNotNone(time_to_thaiword("13:30"))
        self.assertIsNotNone(time_to_thaiword("13:30", "6h"))
        self.assertIsNotNone(time_to_thaiword("13:30", "m6h"))
        self.assertIsNotNone(time_to_thaiword("15:30"))
        self.assertIsNotNone(time_to_thaiword("15:30", "6h"))
        self.assertIsNotNone(time_to_thaiword("15:30", "m6h"))
        self.assertIsNotNone(time_to_thaiword("18:30"))
        self.assertIsNotNone(time_to_thaiword("18:30", "6h"))
        self.assertIsNotNone(time_to_thaiword("18:30", "m6h"))
        self.assertIsNotNone(time_to_thaiword("19:30"))
        self.assertIsNotNone(time_to_thaiword("19:30", "6h"))
        self.assertIsNotNone(time_to_thaiword("19:30", "m6h"))

        with self.assertRaises(NotImplementedError):
            time_to_thaiword("8:17",
                             fmt="xx")  # format string is not supported
        with self.assertRaises(TypeError):
            time_to_thaiword(42)  # input is not datetime/time/str
        with self.assertRaises(ValueError):
            time_to_thaiword("")  # input is empty
        with self.assertRaises(ValueError):
            time_to_thaiword("13:73:23")  # input is not in H:M:S format
        with self.assertRaises(ValueError):
            time_to_thaiword(
                "24:00")  # input is not in H:M:S format (over 23:59:59)

        self.assertEqual(thai_time("11:12"), time_to_thaiword("11:12"))
        with self.assertWarns(DeprecationWarning):
            thai_time("11:16")
Пример #3
0
    def test_thai_time(self):
        self.assertEqual(thai_time("8:17"), thai_time("08:17"))
        self.assertEqual(thai_time("8:17"), "แปดนาฬิกาสิบเจ็ดนาที")
        self.assertEqual(thai_time("8:17", "6h"), "สองโมงเช้าสิบเจ็ดนาที")
        self.assertEqual(thai_time("8:17", "m6h"), "แปดโมงสิบเจ็ดนาที")
        self.assertEqual(thai_time("13:30:01", "6h", "m"), "บ่ายโมงครึ่ง")
        self.assertEqual(
            thai_time(datetime.time(12, 3, 0)), "สิบสองนาฬิกาสามนาที"
        )
        self.assertEqual(
            thai_time(datetime.time(12, 3, 1)),
            "สิบสองนาฬิกาสามนาทีหนึ่งวินาที",
        )
        self.assertEqual(
            thai_time(datetime.datetime(2014, 5, 22, 12, 3, 0), precision="s"),
            "สิบสองนาฬิกาสามนาทีศูนย์วินาที",
        )
        self.assertEqual(
            thai_time(datetime.datetime(2014, 5, 22, 12, 3, 1), precision="m"),
            "สิบสองนาฬิกาสามนาที",
        )
        self.assertEqual(
            thai_time(datetime.datetime(1976, 10, 6, 12, 30, 1), "6h", "m"),
            "เที่ยงครึ่ง",
        )
        self.assertEqual(thai_time("18:30"), "สิบแปดนาฬิกาสามสิบนาที")
        self.assertEqual(thai_time("18:30:00"), "สิบแปดนาฬิกาสามสิบนาที")
        self.assertEqual(
            thai_time("18:30:01"), "สิบแปดนาฬิกาสามสิบนาทีหนึ่งวินาที"
        )
        self.assertEqual(
            thai_time("18:30:01", precision="m"), "สิบแปดนาฬิกาสามสิบนาที"
        )
        self.assertEqual(
            thai_time("18:30:01", precision="s"),
            "สิบแปดนาฬิกาสามสิบนาทีหนึ่งวินาที",
        )
        self.assertEqual(
            thai_time("18:30:01", fmt="m6h", precision="m"), "หกโมงครึ่ง"
        )
        self.assertEqual(
            thai_time("18:30:01", fmt="m6h"), "หกโมงสามสิบนาทีหนึ่งวินาที"
        )
        self.assertEqual(
            thai_time("18:30:01", fmt="m6h", precision="m"), "หกโมงครึ่ง"
        )
        self.assertIsNotNone(thai_time("0:30"))
        self.assertIsNotNone(thai_time("0:30", "6h"))
        self.assertIsNotNone(thai_time("0:30", "m6h"))
        self.assertIsNotNone(thai_time("4:30"))
        self.assertIsNotNone(thai_time("4:30", "6h"))
        self.assertIsNotNone(thai_time("4:30", "m6h"))
        self.assertIsNotNone(thai_time("12:30"))
        self.assertIsNotNone(thai_time("12:30", "6h"))
        self.assertIsNotNone(thai_time("12:30", "m6h"))
        self.assertIsNotNone(thai_time("13:30"))
        self.assertIsNotNone(thai_time("13:30", "6h"))
        self.assertIsNotNone(thai_time("13:30", "m6h"))
        self.assertIsNotNone(thai_time("15:30"))
        self.assertIsNotNone(thai_time("15:30", "6h"))
        self.assertIsNotNone(thai_time("15:30", "m6h"))
        self.assertIsNotNone(thai_time("18:30"))
        self.assertIsNotNone(thai_time("18:30", "6h"))
        self.assertIsNotNone(thai_time("18:30", "m6h"))
        self.assertIsNotNone(thai_time("19:30"))
        self.assertIsNotNone(thai_time("19:30", "6h"))
        self.assertIsNotNone(thai_time("19:30", "m6h"))

        with self.assertRaises(NotImplementedError):
            thai_time("8:17", fmt="xx")