Exemplo n.º 1
0
    def dump_alarms(self, tag=""):
        # Useful when debugging
        dump = "\n" + "="*30 + " ALARMS " + tag + " " + "="*30 + "\n"
        dump += "raw = " + str(self.settings["alarm"]) + "\n\n"

        now_ts = to_utc(now_utc()).timestamp()
        dt = datetime.fromtimestamp(now_ts)
        dump += "now = {} ({})\n".format(
            nice_time(self.get_alarm_local(timestamp=now_ts),
                      speech=False, use_ampm=not self.use_24hour, use_24hour = self.use_24hour),
            now_ts)
        dump += "      U{} L{}\n".format(to_utc(dt), to_local(dt))
        dump += "\n\n"

        idx = 0
        for alarm in self.settings["alarm"]:
            dt = self.get_alarm_local(alarm)
            dump += "alarm[{}] - {} \n".format(idx, alarm)
            dump += "           Next: {} {}\n".format(
                nice_time(dt, speech=False, use_ampm= not self.use_24hour, use_24hour = self.use_24hour),
                nice_date(dt, now=now_local()))
            dump += "                 U{} L{}\n".format(dt, to_local(dt))
            if 'snooze' in alarm:
                dtOrig = self.get_alarm_local(timestamp=alarm['snooze'])
                dump += "           Orig: {} {}\n".format(
                    nice_time(dtOrig, speech=False, use_ampm= not self.use_24hour, use_24hour = self.use_24hour),
                    nice_date(dtOrig, now=now_local()))
            idx += 1

        dump += "="*75

        self.log.info(dump)
Exemplo n.º 2
0
    def test_minutes_past_hour(self):
        # "quarter past ten"
        dt = datetime.datetime(2017, 1, 31, 1, 15, 00)
        self.assertEqual(nice_time(dt, lang="pt-pt", use_24hour=True),
                         "uma e quinze")
        self.assertEqual(nice_time(dt, lang="pt-pt"), "uma e um quarto")

        dt = datetime.datetime(2017, 1, 31, 1, 35, 00)
        self.assertEqual(nice_time(dt, lang="pt-pt"),
                         "duas menos vinte e cinco")

        dt = datetime.datetime(2017, 1, 31, 1, 45, 00)
        self.assertEqual(nice_time(dt, lang="pt-pt"), "duas menos um quarto")

        dt = datetime.datetime(2017, 1, 31, 4, 50, 00)
        self.assertEqual(nice_time(dt, lang="pt-pt"), "cinco menos dez")

        dt = datetime.datetime(2017, 1, 31, 5, 55, 00)
        self.assertEqual(nice_time(dt, lang="pt-pt"), "seis menos cinco")

        dt = datetime.datetime(2017, 1, 31, 5, 30, 00)
        self.assertEqual(nice_time(dt, lang="pt-pt", use_ampm=True),
                         "cinco e meia da madrugada")

        dt = datetime.datetime(2017, 1, 31, 23, 15, 9)
        self.assertEqual(
            nice_time(dt, lang="pt-pt", use_24hour=True, use_ampm=True),
            "vinte e três e quinze")
        self.assertEqual(
            nice_time(dt, lang="pt-pt", use_24hour=False, use_ampm=True),
            "onze e um quarto da noite")
Exemplo n.º 3
0
    def handle_get_appointment_date(self, message):
        """
        Handles the intent asking for events on a specific date.
        Checks the calendar on the specified date first,
        then responses with the number of planned events.
        If it's not 0, the user is asked if the events
        should be listed. If the user responds with 'yes'
        all events are listed with title, start and end time.
        :param message: The speech input message. Used to extract the specified date
        """
        self.log.info(f"Intent message: {message.data['utterance']}")
        extracted_date = extract_datetime(message.data['utterance'],
                                          datetime.now(self.timezone))[0]
        self.log.debug(f"Extracted date(s): {extracted_date}")
        events = self.caldav_interface.get_events_for_date(extracted_date)
        self.log.debug(f"Events on {extracted_date}: {events}")

        if len(events) == 0:
            self.speak_dialog("no.events.on.date", {
                "date":
                nice_date(extracted_date, now=datetime.now(self.timezone))
            })
        else:
            self.speak_dialog(
                "number.events.on.date", {
                    "date":
                    nice_date(extracted_date, now=datetime.now(self.timezone)),
                    "number_of_appointments":
                    len(events),
                    "plural":
                    "s" if len(events) > 1 else ""
                })
            list_events = self.ask_yesno("list.events.of.date", {
                "date":
                nice_date(extracted_date, now=datetime.now(self.timezone))
            })
            if list_events == "yes":
                self.speak_dialog(
                    "events.on.date", {
                        "date":
                        nice_date(extracted_date,
                                  now=datetime.now(self.timezone))
                    })
                for event in events:
                    title = event["title"]
                    startdate_time = event["starttime"]
                    enddate_time = event["endtime"]

                    self.speak_dialog(
                        "event.details", {
                            "title": title,
                            "starttime": nice_time(startdate_time,
                                                   use_ampm=True),
                            "endtime": nice_time(enddate_time, use_ampm=True)
                        })
Exemplo n.º 4
0
 def test_minutes_to_hour(self):
     # "twenty minutes to midnight"
     dt = datetime.datetime(2017, 1, 31,
                            19, 40, 49)
     self.assertEqual(nice_time(dt, lang="pt-pt"),
                      "oito menos vinte")
     self.assertEqual(nice_time(dt, lang="pt-pt", use_ampm=True),
                      "oito menos vinte da tarde")
     self.assertEqual(nice_time(dt, lang="pt-pt", speech=False),
                      "7:40")
     self.assertEqual(nice_time(dt, lang="pt-pt", speech=False,
                                use_ampm=True),
                      "7:40 PM")
     self.assertEqual(nice_time(dt, lang="pt-pt", speech=False,
                                use_24hour=True),
                      "19:40")
     self.assertEqual(nice_time(dt, lang="pt-pt", speech=False,
                                use_24hour=True, use_ampm=True),
                      "19:40")
     self.assertEqual(nice_time(dt, lang="pt-pt", use_24hour=True,
                                use_ampm=True),
                      "dezanove e quarenta")
     self.assertEqual(nice_time(dt, lang="pt-pt", use_24hour=True,
                                use_ampm=False),
                      "dezanove e quarenta")
Exemplo n.º 5
0
 def test_minutes_to_hour(self):
     # "twenty minutes to midnight"
     dt = datetime.datetime(2017, 1, 31, 19, 40, 49)
     self.assertEqual(nice_time(dt, lang="pt-pt"), "oito menos vinte")
     self.assertEqual(nice_time(dt, lang="pt-pt", use_ampm=True),
                      "oito menos vinte da tarde")
     self.assertEqual(nice_time(dt, lang="pt-pt", speech=False), "7:40")
     self.assertEqual(
         nice_time(dt, lang="pt-pt", speech=False, use_ampm=True),
         "7:40 PM")
     self.assertEqual(
         nice_time(dt, lang="pt-pt", speech=False, use_24hour=True),
         "19:40")
     self.assertEqual(
         nice_time(dt,
                   lang="pt-pt",
                   speech=False,
                   use_24hour=True,
                   use_ampm=True), "19:40")
     self.assertEqual(
         nice_time(dt, lang="pt-pt", use_24hour=True, use_ampm=True),
         "dezanove e quarenta")
     self.assertEqual(
         nice_time(dt, lang="pt-pt", use_24hour=True, use_ampm=False),
         "dezanove e quarenta")
Exemplo n.º 6
0
    def _describe(self, alarm):
        if alarm["repeat_rule"]:
            # Describe repeating alarms
            if alarm["repeat_rule"].startswith(
                    "FREQ=WEEKLY;INTERVAL=1;BYDAY="):
                days = alarm["repeat_rule"][29:]  # e.g. "SU,WE"
                days = (days.replace("SU", "0").replace("MO", "1").
                        replace("TU", "2").replace("WE", "3").
                        replace("TH", "4").replace("FR", "5").
                        replace("SA", "6").replace(",", " "))  # now "0 3"
                recur = set()
                for day in days.split():
                    recur.add(day)
                desc = self._recur_desc(recur)
            else:
                desc = self.translate('repeats')

            dt = self.get_alarm_local(alarm)

            dialog = 'recurring.alarm'
            if alarm["name"] != "":
                dialog = dialog + '.named'
            return self.translate(dialog,
                                  data={'time': nice_time(dt, use_ampm=not self.use_24hour,speech=True, use_24hour = self.use_24hour, lang=self.lang),
                                        'recurrence': desc,
                                        'name': alarm["name"]})
        else:
            dt = self.get_alarm_local(alarm)
            dt_string = nice_date_time(dt, now=now_local(), use_ampm= not self.use_24hour, use_24hour = False, lang=self.lang)
            if alarm["name"]:
                return self.translate('alarm.named',
                                      data={'datetime': dt_string,
                                            'name': alarm["name"]})
            else:
                return dt_string
Exemplo n.º 7
0
    def handle_next_intent(self, message):
        if not self.prayer_times:
            self.handle_stop_intent("stop prayer time")
            return

        current_time = now_local()

        next_prayer_time = None

        for prayer_time in self.prayer_times:
            if current_time < prayer_time[1]:
                next_prayer_time = {prayer_time[0]: prayer_time[1]}
                break

        if not next_prayer_time:
            next_prayer_time = {
                self.prayer_times[0][0]: self.prayer_times[0][1]
            }

        use_ampm = bool(not self.config_core.get('time_format') == "full")
        use_24hour = bool(self.config_core.get('time_format') == "full")

        self.speak_dialog(
            "next.mpt", {
                "prayer":
                list(next_prayer_time.keys())[0],
                "time":
                nice_time(next_prayer_time[list(next_prayer_time.keys())[0]],
                          use_24hour=use_24hour,
                          use_ampm=use_ampm)
            })
Exemplo n.º 8
0
 def __nice_time(self, dt, lang="en-us", speech=True, use_24hour=False,
                 use_ampm=False):
     # compatibility wrapper for nice_time
     nt_supported_languages = ['en','it','fr','de']
     if not (lang[0:2] in nt_supported_languages):
         lang = "en-us"
     return nice_time(dt, lang, speech, use_24hour, use_ampm)
Exemplo n.º 9
0
    def handle_get_next_appointment(self, message):
        """
        Generates the response for the intent asking for the next appointment
        in the connected Nextcloud calendar.
        :param message: The speech input message. Unused in this method.
        """
        del message  # unused by handler
        next_event = self.caldav_interface.get_next_event()
        output_data = {}
        dialog_filename = "next.appointment"

        if next_event is not None:
            title = next_event["title"]
            startdate_time = next_event["starttime"]
            enddate_time = next_event["endtime"]
            output_data["startdate"] = nice_date(startdate_time)
            if is_multiple_fulldays_event(startdate_time, enddate_time):
                output_data["enddate"] = nice_date(enddate_time)
            else:
                if not is_fullday_event(startdate_time, enddate_time):
                    output_data["time"] = nice_time(startdate_time)

            if title is not None:
                output_data["title"] = title

        # because we are using Python v3.7.x
        # the order of the keys of the dictionary is the the same as inserted,
        # so we can iterate over the keys to generate the correct dialog filenames
        for key in output_data:
            dialog_filename += "." + key
        self.speak_dialog(dialog_filename, output_data)
Exemplo n.º 10
0
    def _render_time(self, datetime):
        # Show the time in numbers "8:00 AM"
        timestr = nice_time(datetime, speech=False, use_ampm= not self.use_24hour,
                            use_24hour=self.use_24hour)
        x = 16 - ((len(timestr)*4) // 2)  # centers on display
        if not self.use_24hour:
            x += 1  # account for wider letters P and M, offset by the colon

        # draw on the display
        for ch in timestr:
            if ch == ":":
                png = "colon.png"
                w = 2
            elif ch == " ":
                png = "blank.png"
                w = 2
            elif ch == 'A' or ch == 'P' or ch == 'M':
                png = ch+".png"
                w = 5
            else:
                png = ch+".png"
                w = 4

            png = join(abspath(dirname(__file__)), "anim", png)
            self.enclosure.mouth_display_png(png, x=x, y=2, refresh=False)
            x += w
Exemplo n.º 11
0
    def get_display_current_time(self, location=None, dtUTC=None):
        # Get a formatted digital clock time based on the user preferences
        dt = self.get_local_datetime(location, dtUTC)
        if not dt:
            return None

        return nice_time(dt, self.lang, speech=False,
                         use_24hour=self.use_24hour)
Exemplo n.º 12
0
    def __save_reminder_local(self, reminder, reminder_time):
        """ Speak verification and store the reminder. """
        # Choose dialog depending on the date
        if is_today(reminder_time):
            self.speak_dialog('SavingReminder',
                              {'timedate': nice_time(reminder_time, lang=self.lang)})
        elif is_tomorrow(reminder_time):
            self.speak_dialog('SavingReminderTomorrow',
                              {'timedate': nice_time(reminder_time, lang=self.lang)})
        else:
            self.speak_dialog('SavingReminderDate',
                              {'time': nice_time(reminder_time, lang=self.lang),
                               'date': nice_date(reminder_time, lang=self.lang)})

        # Store reminder
        serialized = serialize(reminder_time)
        if 'reminders' in self.settings:
            self.settings['reminders'].append((reminder, serialized))
        else:
            self.settings['reminders'] = [(reminder, serialized)]
Exemplo n.º 13
0
    def get_display_current_time(self, location=None, dtUTC=None):
        print("get_display_current_time")
        #print("8")
        dt = self.get_local_datetime(location, dtUTC)
        print(dt)
        if not dt:
            return None

        return nice_time(dt,
                         self.lang,
                         speech=False,
                         use_24hour=self.use_24hour)
Exemplo n.º 14
0
 def handle_day_appoint(self, message):
     # clean/get date in utter
     if self.update_credentials() is False:  # No credentials
         return
     utter = message.data["utterance"]
     when = extract_datetime(utter, datetime.datetime.now(), self.lang)[0]
     if when is None:
         when = extract_datetime("today", datetime.datetime.now(),
                                 self.lang)
     self.log.info(str(when))
     # get events
     events = self.get_events(when)
     nice_when = nice_date(when, now=now_local(), lang=self.lang)
     if events:
         # say first
         self.speak_dialog("day",
                           data={
                               "num_events":
                               len(events),
                               "event":
                               events[0].get("event"),
                               "when":
                               nice_when,
                               "time":
                               nice_time(events[0].get("datetime"),
                                         use_ampm=True)
                           })
         # Say follow up
         for x in range(1, len(events)):
             self.speak_dialog("day.followed",
                               data={
                                   "event":
                                   events[x].get("event"),
                                   "time":
                                   nice_time(events[x].get("datetime"),
                                             use_ampm=True)
                               })
     elif events is None or events == []:
         self.speak_dialog("no.events", data={"when": nice_when})
Exemplo n.º 15
0
    def get_next_reminder(self, msg=None):
        """ Get the first upcoming reminder. """
        if len(self.settings.get('reminders', [])) > 0:
            reminders = [(r[0], deserialize(r[1]))
                         for r in self.settings['reminders']]
            next_reminder = sorted(reminders, key=lambda tup: tup[1])[0]

            if is_today(next_reminder[1]):
                self.speak_dialog('NextToday',
                                  data={'time': nice_time(next_reminder[1], lang=self.lang),
                                        'reminder': next_reminder[0]})
            elif is_tomorrow(next_reminder[1]):
                self.speak_dialog('NextTomorrow',
                                  data={'time': nice_time(next_reminder[1], lang=self.lang),
                                        'reminder': next_reminder[0]})
            else:
                self.speak_dialog('NextOtherDate',
                                  data={'time': nice_time(next_reminder[1], lang=self.lang),
                                        'date': nice_date(next_reminder[1], lang=self.lang),
                                        'reminder': next_reminder[0]})
        else:
            self.speak_dialog('NoUpcoming')
Exemplo n.º 16
0
 def _read_unread_channel(self, chan):
     if self.state == "stopped":
         return
     msg_count = chan['msg_count']
     if msg_count:
         channel_message = self.dialog_renderer.render(
             "messages.for.channel", {'display_name': chan['display_name']})
         LOG.debug(channel_message)
         self.speak(channel_message)
         pfc = self.mm.posts.get_posts_for_channel(chan['channel_id'])
         order = pfc['order']
         # in case returned posts are less than number of unread
         # avoid 'index out of bounds'
         msg_count = msg_count if msg_count < len(order) else len(order)
         prev_date = ""
         for i in range(0, msg_count):
             if self.state == "stopped":
                 break
             # order starts with newest to oldest,
             # start to read the oldest of the unread
             post = pfc['posts'][order[msg_count - i - 1]]
             create_at = ""
             # nice_date does only support en-us yet - bummer!
             # MM timestamps are in millisecs, python in secs
             msg_date = nice_date(datetime.fromtimestamp(post['create_at'] /
                                                         1000),
                                  self.lang,
                                  now=datetime.now())
             if prev_date != msg_date:
                 create_at = msg_date + " "
                 prev_date = msg_date
             msg_time = nice_time(
                 datetime.fromtimestamp(post['create_at'] / 1000),
                 self.lang)
             create_at += msg_time
             msg = self.dialog_renderer.render(
                 "message", {
                     'user_name': self._get_user_name(post['user_id']),
                     'create_at': create_at,
                     'message': post['message']
                 })
             LOG.debug(msg)
             self.speak(msg, wait=True)
             time.sleep(.3)
         # mark channel as read
         self.mm.channels.view_channel(self.userid,
                                       {'channel_id': chan['channel_id']})
         # TODO clarify when to reset prev_unread/prev_mentions
         self.prev_unread = 0
         self.prev_mentions = 0
Exemplo n.º 17
0
    def test_minutes_past_hour(self):
        # "quarter past ten"
        dt = datetime.datetime(2017, 1, 31,
                               1, 15, 00)
        self.assertEqual(nice_time(dt, lang="pt-pt", use_24hour=True),
                         "uma e quinze")
        self.assertEqual(nice_time(dt, lang="pt-pt"),
                         "uma e um quarto")

        dt = datetime.datetime(2017, 1, 31,
                               1, 35, 00)
        self.assertEqual(nice_time(dt, lang="pt-pt"),
                         "duas menos vinte e cinco")

        dt = datetime.datetime(2017, 1, 31,
                               1, 45, 00)
        self.assertEqual(nice_time(dt, lang="pt-pt"),
                         "duas menos um quarto")

        dt = datetime.datetime(2017, 1, 31,
                               4, 50, 00)
        self.assertEqual(nice_time(dt, lang="pt-pt"),
                         "cinco menos dez")

        dt = datetime.datetime(2017, 1, 31,
                               5, 55, 00)
        self.assertEqual(nice_time(dt, lang="pt-pt"),
                         "seis menos cinco")

        dt = datetime.datetime(2017, 1, 31,
                               5, 30, 00)
        self.assertEqual(nice_time(dt, lang="pt-pt", use_ampm=True),
                         "cinco e meia da madrugada")

        dt = datetime.datetime(2017, 1, 31,
                               23, 15, 9)
        self.assertEqual(nice_time(dt, lang="pt-pt", use_24hour=True,
                                   use_ampm=True),
                         "vinte e três e quinze")
        self.assertEqual(nice_time(dt, lang="pt-pt", use_24hour=False,
                                   use_ampm=True),
                         "onze e um quarto da noite")
Exemplo n.º 18
0
    def get_reminders_for_day(self, msg=None):
        """ List all reminders for the specified date. """
        if 'date' in msg.data:
            date, _ = extract_datetime(msg.data['date'], lang=self.lang)
        else:
            date, _ = extract_datetime(msg.data['utterance'], lang=self.lang)

        if 'reminders' in self.settings:
            reminders = [r for r in self.settings['reminders']
                         if deserialize(r[1]).date() == date.date()]
            if len(reminders) > 0:
                for r in reminders:
                    reminder, dt = (r[0], deserialize(r[1]))
                    self.speak(reminder + ' at ' + nice_time(dt))
                return
        self.speak_dialog('NoUpcoming')
Exemplo n.º 19
0
    def get_spoken_current_time(self, location=None,
                                dtUTC=None, force_ampm=False):
        # Get a formatted spoken time based on the user preferences
        dt = self.get_local_datetime(location, dtUTC)
        if not dt:
            return

        # speak AM/PM when talking about somewhere else
        say_am_pm = bool(location) or force_ampm

        s = nice_time(dt, self.lang, speech=True,
                      use_24hour=self.use_24hour, use_ampm=say_am_pm)
        # HACK: Mimic 2 has a bug with saying "AM".  Work around it for now.
        if say_am_pm:
            s = s.replace("AM", "A.M.")
        return s
Exemplo n.º 20
0
 def test_midnight(self):
     dt = datetime.datetime(2017, 1, 31,
                            0, 2, 3)
     self.assertEqual(nice_time(dt, lang="pt"),
                      "meia noite e dois")
     self.assertEqual(nice_time(dt, lang="pt", use_ampm=True),
                      "meia noite e dois")
     self.assertEqual(nice_time(dt, lang="pt", use_24hour=True),
                      "zero e dois")
     self.assertEqual(nice_time(dt, lang="pt", speech=False),
                      "12:02")
     self.assertEqual(nice_time(dt, lang="pt", speech=False,
                                use_ampm=True), "12:02 AM")
     self.assertEqual(nice_time(dt, lang="pt", speech=False,
                                use_24hour=True), "00:02")
     self.assertEqual(nice_time(dt, lang="pt", speech=False,
                                use_24hour=True,
                                use_ampm=True), "00:02")
     self.assertEqual(nice_time(dt, lang="pt", use_24hour=True,
                                use_ampm=True), "zero e dois")
     self.assertEqual(nice_time(dt, lang="pt", use_24hour=True,
                                use_ampm=False), "zero e dois")
Exemplo n.º 21
0
 def test_midnight(self):
     dt = datetime.datetime(2017, 1, 31,
                            0, 2, 3)
     self.assertEqual(nice_time(dt, lang="pt"),
                      "meia noite e dois")
     self.assertEqual(nice_time(dt, lang="pt", use_ampm=True),
                      "meia noite e dois")
     self.assertEqual(nice_time(dt, lang="pt", use_24hour=True),
                      "zero e dois")
     self.assertEqual(nice_time(dt, lang="pt", speech=False),
                      "12:02")
     self.assertEqual(nice_time(dt, lang="pt", speech=False,
                                use_ampm=True), "12:02 AM")
     self.assertEqual(nice_time(dt, lang="pt", speech=False,
                                use_24hour=True), "00:02")
     self.assertEqual(nice_time(dt, lang="pt", speech=False,
                                use_24hour=True,
                                use_ampm=True), "00:02")
     self.assertEqual(nice_time(dt, lang="pt", use_24hour=True,
                                use_ampm=True), "zero e dois")
     self.assertEqual(nice_time(dt, lang="pt", use_24hour=True,
                                use_ampm=False), "zero e dois")
Exemplo n.º 22
0
    def get_spoken_current_time(self,
                                location=None,
                                dtUTC=None,
                                force_ampm=False):
        print("get_spoken_current_time")
        #print("9")
        dt = self.get_local_datetime(location, dtUTC)
        if not dt:
            print("9.1")
            return
        say_am_pm = bool(location) or force_ampm

        s = nice_time(dt,
                      self.lang,
                      speech=True,
                      use_24hour=self.use_24hour,
                      use_ampm=say_am_pm)
        print("exit from get_spoken_current_time")
        return s
Exemplo n.º 23
0
    def handle_today_intent(self, message):
        if not self.prayer_times:
            self.handle_stop_intent("stop prayer time")
            return

        use_ampm = bool(not self.config_core.get('time_format') == "full")
        use_24hour = bool(self.config_core.get('time_format') == "full")

        for prayer_time in self.prayer_times:
            self.speak_dialog(
                "today.mpt", {
                    "prayer":
                    prayer_time[0],
                    "time":
                    nice_time(prayer_time[1],
                              use_24hour=use_24hour,
                              use_ampm=use_ampm)
                })

            wait_while_speaking()
Exemplo n.º 24
0
 def test_midday(self):
     dt = datetime.datetime(2017, 1, 31, 12, 15, 9)
     self.assertEqual(nice_time(dt, lang="pt-pt"), "meio dia e um quarto")
     self.assertEqual(nice_time(dt, lang="pt-pt", use_ampm=True),
                      "meio dia e um quarto")
     self.assertEqual(nice_time(dt, lang="pt-pt", speech=False), "12:15")
     self.assertEqual(
         nice_time(dt, lang="pt-pt", speech=False, use_ampm=True),
         "12:15 PM")
     self.assertEqual(
         nice_time(dt, lang="pt-pt", speech=False, use_24hour=True),
         "12:15")
     self.assertEqual(
         nice_time(dt,
                   lang="pt-pt",
                   speech=False,
                   use_24hour=True,
                   use_ampm=True), "12:15")
     self.assertEqual(
         nice_time(dt, lang="pt-pt", use_24hour=True, use_ampm=True),
         "doze e quinze")
     self.assertEqual(
         nice_time(dt, lang="pt-pt", use_24hour=True, use_ampm=False),
         "doze e quinze")
Exemplo n.º 25
0
 def test_midday(self):
     dt = datetime.datetime(2017, 1, 31,
                            12, 15, 9)
     self.assertEqual(nice_time(dt, lang="pt-pt"),
                      "meio dia e um quarto")
     self.assertEqual(nice_time(dt, lang="pt-pt", use_ampm=True),
                      "meio dia e um quarto")
     self.assertEqual(nice_time(dt, lang="pt-pt", speech=False),
                      "12:15")
     self.assertEqual(nice_time(dt, lang="pt-pt", speech=False,
                                use_ampm=True),
                      "12:15 PM")
     self.assertEqual(nice_time(dt, lang="pt-pt", speech=False,
                                use_24hour=True),
                      "12:15")
     self.assertEqual(nice_time(dt, lang="pt-pt", speech=False,
                                use_24hour=True, use_ampm=True),
                      "12:15")
     self.assertEqual(nice_time(dt, lang="pt-pt", use_24hour=True,
                                use_ampm=True),
                      "doze e quinze")
     self.assertEqual(nice_time(dt, lang="pt-pt", use_24hour=True,
                                use_ampm=False),
                      "doze e quinze")
Exemplo n.º 26
0
    def handle_sunset(self, message):
        report = self.__initialize_report(message)

        when = extract_datetime(message.data.get('utterance'))[0]
        if when == extract_datetime(" ")[0]:
            weather = self.owm.weather_at_place(report['full_location'],
                                                report['lat'],
                                                report['lon']).get_weather()
        else:
            # Get forecast for that day
            # weather = self.__get_forecast(when, report['full_location'],
            #                               report['lat'], report['lon'])

            # There appears to be a bug in OWM, it can't extract the sunrise/
            # sunset from forecast objects.  Look in to this later, but say
            # "I don't know" for now
            weather = None
        if not weather or weather.get_humidity() == 0:
            self.speak_dialog("do not know")
            return

        dtSunriseUTC = datetime.fromtimestamp(weather.get_sunset_time())
        dtLocal = self.__to_Local(dtSunriseUTC)
        self.speak(nice_time(dtLocal, use_ampm=True))
Exemplo n.º 27
0
    def test_pm(self):
        dt = datetime.datetime(2017, 1, 31, 13, 22, 3)

        # Verify defaults haven't changed
        self.assertEqual(nice_time(dt, lang="pt-pt"),
                         nice_time(dt, "pt-pt", True, False, False))

        self.assertEqual(nice_time(dt, lang="pt"), "uma e vinte e dois")
        self.assertEqual(nice_time(dt, lang="pt", use_ampm=True),
                         "uma e vinte e dois da tarde")
        self.assertEqual(nice_time(dt, lang="pt", speech=False), "1:22")
        self.assertEqual(nice_time(dt, lang="pt", speech=False, use_ampm=True),
                         "1:22 PM")
        self.assertEqual(
            nice_time(dt, lang="pt", speech=False, use_24hour=True), "13:22")
        self.assertEqual(
            nice_time(dt,
                      lang="pt",
                      speech=False,
                      use_24hour=True,
                      use_ampm=True), "13:22")
        self.assertEqual(
            nice_time(dt, lang="pt", use_24hour=True, use_ampm=True),
            "treze e vinte e dois")
        self.assertEqual(
            nice_time(dt, lang="pt", use_24hour=True, use_ampm=False),
            "treze e vinte e dois")

        dt = datetime.datetime(2017, 1, 31, 13, 0, 3)
        self.assertEqual(nice_time(dt, lang="pt"), "uma em ponto")
        self.assertEqual(nice_time(dt, lang="pt", use_ampm=True),
                         "uma da tarde")
        self.assertEqual(nice_time(dt, lang="pt", speech=False), "1:00")
        self.assertEqual(nice_time(dt, lang="pt", speech=False, use_ampm=True),
                         "1:00 PM")
        self.assertEqual(
            nice_time(dt, lang="pt", speech=False, use_24hour=True), "13:00")
        self.assertEqual(
            nice_time(dt,
                      lang="pt",
                      speech=False,
                      use_24hour=True,
                      use_ampm=True), "13:00")
        self.assertEqual(
            nice_time(dt, lang="pt", use_24hour=True, use_ampm=True), "treze")
        dt = datetime.datetime(2017, 1, 31, 13, 2, 3)
        self.assertEqual(nice_time(dt, lang="pt", use_24hour=True),
                         "treze e dois")
        self.assertEqual(nice_time(dt, lang="pt", use_ampm=True),
                         "uma e dois da tarde")
        self.assertEqual(nice_time(dt, lang="pt", speech=False), "1:02")
        self.assertEqual(nice_time(dt, lang="pt", speech=False, use_ampm=True),
                         "1:02 PM")
        self.assertEqual(
            nice_time(dt, lang="pt", speech=False, use_24hour=True), "13:02")
        self.assertEqual(
            nice_time(dt,
                      lang="pt",
                      speech=False,
                      use_24hour=True,
                      use_ampm=True), "13:02")
        self.assertEqual(
            nice_time(dt, lang="pt", use_24hour=True, use_ampm=True),
            "treze e dois")
        self.assertEqual(
            nice_time(dt, lang="pt", use_24hour=True, use_ampm=False),
            "treze e dois")
Exemplo n.º 28
0
    def test_convert_times(self):
        dt = datetime.datetime(2017, 1, 31,
                               13, 22, 3)

        # Verify defaults haven't changed
        self.assertEqual(nice_time(dt),
                         nice_time(dt, "en-us", True, False, False))

        self.assertEqual(nice_time(dt),
                         "one twenty two")
        self.assertEqual(nice_time(dt, use_ampm=True),
                         "one twenty two p.m.")
        self.assertEqual(nice_time(dt, speech=False),
                         "1:22")
        self.assertEqual(nice_time(dt, speech=False, use_ampm=True),
                         "1:22 PM")
        self.assertEqual(nice_time(dt, speech=False, use_24hour=True),
                         "13:22")
        self.assertEqual(nice_time(dt, speech=False, use_24hour=True,
                                   use_ampm=True),
                         "13:22")
        self.assertEqual(nice_time(dt, use_24hour=True, use_ampm=True),
                         "thirteen twenty two")
        self.assertEqual(nice_time(dt, use_24hour=True, use_ampm=False),
                         "thirteen twenty two")

        dt = datetime.datetime(2017, 1, 31,
                               13, 0, 3)
        self.assertEqual(nice_time(dt),
                         "one o'clock")
        self.assertEqual(nice_time(dt, use_ampm=True),
                         "one p.m.")
        self.assertEqual(nice_time(dt, speech=False),
                         "1:00")
        self.assertEqual(nice_time(dt, speech=False, use_ampm=True),
                         "1:00 PM")
        self.assertEqual(nice_time(dt, speech=False, use_24hour=True),
                         "13:00")
        self.assertEqual(nice_time(dt, speech=False, use_24hour=True,
                                   use_ampm=True),
                         "13:00")
        self.assertEqual(nice_time(dt, use_24hour=True, use_ampm=True),
                         "thirteen hundred")
        self.assertEqual(nice_time(dt, use_24hour=True, use_ampm=False),
                         "thirteen hundred")

        dt = datetime.datetime(2017, 1, 31,
                               13, 2, 3)
        self.assertEqual(nice_time(dt),
                         "one oh two")
        self.assertEqual(nice_time(dt, use_ampm=True),
                         "one oh two p.m.")
        self.assertEqual(nice_time(dt, speech=False),
                         "1:02")
        self.assertEqual(nice_time(dt, speech=False, use_ampm=True),
                         "1:02 PM")
        self.assertEqual(nice_time(dt, speech=False, use_24hour=True),
                         "13:02")
        self.assertEqual(nice_time(dt, speech=False, use_24hour=True,
                                   use_ampm=True),
                         "13:02")
        self.assertEqual(nice_time(dt, use_24hour=True, use_ampm=True),
                         "thirteen zero two")
        self.assertEqual(nice_time(dt, use_24hour=True, use_ampm=False),
                         "thirteen zero two")

        dt = datetime.datetime(2017, 1, 31,
                               0, 2, 3)
        self.assertEqual(nice_time(dt),
                         "twelve oh two")
        self.assertEqual(nice_time(dt, use_ampm=True),
                         "twelve oh two a.m.")
        self.assertEqual(nice_time(dt, speech=False),
                         "12:02")
        self.assertEqual(nice_time(dt, speech=False, use_ampm=True),
                         "12:02 AM")
        self.assertEqual(nice_time(dt, speech=False, use_24hour=True),
                         "00:02")
        self.assertEqual(nice_time(dt, speech=False, use_24hour=True,
                                   use_ampm=True),
                         "00:02")
        self.assertEqual(nice_time(dt, use_24hour=True, use_ampm=True),
                         "zero zero zero two")
        self.assertEqual(nice_time(dt, use_24hour=True, use_ampm=False),
                         "zero zero zero two")

        dt = datetime.datetime(2018, 2, 8,
                               1, 2, 33)
        self.assertEqual(nice_time(dt),
                         "one oh two")
        self.assertEqual(nice_time(dt, use_ampm=True),
                         "one oh two a.m.")
        self.assertEqual(nice_time(dt, speech=False),
                         "1:02")
        self.assertEqual(nice_time(dt, speech=False, use_ampm=True),
                         "1:02 AM")
        self.assertEqual(nice_time(dt, speech=False, use_24hour=True),
                         "01:02")
        self.assertEqual(nice_time(dt, speech=False, use_24hour=True,
                                   use_ampm=True),
                         "01:02")
        self.assertEqual(nice_time(dt, use_24hour=True, use_ampm=True),
                         "zero one zero two")
        self.assertEqual(nice_time(dt, use_24hour=True, use_ampm=False),
                         "zero one zero two")
Exemplo n.º 29
0
    def test_convert_times(self):
        dt = datetime.datetime(2017, 1, 31,
                               13, 22, 3)

        # Verify defaults haven't changed
        self.assertEqual(nice_time(dt),
                         nice_time(dt, "en-us", True, False, False))

        self.assertEqual(nice_time(dt),
                         "one twenty two")
        self.assertEqual(nice_time(dt, use_ampm=True),
                         "one twenty two PM")
        self.assertEqual(nice_time(dt, speech=False),
                         "1:22")
        self.assertEqual(nice_time(dt, speech=False, use_ampm=True),
                         "1:22 PM")
        self.assertEqual(nice_time(dt, speech=False, use_24hour=True),
                         "13:22")
        self.assertEqual(nice_time(dt, speech=False, use_24hour=True,
                                   use_ampm=True),
                         "13:22")
        self.assertEqual(nice_time(dt, use_24hour=True, use_ampm=True),
                         "thirteen twenty two")
        self.assertEqual(nice_time(dt, use_24hour=True, use_ampm=False),
                         "thirteen twenty two")

        dt = datetime.datetime(2017, 1, 31,
                               13, 0, 3)
        self.assertEqual(nice_time(dt),
                         "one o'clock")
        self.assertEqual(nice_time(dt, use_ampm=True),
                         "one PM")
        self.assertEqual(nice_time(dt, speech=False),
                         "1:00")
        self.assertEqual(nice_time(dt, speech=False, use_ampm=True),
                         "1:00 PM")
        self.assertEqual(nice_time(dt, speech=False, use_24hour=True),
                         "13:00")
        self.assertEqual(nice_time(dt, speech=False, use_24hour=True,
                                   use_ampm=True),
                         "13:00")
        self.assertEqual(nice_time(dt, use_24hour=True, use_ampm=True),
                         "thirteen hundred")
        self.assertEqual(nice_time(dt, use_24hour=True, use_ampm=False),
                         "thirteen hundred")

        dt = datetime.datetime(2017, 1, 31,
                               13, 2, 3)
        self.assertEqual(nice_time(dt),
                         "one oh two")
        self.assertEqual(nice_time(dt, use_ampm=True),
                         "one oh two PM")
        self.assertEqual(nice_time(dt, speech=False),
                         "1:02")
        self.assertEqual(nice_time(dt, speech=False, use_ampm=True),
                         "1:02 PM")
        self.assertEqual(nice_time(dt, speech=False, use_24hour=True),
                         "13:02")
        self.assertEqual(nice_time(dt, speech=False, use_24hour=True,
                                   use_ampm=True),
                         "13:02")
        self.assertEqual(nice_time(dt, use_24hour=True, use_ampm=True),
                         "thirteen zero two")
        self.assertEqual(nice_time(dt, use_24hour=True, use_ampm=False),
                         "thirteen zero two")

        dt = datetime.datetime(2017, 1, 31,
                               0, 2, 3)
        self.assertEqual(nice_time(dt),
                         "twelve oh two")
        self.assertEqual(nice_time(dt, use_ampm=True),
                         "twelve oh two AM")
        self.assertEqual(nice_time(dt, speech=False),
                         "12:02")
        self.assertEqual(nice_time(dt, speech=False, use_ampm=True),
                         "12:02 AM")
        self.assertEqual(nice_time(dt, speech=False, use_24hour=True),
                         "00:02")
        self.assertEqual(nice_time(dt, speech=False, use_24hour=True,
                                   use_ampm=True),
                         "00:02")
        self.assertEqual(nice_time(dt, use_24hour=True, use_ampm=True),
                         "zero zero zero two")
        self.assertEqual(nice_time(dt, use_24hour=True, use_ampm=False),
                         "zero zero zero two")

        dt = datetime.datetime(2018, 2, 8,
                               1, 2, 33)
        self.assertEqual(nice_time(dt),
                         "one oh two")
        self.assertEqual(nice_time(dt, use_ampm=True),
                         "one oh two AM")
        self.assertEqual(nice_time(dt, speech=False),
                         "1:02")
        self.assertEqual(nice_time(dt, speech=False, use_ampm=True),
                         "1:02 AM")
        self.assertEqual(nice_time(dt, speech=False, use_24hour=True),
                         "01:02")
        self.assertEqual(nice_time(dt, speech=False, use_24hour=True,
                                   use_ampm=True),
                         "01:02")
        self.assertEqual(nice_time(dt, use_24hour=True, use_ampm=True),
                         "zero one zero two")
        self.assertEqual(nice_time(dt, use_24hour=True, use_ampm=False),
                         "zero one zero two")
Exemplo n.º 30
0
    def test_convert_times_da(self):
        dt = datetime.datetime(2017, 1, 31, 13, 22, 3)

        self.assertEqual(nice_time(dt, lang="da-dk"),
                         "et toogtyve")
        self.assertEqual(nice_time(dt, lang="da-dk", use_ampm=True),
                         "et toogtyve om eftermiddagen")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False),
                         "01:22")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False,
                                   use_ampm=True),
                         "01:22 PM")
        self.assertEqual(nice_time(dt, lang="da-dk",
                                   speech=False, use_24hour=True),
                         "13:22")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "13:22")
        self.assertEqual(nice_time(dt, lang="da-dk", use_24hour=True,
                                   use_ampm=True),
                         "tretten toogtyve")
        self.assertEqual(nice_time(dt, lang="da-dk", use_24hour=True,
                                   use_ampm=False),
                         "tretten toogtyve")

        dt = datetime.datetime(2017, 1, 31, 13, 0, 3)
        self.assertEqual(nice_time(dt, lang="da-dk"), "et")
        self.assertEqual(nice_time(dt, lang="da-dk", use_ampm=True),
                         "et om eftermiddagen")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False),
                         "01:00")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False,
                                   use_ampm=True),
                         "01:00 PM")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False,
                                   use_24hour=True),
                         "13:00")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "13:00")
        self.assertEqual(nice_time(dt, lang="da-dk", use_24hour=True,
                                   use_ampm=True),
                         "tretten")
        self.assertEqual(nice_time(dt, lang="da-dk", use_24hour=True,
                                   use_ampm=False),
                         "tretten")

        dt = datetime.datetime(2017, 1, 31, 13, 2, 3)
        self.assertEqual(nice_time(dt, lang="da-dk"), "et nul to")
        self.assertEqual(nice_time(dt, lang="da-dk", use_ampm=True),
                         "et nul to om eftermiddagen")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False),
                         "01:02")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False,
                                   use_ampm=True),
                         "01:02 PM")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False,
                                   use_24hour=True),
                         "13:02")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "13:02")
        self.assertEqual(nice_time(dt, lang="da-dk", use_24hour=True,
                                   use_ampm=True),
                         "tretten nul to")
        self.assertEqual(nice_time(dt, lang="da-dk", use_24hour=True,
                                   use_ampm=False),
                         "tretten nul to")

        dt = datetime.datetime(2017, 1, 31, 0, 2, 3)
        self.assertEqual(nice_time(dt, lang="da-dk"), "tolv nul to")
        self.assertEqual(nice_time(dt, lang="da-dk", use_ampm=True),
                         "tolv nul to om natten")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False),
                         "12:02")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False,
                                   use_ampm=True),
                         "12:02 AM")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False,
                                   use_24hour=True),
                         "00:02")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "00:02")
        self.assertEqual(nice_time(dt, lang="da-dk", use_24hour=True,
                                   use_ampm=True),
                         "nul nul to")
        self.assertEqual(nice_time(dt, lang="da-dk", use_24hour=True,
                                   use_ampm=False),
                         "nul nul to")

        dt = datetime.datetime(2017, 1, 31, 12, 15, 9)
        self.assertEqual(nice_time(dt, lang="da-dk"), "tolv femten")
        self.assertEqual(nice_time(dt, lang="da-dk", use_ampm=True),
                         "tolv femten om eftermiddagen")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False),
                         "12:15")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False,
                                   use_ampm=True),
                         "12:15 PM")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False,
                                   use_24hour=True),
                         "12:15")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "12:15")
        self.assertEqual(nice_time(dt, lang="da-dk", use_24hour=True,
                                   use_ampm=True),
                         "tolv femten")
        self.assertEqual(nice_time(dt, lang="da-dk", use_24hour=True,
                                   use_ampm=False),
                         "tolv femten")

        dt = datetime.datetime(2017, 1, 31, 19, 40, 49)
        self.assertEqual(nice_time(dt, lang="da-dk"), "syv fyrre")
        self.assertEqual(nice_time(dt, lang="da-dk", use_ampm=True),
                         "syv fyrre om aftenen")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False),
                         "07:40")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False,
                                   use_ampm=True),
                         "07:40 PM")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False,
                                   use_24hour=True),
                         "19:40")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "19:40")
        self.assertEqual(nice_time(dt, lang="da-dk", use_24hour=True,
                                   use_ampm=True),
                         "nitten fyrre")
        self.assertEqual(nice_time(dt, lang="da-dk", use_24hour=True,
                                   use_ampm=False),
                         "nitten fyrre")

        dt = datetime.datetime(2017, 1, 31, 1, 15, 00)
        self.assertEqual(nice_time(dt, lang="da-dk", use_24hour=True),
                         "et femten")

        dt = datetime.datetime(2017, 1, 31, 1, 35, 00)
        self.assertEqual(nice_time(dt, lang="da-dk"),
                         "et femogtredive")

        dt = datetime.datetime(2017, 1, 31, 1, 45, 00)
        self.assertEqual(nice_time(dt, lang="da-dk"), "et femogfyrre")

        dt = datetime.datetime(2017, 1, 31, 4, 50, 00)
        self.assertEqual(nice_time(dt, lang="da-dk"), "fire halvtres")

        dt = datetime.datetime(2017, 1, 31, 5, 55, 00)
        self.assertEqual(nice_time(dt, lang="da-dk"), "fem femoghalvtres")

        dt = datetime.datetime(2017, 1, 31, 5, 30, 00)
        self.assertEqual(nice_time(dt, lang="da-dk", use_ampm=True),
                         "fem tredive om morgenen")
Exemplo n.º 31
0
    def test_convert_times(self):
        dt = datetime.datetime(2017, 1, 31, 13, 22, 3)

        # Verify defaults haven't changed
        self.assertEqual(nice_time(dt, lang="it-it"),
                         nice_time(dt, "it-it", True, False, False))

        self.assertEqual(nice_time(dt, lang="it"),
                         "una e ventidue")
        self.assertEqual(nice_time(dt, lang="it", use_ampm=True),
                         "una e ventidue del pomeriggio")
        self.assertEqual(nice_time(dt, lang="it", speech=False), "1:22")
        self.assertEqual(nice_time(dt, lang="it", speech=False,
                                   use_ampm=True), "1:22 PM")
        self.assertEqual(nice_time(dt, lang="it", speech=False,
                                   use_24hour=True), "13:22")
        self.assertEqual(nice_time(dt, lang="it", speech=False,
                                   use_24hour=True, use_ampm=True), "13:22")
        self.assertEqual(nice_time(dt, lang="it", use_24hour=True,
                                   use_ampm=True), "tredici e ventidue")
        self.assertEqual(nice_time(dt, lang="it", use_24hour=True,
                                   use_ampm=False), "tredici e ventidue")
        # Verifica fasce orarie use_ampm = True
        d_time = datetime.datetime(2017, 1, 31, 8, 22, 3)
        self.assertEqual(nice_time(d_time, lang="it", use_ampm=True),
                         "otto e ventidue della mattina")
        d_time = datetime.datetime(2017, 1, 31, 20, 22, 3)
        self.assertEqual(nice_time(d_time, lang="it", use_ampm=True),
                         "otto e ventidue della sera")
        d_time = datetime.datetime(2017, 1, 31, 23, 22, 3)
        self.assertEqual(nice_time(d_time, lang="it", use_ampm=True),
                         "undici e ventidue della notte")
        d_time = datetime.datetime(2017, 1, 31, 00, 00, 3)
        self.assertEqual(nice_time(d_time, lang="it", use_ampm=True),
                         "mezzanotte")
        d_time = datetime.datetime(2017, 1, 31, 12, 00, 3)
        self.assertEqual(nice_time(d_time, lang="it", use_ampm=True),
                         "mezzogiorno")
        dt = datetime.datetime(2017, 1, 31, 13, 0, 3)
        self.assertEqual(nice_time(dt, lang="it"),
                         "una in punto")
        self.assertEqual(nice_time(dt, lang="it", use_ampm=True),
                         "una del pomeriggio")
        self.assertEqual(nice_time(dt, lang="it", speech=False),
                         "1:00")
        self.assertEqual(nice_time(dt, lang="it", speech=False,
                                   use_ampm=True), "1:00 PM")
        self.assertEqual(nice_time(dt, lang="it", speech=False,
                                   use_24hour=True), "13:00")
        self.assertEqual(nice_time(dt, lang="it", speech=False,
                                   use_24hour=True, use_ampm=True), "13:00")
        self.assertEqual(nice_time(dt, lang="it", use_24hour=True,
                                   use_ampm=True), "tredici e zerozero")
        self.assertEqual(nice_time(dt, lang="it", use_24hour=True,
                                   use_ampm=False), "tredici e zerozero")

        dt = datetime.datetime(2017, 1, 31, 13, 2, 3)
        self.assertEqual(nice_time(dt, lang="it", use_24hour=True),
                         "tredici e zero due")
        self.assertEqual(nice_time(dt, lang="it", use_ampm=True),
                         "una e zero due del pomeriggio")
        self.assertEqual(nice_time(dt, lang="it", speech=False),
                         "1:02")
        self.assertEqual(nice_time(dt, lang="it", speech=False,
                                   use_ampm=True), "1:02 PM")
        self.assertEqual(nice_time(dt, lang="it", speech=False,
                                   use_24hour=True), "13:02")
        self.assertEqual(nice_time(dt, lang="it", speech=False,
                                   use_24hour=True, use_ampm=True), "13:02")
        self.assertEqual(nice_time(dt, lang="it", use_24hour=True,
                                   use_ampm=True), "tredici e zero due")
        self.assertEqual(nice_time(dt, lang="it", use_24hour=True,
                                   use_ampm=False), "tredici e zero due")

        dt = datetime.datetime(2017, 1, 31, 0, 2, 3)
        self.assertEqual(nice_time(dt, lang="it"),
                         "mezzanotte e zero due")
        self.assertEqual(nice_time(dt, lang="it", use_ampm=True),
                         "mezzanotte e zero due")
        self.assertEqual(nice_time(dt, lang="it", speech=False),
                         "12:02")
        self.assertEqual(nice_time(dt, lang="it", speech=False,
                                   use_ampm=True), "12:02 AM")
        self.assertEqual(nice_time(dt, lang="it", speech=False,
                                   use_24hour=True), "00:02")
        self.assertEqual(nice_time(dt, lang="it", speech=False,
                                   use_24hour=True,
                                   use_ampm=True), "00:02")
        self.assertEqual(nice_time(dt, lang="it", use_24hour=True,
                                   use_ampm=True), "zerozero e zero due")
        self.assertEqual(nice_time(dt, lang="it", use_24hour=True,
                                   use_ampm=False), "zerozero e zero due")
        # casi particolari
        d_time = datetime.datetime(2017, 1, 31, 1, 2, 3)
        self.assertEqual(nice_time(d_time, lang="it", use_24hour=True,
                                   use_ampm=True), "una e zero due")
        d_time = datetime.datetime(2017, 1, 31, 2, 2, 3)
        self.assertEqual(nice_time(d_time, lang="it", use_24hour=True,
                                   use_ampm=False), "zero due e zero due")
        d_time = datetime.datetime(2017, 1, 31, 10, 15, 0)
        self.assertEqual(nice_time(d_time, lang="it", use_24hour=False,
                                   use_ampm=False), "dieci e un quarto")
        d_time = datetime.datetime(2017, 1, 31, 22, 45, 0)
        self.assertEqual(nice_time(d_time, lang="it", use_24hour=False,
                                   use_ampm=False), "dieci e tre quarti")
Exemplo n.º 32
0
    def test_convert_times_de(self):
        dt = datetime.datetime(2017, 1, 31,
                               13, 22, 3)

        self.assertEqual(nice_time(dt, lang="de-de"),
                         "ein Uhr zweiundzwanzig")
        self.assertEqual(nice_time(dt, lang="de-de", use_ampm=True),
                         "ein Uhr zweiundzwanzig nachmittags")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False),
                         "1:22")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False,
                                   use_ampm=True),
                         "1:22 PM")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False,
                                   use_24hour=True),
                         "13:22")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "13:22")
        self.assertEqual(nice_time(dt, lang="de-de", use_24hour=True,
                                   use_ampm=True),
                         "dreizehn Uhr zweiundzwanzig")
        self.assertEqual(nice_time(dt, lang="de-de", use_24hour=True,
                                   use_ampm=False),
                         "dreizehn Uhr zweiundzwanzig")

        dt = datetime.datetime(2017, 1, 31,
                               13, 0, 3)
        self.assertEqual(nice_time(dt, lang="de-de"),
                         "ein Uhr")
        self.assertEqual(nice_time(dt, lang="de-de", use_ampm=True),
                         "ein Uhr nachmittags")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False),
                         "1:00")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False,
                                   use_ampm=True),
                         "1:00 PM")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False,
                                   use_24hour=True),
                         "13:00")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "13:00")
        self.assertEqual(nice_time(dt, lang="de-de", use_24hour=True,
                                   use_ampm=True),
                         "dreizehn Uhr")
        self.assertEqual(nice_time(dt, lang="de-de", use_24hour=True,
                                   use_ampm=False),
                         "dreizehn Uhr")

        dt = datetime.datetime(2017, 1, 31,
                               13, 2, 3)
        self.assertEqual(nice_time(dt, lang="de-de"),
                         "ein Uhr zwei")
        self.assertEqual(nice_time(dt, lang="de-de", use_ampm=True),
                         "ein Uhr zwei nachmittags")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False),
                         "1:02")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False,
                                   use_ampm=True),
                         "1:02 PM")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False,
                                   use_24hour=True),
                         "13:02")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "13:02")
        self.assertEqual(nice_time(dt, lang="de-de", use_24hour=True,
                                   use_ampm=True),
                         "dreizehn Uhr zwei")
        self.assertEqual(nice_time(dt, lang="de-de", use_24hour=True,
                                   use_ampm=False),
                         "dreizehn Uhr zwei")

        dt = datetime.datetime(2017, 1, 31,
                               0, 2, 3)
        self.assertEqual(nice_time(dt, lang="de-de"),
                         u"zwölf Uhr zwei")
        self.assertEqual(nice_time(dt, lang="de-de", use_ampm=True),
                         u"zwölf Uhr zwei nachts")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False),
                         "12:02")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False,
                                   use_ampm=True),
                         "12:02 AM")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False,
                                   use_24hour=True),
                         "00:02")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "00:02")
        self.assertEqual(nice_time(dt, lang="de-de", use_24hour=True,
                                   use_ampm=True),
                         "null Uhr zwei")
        self.assertEqual(nice_time(dt, lang="de-de", use_24hour=True,
                                   use_ampm=False),
                         "null Uhr zwei")

        dt = datetime.datetime(2017, 1, 31,
                               12, 15, 9)
        self.assertEqual(nice_time(dt, lang="de-de"),
                         u"zwölf Uhr fünfzehn")
        self.assertEqual(nice_time(dt, lang="de-de", use_ampm=True),
                         u"zwölf Uhr fünfzehn nachmittags")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False),
                         "12:15")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False,
                                   use_ampm=True),
                         "12:15 PM")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False,
                                   use_24hour=True),
                         "12:15")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "12:15")
        self.assertEqual(nice_time(dt, lang="de-de", use_24hour=True,
                                   use_ampm=True),
                         u"zwölf Uhr fünfzehn")
        self.assertEqual(nice_time(dt, lang="de-de", use_24hour=True,
                                   use_ampm=False),
                         u"zwölf Uhr fünfzehn")

        dt = datetime.datetime(2017, 1, 31,
                               19, 40, 49)
        self.assertEqual(nice_time(dt, lang="de-de"),
                         "sieben Uhr vierzig")
        self.assertEqual(nice_time(dt, lang="de-de", use_ampm=True),
                         "sieben Uhr vierzig abends")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False),
                         "7:40")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False,
                                   use_ampm=True),
                         "7:40 PM")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False,
                                   use_24hour=True),
                         "19:40")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "19:40")
        self.assertEqual(nice_time(dt, lang="de-de", use_24hour=True,
                                   use_ampm=True),
                         "neunzehn Uhr vierzig")
        self.assertEqual(nice_time(dt, lang="de-de", use_24hour=True,
                                   use_ampm=False),
                         "neunzehn Uhr vierzig")

        dt = datetime.datetime(2017, 1, 31,
                               1, 15, 00)
        self.assertEqual(nice_time(dt, lang="de-de", use_24hour=True),
                         u"ein Uhr fünfzehn")

        dt = datetime.datetime(2017, 1, 31,
                               1, 35, 00)
        self.assertEqual(nice_time(dt, lang="de-de"),
                         u"ein Uhr fünfunddreißig")

        dt = datetime.datetime(2017, 1, 31,
                               1, 45, 00)
        self.assertEqual(nice_time(dt, lang="de-de"),
                         u"ein Uhr fünfundvierzig")

        dt = datetime.datetime(2017, 1, 31,
                               4, 50, 00)
        self.assertEqual(nice_time(dt, lang="de-de"),
                         u"vier Uhr fünfzig")

        dt = datetime.datetime(2017, 1, 31,
                               5, 55, 00)
        self.assertEqual(nice_time(dt, lang="de-de"),
                         u"fünf Uhr fünfundfünfzig")

        dt = datetime.datetime(2017, 1, 31,
                               5, 30, 00)
        self.assertEqual(nice_time(dt, lang="de-de", use_ampm=True),
                         u"fünf Uhr dreißig morgens")
Exemplo n.º 33
0
    def test_convert_times_da(self):
        dt = datetime.datetime(2017, 1, 31, 13, 22, 3)

        self.assertEqual(nice_time(dt, lang="da-dk"),
                         "et toogtyve")
        self.assertEqual(nice_time(dt, lang="da-dk", use_ampm=True),
                         "et toogtyve om eftermiddagen")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False),
                         "01:22")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False,
                                   use_ampm=True),
                         "01:22 PM")
        self.assertEqual(nice_time(dt, lang="da-dk",
                                   speech=False, use_24hour=True),
                         "13:22")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "13:22")
        self.assertEqual(nice_time(dt, lang="da-dk", use_24hour=True,
                                   use_ampm=True),
                         "tretten toogtyve")
        self.assertEqual(nice_time(dt, lang="da-dk", use_24hour=True,
                                   use_ampm=False),
                         "tretten toogtyve")

        dt = datetime.datetime(2017, 1, 31, 13, 0, 3)
        self.assertEqual(nice_time(dt, lang="da-dk"), "et")
        self.assertEqual(nice_time(dt, lang="da-dk", use_ampm=True),
                         "et om eftermiddagen")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False),
                         "01:00")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False,
                                   use_ampm=True),
                         "01:00 PM")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False,
                                   use_24hour=True),
                         "13:00")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "13:00")
        self.assertEqual(nice_time(dt, lang="da-dk", use_24hour=True,
                                   use_ampm=True),
                         "tretten")
        self.assertEqual(nice_time(dt, lang="da-dk", use_24hour=True,
                                   use_ampm=False),
                         "tretten")

        dt = datetime.datetime(2017, 1, 31, 13, 2, 3)
        self.assertEqual(nice_time(dt, lang="da-dk"), "et nul to")
        self.assertEqual(nice_time(dt, lang="da-dk", use_ampm=True),
                         "et nul to om eftermiddagen")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False),
                         "01:02")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False,
                                   use_ampm=True),
                         "01:02 PM")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False,
                                   use_24hour=True),
                         "13:02")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "13:02")
        self.assertEqual(nice_time(dt, lang="da-dk", use_24hour=True,
                                   use_ampm=True),
                         "tretten nul to")
        self.assertEqual(nice_time(dt, lang="da-dk", use_24hour=True,
                                   use_ampm=False),
                         "tretten nul to")

        dt = datetime.datetime(2017, 1, 31, 0, 2, 3)
        self.assertEqual(nice_time(dt, lang="da-dk"), "tolv nul to")
        self.assertEqual(nice_time(dt, lang="da-dk", use_ampm=True),
                         "tolv nul to om natten")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False),
                         "12:02")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False,
                                   use_ampm=True),
                         "12:02 AM")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False,
                                   use_24hour=True),
                         "00:02")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "00:02")
        self.assertEqual(nice_time(dt, lang="da-dk", use_24hour=True,
                                   use_ampm=True),
                         "nul nul to")
        self.assertEqual(nice_time(dt, lang="da-dk", use_24hour=True,
                                   use_ampm=False),
                         "nul nul to")

        dt = datetime.datetime(2017, 1, 31, 12, 15, 9)
        self.assertEqual(nice_time(dt, lang="da-dk"), "tolv femten")
        self.assertEqual(nice_time(dt, lang="da-dk", use_ampm=True),
                         "tolv femten om eftermiddagen")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False),
                         "12:15")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False,
                                   use_ampm=True),
                         "12:15 PM")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False,
                                   use_24hour=True),
                         "12:15")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "12:15")
        self.assertEqual(nice_time(dt, lang="da-dk", use_24hour=True,
                                   use_ampm=True),
                         "tolv femten")
        self.assertEqual(nice_time(dt, lang="da-dk", use_24hour=True,
                                   use_ampm=False),
                         "tolv femten")

        dt = datetime.datetime(2017, 1, 31, 19, 40, 49)
        self.assertEqual(nice_time(dt, lang="da-dk"), "syv fyrre")
        self.assertEqual(nice_time(dt, lang="da-dk", use_ampm=True),
                         "syv fyrre om aftenen")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False),
                         "07:40")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False,
                                   use_ampm=True),
                         "07:40 PM")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False,
                                   use_24hour=True),
                         "19:40")
        self.assertEqual(nice_time(dt, lang="da-dk", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "19:40")
        self.assertEqual(nice_time(dt, lang="da-dk", use_24hour=True,
                                   use_ampm=True),
                         "nitten fyrre")
        self.assertEqual(nice_time(dt, lang="da-dk", use_24hour=True,
                                   use_ampm=False),
                         "nitten fyrre")

        dt = datetime.datetime(2017, 1, 31, 1, 15, 00)
        self.assertEqual(nice_time(dt, lang="da-dk", use_24hour=True),
                         "et femten")

        dt = datetime.datetime(2017, 1, 31, 1, 35, 00)
        self.assertEqual(nice_time(dt, lang="da-dk"),
                         "et femogtredive")

        dt = datetime.datetime(2017, 1, 31, 1, 45, 00)
        self.assertEqual(nice_time(dt, lang="da-dk"), "et femogfyrre")

        dt = datetime.datetime(2017, 1, 31, 4, 50, 00)
        self.assertEqual(nice_time(dt, lang="da-dk"), "fire halvtres")

        dt = datetime.datetime(2017, 1, 31, 5, 55, 00)
        self.assertEqual(nice_time(dt, lang="da-dk"), "fem femoghalvtres")

        dt = datetime.datetime(2017, 1, 31, 5, 30, 00)
        self.assertEqual(nice_time(dt, lang="da-dk", use_ampm=True),
                         "fem tredive om morgenen")
Exemplo n.º 34
0
    def test_convert_times(self):
        dt = datetime.datetime(2017, 1, 31, 13, 22, 3)

        # Verify defaults haven't changed
        self.assertEqual(nice_time(dt, lang="es-es"),
                         nice_time(dt, "es-es", True, False, False))

        self.assertEqual(nice_time(dt, lang="es"), "la una y veintidós")
        self.assertEqual(nice_time(dt, lang="es", use_ampm=True),
                         "la una y veintidós de la tarde")
        self.assertEqual(nice_time(dt, lang="es", speech=False), "1:22")
        self.assertEqual(nice_time(dt, lang="es", speech=False, use_ampm=True),
                         "1:22 PM")
        self.assertEqual(
            nice_time(dt, lang="es", speech=False, use_24hour=True), "13:22")
        self.assertEqual(
            nice_time(dt,
                      lang="es",
                      speech=False,
                      use_24hour=True,
                      use_ampm=True), "13:22")
        self.assertEqual(
            nice_time(dt, lang="es", use_24hour=True, use_ampm=True),
            "las trece veintidós")
        self.assertEqual(
            nice_time(dt, lang="es", use_24hour=True, use_ampm=False),
            "las trece veintidós")

        dt = datetime.datetime(2017, 1, 31, 13, 0, 3)
        self.assertEqual(nice_time(dt, lang="es"), "la una en punto")
        self.assertEqual(nice_time(dt, lang="es", use_ampm=True),
                         "la una de la tarde")
        self.assertEqual(nice_time(dt, lang="es", speech=False), "1:00")
        self.assertEqual(nice_time(dt, lang="es", speech=False, use_ampm=True),
                         "1:00 PM")
        self.assertEqual(
            nice_time(dt, lang="es", speech=False, use_24hour=True), "13:00")
        self.assertEqual(
            nice_time(dt,
                      lang="es",
                      speech=False,
                      use_24hour=True,
                      use_ampm=True), "13:00")
        self.assertEqual(
            nice_time(dt, lang="es", use_24hour=True, use_ampm=True),
            "las trece cero cero")
        dt = datetime.datetime(2017, 1, 31, 13, 2, 3)
        self.assertEqual(nice_time(dt, lang="es", use_24hour=True),
                         "las trece cero dos")
        self.assertEqual(nice_time(dt, lang="es", use_ampm=True),
                         "la una y dos de la tarde")
        self.assertEqual(nice_time(dt, lang="es", speech=False), "1:02")
        self.assertEqual(nice_time(dt, lang="es", speech=False, use_ampm=True),
                         "1:02 PM")
        self.assertEqual(
            nice_time(dt, lang="es", speech=False, use_24hour=True), "13:02")
        self.assertEqual(
            nice_time(dt,
                      lang="es",
                      speech=False,
                      use_24hour=True,
                      use_ampm=True), "13:02")
        self.assertEqual(
            nice_time(dt, lang="es", use_24hour=True, use_ampm=True),
            "las trece cero dos")
        self.assertEqual(
            nice_time(dt, lang="es", use_24hour=True, use_ampm=False),
            "las trece cero dos")

        dt = datetime.datetime(2017, 1, 31, 0, 2, 3)
        self.assertEqual(nice_time(dt, lang="es"), "las doce y dos")
        self.assertEqual(nice_time(dt, lang="es", use_ampm=True),
                         "las doce y dos de la madrugada")
        self.assertEqual(nice_time(dt, lang="es", use_24hour=True),
                         "las cero cero dos")
        self.assertEqual(nice_time(dt, lang="es", speech=False), "12:02")
        self.assertEqual(nice_time(dt, lang="es", speech=False, use_ampm=True),
                         "12:02 AM")
        self.assertEqual(
            nice_time(dt, lang="es", speech=False, use_24hour=True), "00:02")
        self.assertEqual(
            nice_time(dt,
                      lang="es",
                      speech=False,
                      use_24hour=True,
                      use_ampm=True), "00:02")
        self.assertEqual(
            nice_time(dt, lang="es", use_24hour=True, use_ampm=True),
            "las cero cero dos")
        self.assertEqual(
            nice_time(dt, lang="es", use_24hour=True, use_ampm=False),
            "las cero cero dos")

        dt = datetime.datetime(2017, 1, 31, 12, 15, 9)
        self.assertEqual(nice_time(dt, lang="es-es"), "las doce y cuarto")
        self.assertEqual(nice_time(dt, lang="es-es", use_ampm=True),
                         "las doce y cuarto de la mañana")
        self.assertEqual(nice_time(dt, lang="es-es", speech=False), "12:15")
        self.assertEqual(
            nice_time(dt, lang="es-es", speech=False, use_ampm=True),
            "12:15 PM")
        self.assertEqual(
            nice_time(dt, lang="es-es", speech=False, use_24hour=True),
            "12:15")
        self.assertEqual(
            nice_time(dt,
                      lang="es-es",
                      speech=False,
                      use_24hour=True,
                      use_ampm=True), "12:15")
        self.assertEqual(
            nice_time(dt, lang="es-es", use_24hour=True, use_ampm=True),
            "las doce quince")
        self.assertEqual(
            nice_time(dt, lang="es-es", use_24hour=True, use_ampm=False),
            "las doce quince")

        dt = datetime.datetime(2017, 1, 31, 19, 40, 49)
        self.assertEqual(nice_time(dt, lang="es-es"), "las ocho menos veinte")
        self.assertEqual(nice_time(dt, lang="es-es", use_ampm=True),
                         "las ocho menos veinte de la tarde")
        self.assertEqual(nice_time(dt, lang="es-es", speech=False), "7:40")
        self.assertEqual(
            nice_time(dt, lang="es-es", speech=False, use_ampm=True),
            "7:40 PM")
        self.assertEqual(
            nice_time(dt, lang="es-es", speech=False, use_24hour=True),
            "19:40")
        self.assertEqual(
            nice_time(dt,
                      lang="es-es",
                      speech=False,
                      use_24hour=True,
                      use_ampm=True), "19:40")
        self.assertEqual(
            nice_time(dt, lang="es-es", use_24hour=True, use_ampm=True),
            "las diecinueve cuarenta")
        self.assertEqual(
            nice_time(dt, lang="es-es", use_24hour=True, use_ampm=False),
            "las diecinueve cuarenta")

        dt = datetime.datetime(2017, 1, 31, 1, 15, 00)
        self.assertEqual(nice_time(dt, lang="es-es", use_24hour=True),
                         "la una quince")

        dt = datetime.datetime(2017, 1, 31, 1, 35, 00)
        self.assertEqual(nice_time(dt, lang="es-es"),
                         "las dos menos veinticinco")

        dt = datetime.datetime(2017, 1, 31, 1, 45, 00)
        self.assertEqual(nice_time(dt, lang="es-es"), "las dos menos cuarto")

        dt = datetime.datetime(2017, 1, 31, 4, 50, 00)
        self.assertEqual(nice_time(dt, lang="es-es"), "las cinco menos diez")

        dt = datetime.datetime(2017, 1, 31, 5, 55, 00)
        self.assertEqual(nice_time(dt, lang="es-es"), "las seis menos cinco")

        dt = datetime.datetime(2017, 1, 31, 5, 30, 00)
        self.assertEqual(nice_time(dt, lang="es-es", use_ampm=True),
                         "las cinco y media de la madrugada")

        dt = datetime.datetime(2017, 1, 31, 23, 15, 9)
        self.assertEqual(
            nice_time(dt, lang="es-es", use_24hour=True, use_ampm=True),
            "las veintitrés quince")
        self.assertEqual(
            nice_time(dt, lang="es-es", use_24hour=False, use_ampm=True),
            "las once y cuarto de la noche")
Exemplo n.º 35
0
    def test_convert_times(self):
        dt = datetime.datetime(2017, 1, 31, 13, 22, 3)

        # Verify defaults haven't changed
        self.assertEqual(nice_time(dt, lang="it-it"),
                         nice_time(dt, "it-it", True, False, False))

        self.assertEqual(nice_time(dt, lang="it"), "una e ventidue")
        self.assertEqual(nice_time(dt, lang="it", use_ampm=True),
                         "una e ventidue del pomeriggio")
        self.assertEqual(nice_time(dt, lang="it", speech=False), "1:22")
        self.assertEqual(nice_time(dt, lang="it", speech=False, use_ampm=True),
                         "1:22 PM")
        self.assertEqual(
            nice_time(dt, lang="it", speech=False, use_24hour=True), "13:22")
        self.assertEqual(
            nice_time(dt,
                      lang="it",
                      speech=False,
                      use_24hour=True,
                      use_ampm=True), "13:22")
        self.assertEqual(
            nice_time(dt, lang="it", use_24hour=True, use_ampm=True),
            "tredici e ventidue")
        self.assertEqual(
            nice_time(dt, lang="it", use_24hour=True, use_ampm=False),
            "tredici e ventidue")
        # Verifica fasce orarie use_ampm = True
        d_time = datetime.datetime(2017, 1, 31, 8, 22, 3)
        self.assertEqual(nice_time(d_time, lang="it", use_ampm=True),
                         "otto e ventidue della mattina")
        d_time = datetime.datetime(2017, 1, 31, 20, 22, 3)
        self.assertEqual(nice_time(d_time, lang="it", use_ampm=True),
                         "otto e ventidue della sera")
        d_time = datetime.datetime(2017, 1, 31, 23, 22, 3)
        self.assertEqual(nice_time(d_time, lang="it", use_ampm=True),
                         "undici e ventidue della notte")
        d_time = datetime.datetime(2017, 1, 31, 00, 00, 3)
        self.assertEqual(nice_time(d_time, lang="it", use_ampm=True),
                         "mezzanotte")
        d_time = datetime.datetime(2017, 1, 31, 12, 00, 3)
        self.assertEqual(nice_time(d_time, lang="it", use_ampm=True),
                         "mezzogiorno")
        dt = datetime.datetime(2017, 1, 31, 13, 0, 3)
        self.assertEqual(nice_time(dt, lang="it"), "una in punto")
        self.assertEqual(nice_time(dt, lang="it", use_ampm=True),
                         "una del pomeriggio")
        self.assertEqual(nice_time(dt, lang="it", speech=False), "1:00")
        self.assertEqual(nice_time(dt, lang="it", speech=False, use_ampm=True),
                         "1:00 PM")
        self.assertEqual(
            nice_time(dt, lang="it", speech=False, use_24hour=True), "13:00")
        self.assertEqual(
            nice_time(dt,
                      lang="it",
                      speech=False,
                      use_24hour=True,
                      use_ampm=True), "13:00")
        self.assertEqual(
            nice_time(dt, lang="it", use_24hour=True, use_ampm=True),
            "tredici e zerozero")
        self.assertEqual(
            nice_time(dt, lang="it", use_24hour=True, use_ampm=False),
            "tredici e zerozero")

        dt = datetime.datetime(2017, 1, 31, 13, 2, 3)
        self.assertEqual(nice_time(dt, lang="it", use_24hour=True),
                         "tredici e zero due")
        self.assertEqual(nice_time(dt, lang="it", use_ampm=True),
                         "una e zero due del pomeriggio")
        self.assertEqual(nice_time(dt, lang="it", speech=False), "1:02")
        self.assertEqual(nice_time(dt, lang="it", speech=False, use_ampm=True),
                         "1:02 PM")
        self.assertEqual(
            nice_time(dt, lang="it", speech=False, use_24hour=True), "13:02")
        self.assertEqual(
            nice_time(dt,
                      lang="it",
                      speech=False,
                      use_24hour=True,
                      use_ampm=True), "13:02")
        self.assertEqual(
            nice_time(dt, lang="it", use_24hour=True, use_ampm=True),
            "tredici e zero due")
        self.assertEqual(
            nice_time(dt, lang="it", use_24hour=True, use_ampm=False),
            "tredici e zero due")

        dt = datetime.datetime(2017, 1, 31, 0, 2, 3)
        self.assertEqual(nice_time(dt, lang="it"), "mezzanotte e zero due")
        self.assertEqual(nice_time(dt, lang="it", use_ampm=True),
                         "mezzanotte e zero due")
        self.assertEqual(nice_time(dt, lang="it", speech=False), "12:02")
        self.assertEqual(nice_time(dt, lang="it", speech=False, use_ampm=True),
                         "12:02 AM")
        self.assertEqual(
            nice_time(dt, lang="it", speech=False, use_24hour=True), "00:02")
        self.assertEqual(
            nice_time(dt,
                      lang="it",
                      speech=False,
                      use_24hour=True,
                      use_ampm=True), "00:02")
        self.assertEqual(
            nice_time(dt, lang="it", use_24hour=True, use_ampm=True),
            "zerozero e zero due")
        self.assertEqual(
            nice_time(dt, lang="it", use_24hour=True, use_ampm=False),
            "zerozero e zero due")
        # casi particolari
        d_time = datetime.datetime(2017, 1, 31, 1, 2, 3)
        self.assertEqual(
            nice_time(d_time, lang="it", use_24hour=True, use_ampm=True),
            "una e zero due")
        d_time = datetime.datetime(2017, 1, 31, 2, 2, 3)
        self.assertEqual(
            nice_time(d_time, lang="it", use_24hour=True, use_ampm=False),
            "zero due e zero due")
        d_time = datetime.datetime(2017, 1, 31, 10, 15, 0)
        self.assertEqual(
            nice_time(d_time, lang="it", use_24hour=False, use_ampm=False),
            "dieci e un quarto")
        d_time = datetime.datetime(2017, 1, 31, 22, 45, 0)
        self.assertEqual(
            nice_time(d_time, lang="it", use_24hour=False, use_ampm=False),
            "dieci e tre quarti")
Exemplo n.º 36
0
    def test_convert_times_nl(self):
        dt = datetime.datetime(2017, 1, 31,
                               13, 22, 3)

        self.assertEqual(nice_time(dt, lang="nl-nl"),
                         u"tweeentwintig over één")
        self.assertEqual(nice_time(dt, lang="nl-nl", use_ampm=True),
                         u"tweeentwintig over één 's middags")
        self.assertEqual(nice_time(dt, lang="nl-nl", speech=False),
                         "1:22")
        self.assertEqual(nice_time(dt, lang="nl-nl", speech=False,
                                   use_ampm=True),
                         "1:22 PM")
        self.assertEqual(nice_time(dt, lang="nl-nl", speech=False,
                                   use_24hour=True),
                         "13:22")
        self.assertEqual(nice_time(dt, lang="nl-nl", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "13:22")
        self.assertEqual(nice_time(dt, lang="nl-nl", use_24hour=True,
                                   use_ampm=True),
                         "dertien uur tweeentwintig")
        self.assertEqual(nice_time(dt, lang="nl-nl", use_24hour=True,
                                   use_ampm=False),
                         "dertien uur tweeentwintig")

        dt = datetime.datetime(2017, 1, 31,
                               13, 0, 3)
        self.assertEqual(nice_time(dt, lang="nl-nl"),
                         u"één uur")
        self.assertEqual(nice_time(dt, lang="nl-nl", use_ampm=True),
                         u"één uur 's middags")
        self.assertEqual(nice_time(dt, lang="nl-nl", speech=False),
                         "1:00")
        self.assertEqual(nice_time(dt, lang="nl-nl", speech=False,
                                   use_ampm=True),
                         "1:00 PM")
        self.assertEqual(nice_time(dt, lang="nl-nl", speech=False,
                                   use_24hour=True),
                         "13:00")
        self.assertEqual(nice_time(dt, lang="nl-nl", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "13:00")
        self.assertEqual(nice_time(dt, lang="nl-nl", use_24hour=True,
                                   use_ampm=True),
                         "dertien uur")
        self.assertEqual(nice_time(dt, lang="nl-nl", use_24hour=True,
                                   use_ampm=False),
                         "dertien uur")

        dt = datetime.datetime(2017, 1, 31,
                               13, 2, 3)
        self.assertEqual(nice_time(dt, lang="nl-nl"),
                         u"twee over één")
        self.assertEqual(nice_time(dt, lang="nl-nl", use_ampm=True),
                         u"twee over één 's middags")
        self.assertEqual(nice_time(dt, lang="nl-nl", speech=False),
                         "1:02")
        self.assertEqual(nice_time(dt, lang="nl-nl", speech=False,
                                   use_ampm=True),
                         "1:02 PM")
        self.assertEqual(nice_time(dt, lang="nl-nl", speech=False,
                                   use_24hour=True),
                         "13:02")
        self.assertEqual(nice_time(dt, lang="nl-nl", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "13:02")
        self.assertEqual(nice_time(dt, lang="nl-nl", use_24hour=True,
                                   use_ampm=True),
                         "dertien uur twee")
        self.assertEqual(nice_time(dt, lang="nl-nl", use_24hour=True,
                                   use_ampm=False),
                         "dertien uur twee")

        dt = datetime.datetime(2017, 1, 31,
                               0, 2, 3)
        self.assertEqual(nice_time(dt, lang="nl-nl"),
                         "twee over twaalf")
        self.assertEqual(nice_time(dt, lang="nl-nl", use_ampm=True),
                         "twee over twaalf 's nachts")
        self.assertEqual(nice_time(dt, lang="nl-nl", speech=False),
                         "12:02")
        self.assertEqual(nice_time(dt, lang="nl-nl", speech=False,
                                   use_ampm=True),
                         "12:02 AM")
        self.assertEqual(nice_time(dt, lang="nl-nl", speech=False,
                                   use_24hour=True),
                         "00:02")
        self.assertEqual(nice_time(dt, lang="nl-nl", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "00:02")
        self.assertEqual(nice_time(dt, lang="nl-nl", use_24hour=True,
                                   use_ampm=True),
                         "nul uur twee")
        self.assertEqual(nice_time(dt, lang="nl-nl", use_24hour=True,
                                   use_ampm=False),
                         "nul uur twee")

        dt = datetime.datetime(2017, 1, 31,
                               12, 15, 9)
        self.assertEqual(nice_time(dt, lang="nl-nl"),
                         "kwart over twaalf")
        self.assertEqual(nice_time(dt, lang="nl-nl", use_ampm=True),
                         "kwart over twaalf 's middags")
        self.assertEqual(nice_time(dt, lang="nl-nl", speech=False),
                         "12:15")
        self.assertEqual(nice_time(dt, lang="nl-nl", speech=False,
                                   use_ampm=True),
                         "12:15 PM")
        self.assertEqual(nice_time(dt, lang="nl-nl", speech=False,
                                   use_24hour=True),
                         "12:15")
        self.assertEqual(nice_time(dt, lang="nl-nl", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "12:15")
        self.assertEqual(nice_time(dt, lang="nl-nl", use_24hour=True,
                                   use_ampm=True),
                         "twaalf uur vijftien")
        self.assertEqual(nice_time(dt, lang="nl-nl", use_24hour=True,
                                   use_ampm=False),
                         "twaalf uur vijftien")

        dt = datetime.datetime(2017, 1, 31,
                               19, 40, 49)
        self.assertEqual(nice_time(dt, lang="nl-nl"),
                         "twintig voor acht")
        self.assertEqual(nice_time(dt, lang="nl-nl", use_ampm=True),
                         "twintig voor acht 's avonds")
        self.assertEqual(nice_time(dt, lang="nl-nl", speech=False),
                         "7:40")
        self.assertEqual(nice_time(dt, lang="nl-nl", speech=False,
                                   use_ampm=True),
                         "7:40 PM")
        self.assertEqual(nice_time(dt, lang="nl-nl", speech=False,
                                   use_24hour=True),
                         "19:40")
        self.assertEqual(nice_time(dt, lang="nl-nl", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "19:40")
        self.assertEqual(nice_time(dt, lang="nl-nl", use_24hour=True,
                                   use_ampm=True),
                         "negentien uur veertig")
        self.assertEqual(nice_time(dt, lang="nl-nl", use_24hour=True,
                                   use_ampm=False),
                         "negentien uur veertig")

        dt = datetime.datetime(2017, 1, 31,
                               1, 15, 00)
        self.assertEqual(nice_time(dt, lang="nl-nl", use_24hour=True),
                         u"één uur vijftien")

        dt = datetime.datetime(2017, 1, 31,
                               1, 35, 00)
        self.assertEqual(nice_time(dt, lang="nl-nl"),
                         u"vijfentwintig voor twee")

        dt = datetime.datetime(2017, 1, 31,
                               1, 45, 00)
        self.assertEqual(nice_time(dt, lang="nl-nl"),
                         u"kwart voor twee")

        dt = datetime.datetime(2017, 1, 31,
                               4, 50, 00)
        self.assertEqual(nice_time(dt, lang="nl-nl"),
                         u"tien voor vijf")

        dt = datetime.datetime(2017, 1, 31,
                               5, 55, 00)
        self.assertEqual(nice_time(dt, lang="nl-nl"),
                         "vijf voor zes")

        dt = datetime.datetime(2017, 1, 31,
                               5, 30, 00)
        self.assertEqual(nice_time(dt, lang="nl-nl", use_ampm=True),
                         u"half zes 's nachts")
Exemplo n.º 37
0
    def test_convert_times(self):
        dt = datetime.datetime(2017, 1, 31, 13, 22, 3)

        # Verify defaults haven't changed
        self.assertEqual(nice_time(dt, lang="it-it"),
                         nice_time(dt, "it-it", True, False, False))

        self.assertEqual(nice_time(dt, lang="it"), "una e ventidue")
        self.assertEqual(nice_time(dt, lang="it", use_ampm=True),
                         "una e ventidue del pomeriggio")
        self.assertEqual(nice_time(dt, lang="it", speech=False), "1:22")
        self.assertEqual(nice_time(dt, lang="it", speech=False, use_ampm=True),
                         "1:22 PM")
        self.assertEqual(
            nice_time(dt, lang="it", speech=False, use_24hour=True), "13:22")
        self.assertEqual(
            nice_time(dt,
                      lang="it",
                      speech=False,
                      use_24hour=True,
                      use_ampm=True), "13:22")
        self.assertEqual(
            nice_time(dt, lang="it", use_24hour=True, use_ampm=True),
            "tredici e ventidue")
        self.assertEqual(
            nice_time(dt, lang="it", use_24hour=True, use_ampm=False),
            "tredici e ventidue")

        dt = datetime.datetime(2017, 1, 31, 13, 0, 3)
        self.assertEqual(nice_time(dt, lang="it"), "una in punto")
        self.assertEqual(nice_time(dt, lang="it", use_ampm=True),
                         "una del pomeriggio")
        self.assertEqual(nice_time(dt, lang="it", speech=False), "1:00")
        self.assertEqual(nice_time(dt, lang="it", speech=False, use_ampm=True),
                         "1:00 PM")
        self.assertEqual(
            nice_time(dt, lang="it", speech=False, use_24hour=True), "13:00")
        self.assertEqual(
            nice_time(dt,
                      lang="it",
                      speech=False,
                      use_24hour=True,
                      use_ampm=True), "13:00")
        self.assertEqual(
            nice_time(dt, lang="it", use_24hour=True, use_ampm=True),
            "tredici e zerozero")
        self.assertEqual(
            nice_time(dt, lang="it", use_24hour=True, use_ampm=False),
            "tredici e zerozero")

        dt = datetime.datetime(2017, 1, 31, 13, 2, 3)
        self.assertEqual(nice_time(dt, lang="it", use_24hour=True),
                         "tredici e zero due")
        self.assertEqual(nice_time(dt, lang="it", use_ampm=True),
                         "una e zero due del pomeriggio")
        self.assertEqual(nice_time(dt, lang="it", speech=False), "1:02")
        self.assertEqual(nice_time(dt, lang="it", speech=False, use_ampm=True),
                         "1:02 PM")
        self.assertEqual(
            nice_time(dt, lang="it", speech=False, use_24hour=True), "13:02")
        self.assertEqual(
            nice_time(dt,
                      lang="it",
                      speech=False,
                      use_24hour=True,
                      use_ampm=True), "13:02")
        self.assertEqual(
            nice_time(dt, lang="it", use_24hour=True, use_ampm=True),
            "tredici e zero due")
        self.assertEqual(
            nice_time(dt, lang="it", use_24hour=True, use_ampm=False),
            "tredici e zero due")

        dt = datetime.datetime(2017, 1, 31, 0, 2, 3)
        self.assertEqual(nice_time(dt, lang="it"), "mezzanotte e zero due")
        self.assertEqual(nice_time(dt, lang="it", use_ampm=True),
                         "mezzanotte e zero due")
        self.assertEqual(nice_time(dt, lang="it", speech=False), "12:02")
        self.assertEqual(nice_time(dt, lang="it", speech=False, use_ampm=True),
                         "12:02 AM")
        self.assertEqual(
            nice_time(dt, lang="it", speech=False, use_24hour=True), "00:02")
        self.assertEqual(
            nice_time(dt,
                      lang="it",
                      speech=False,
                      use_24hour=True,
                      use_ampm=True), "00:02")
        self.assertEqual(
            nice_time(dt, lang="it", use_24hour=True, use_ampm=True),
            "zerozero e zero due")
        self.assertEqual(
            nice_time(dt, lang="it", use_24hour=True, use_ampm=False),
            "zerozero e zero due")
Exemplo n.º 38
0
    def test_convert_times_hu(self):
        dt = datetime.datetime(2017, 1, 31,
                               13, 22, 3)

        self.assertEqual(nice_time(dt, lang="hu-hu"),
                         "egy óra huszonkettő")
        self.assertEqual(nice_time(dt, lang="hu-hu", use_ampm=True),
                         "délután egy óra huszonkettő")
        self.assertEqual(nice_time(dt, lang="hu-hu", speech=False),
                         "1:22")
        self.assertEqual(nice_time(dt, lang="hu-hu", speech=False,
                                   use_ampm=True),
                         "1:22 PM")
        self.assertEqual(nice_time(dt, lang="hu-hu", speech=False,
                                   use_24hour=True),
                         "13:22")
        self.assertEqual(nice_time(dt, lang="hu-hu", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "13:22")
        self.assertEqual(nice_time(dt, lang="hu-hu", use_24hour=True,
                                   use_ampm=True),
                         "tizenhárom óra huszonkettő")
        self.assertEqual(nice_time(dt, lang="hu-hu", use_24hour=True,
                                   use_ampm=False),
                         "tizenhárom óra huszonkettő")

        dt = datetime.datetime(2017, 1, 31,
                               13, 0, 3)
        self.assertEqual(nice_time(dt, lang="hu-hu"),
                         "egy óra")
        self.assertEqual(nice_time(dt, lang="hu-hu", use_ampm=True),
                         "délután egy óra")
        self.assertEqual(nice_time(dt, lang="hu-hu", speech=False),
                         "1:00")
        self.assertEqual(nice_time(dt, lang="hu-hu", speech=False,
                                   use_ampm=True),
                         "1:00 PM")
        self.assertEqual(nice_time(dt, lang="hu-hu", speech=False,
                                   use_24hour=True),
                         "13:00")
        self.assertEqual(nice_time(dt, lang="hu-hu", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "13:00")
        self.assertEqual(nice_time(dt, lang="hu-hu", use_24hour=True,
                                   use_ampm=True),
                         "tizenhárom óra")
        self.assertEqual(nice_time(dt, lang="hu-hu", use_24hour=True,
                                   use_ampm=False),
                         "tizenhárom óra")

        dt = datetime.datetime(2017, 1, 31,
                               13, 2, 3)
        self.assertEqual(nice_time(dt, lang="hu-hu"),
                         "egy óra kettő")
        self.assertEqual(nice_time(dt, lang="hu-hu", use_ampm=True),
                         "délután egy óra kettő")
        self.assertEqual(nice_time(dt, lang="hu-hu", speech=False),
                         "1:02")
        self.assertEqual(nice_time(dt, lang="hu-hu", speech=False,
                                   use_ampm=True),
                         "1:02 PM")
        self.assertEqual(nice_time(dt, lang="hu-hu", speech=False,
                                   use_24hour=True),
                         "13:02")
        self.assertEqual(nice_time(dt, lang="hu-hu", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "13:02")
        self.assertEqual(nice_time(dt, lang="hu-hu", use_24hour=True,
                                   use_ampm=True),
                         "tizenhárom óra kettő")
        self.assertEqual(nice_time(dt, lang="hu-hu", use_24hour=True,
                                   use_ampm=False),
                         "tizenhárom óra kettő")

        dt = datetime.datetime(2017, 1, 31,
                               0, 2, 3)
        self.assertEqual(nice_time(dt, lang="hu-hu"),
                         "tizenkét óra kettő")
        self.assertEqual(nice_time(dt, lang="hu-hu", use_ampm=True),
                         "éjjel tizenkét óra kettő")
        self.assertEqual(nice_time(dt, lang="hu-hu", speech=False),
                         "12:02")
        self.assertEqual(nice_time(dt, lang="hu-hu", speech=False,
                                   use_ampm=True),
                         "12:02 AM")
        self.assertEqual(nice_time(dt, lang="hu-hu", speech=False,
                                   use_24hour=True),
                         "00:02")
        self.assertEqual(nice_time(dt, lang="hu-hu", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "00:02")
        self.assertEqual(nice_time(dt, lang="hu-hu", use_24hour=True,
                                   use_ampm=True),
                         "nulla óra kettő")
        self.assertEqual(nice_time(dt, lang="hu-hu", use_24hour=True,
                                   use_ampm=False),
                         "nulla óra kettő")

        dt = datetime.datetime(2017, 1, 31,
                               12, 15, 9)
        self.assertEqual(nice_time(dt, lang="hu-hu"),
                         "tizenkét óra tizenöt")
        self.assertEqual(nice_time(dt, lang="hu-hu", use_ampm=True),
                         "délután tizenkét óra tizenöt")
        self.assertEqual(nice_time(dt, lang="hu-hu", speech=False),
                         "12:15")
        self.assertEqual(nice_time(dt, lang="hu-hu", speech=False,
                                   use_ampm=True),
                         "12:15 PM")
        self.assertEqual(nice_time(dt, lang="hu-hu", speech=False,
                                   use_24hour=True),
                         "12:15")
        self.assertEqual(nice_time(dt, lang="hu-hu", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "12:15")
        self.assertEqual(nice_time(dt, lang="hu-hu", use_24hour=True,
                                   use_ampm=True),
                         "tizenkét óra tizenöt")
        self.assertEqual(nice_time(dt, lang="hu-hu", use_24hour=True,
                                   use_ampm=False),
                         "tizenkét óra tizenöt")

        dt = datetime.datetime(2017, 1, 31,
                               19, 40, 49)
        self.assertEqual(nice_time(dt, lang="hu-hu"),
                         "hét óra negyven")
        self.assertEqual(nice_time(dt, lang="hu-hu", use_ampm=True),
                         "este hét óra negyven")
        self.assertEqual(nice_time(dt, lang="hu-hu", speech=False),
                         "7:40")
        self.assertEqual(nice_time(dt, lang="hu-hu", speech=False,
                                   use_ampm=True),
                         "7:40 PM")
        self.assertEqual(nice_time(dt, lang="hu-hu", speech=False,
                                   use_24hour=True),
                         "19:40")
        self.assertEqual(nice_time(dt, lang="hu-hu", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "19:40")
        self.assertEqual(nice_time(dt, lang="hu-hu", use_24hour=True,
                                   use_ampm=True),
                         "tizenkilenc óra negyven")
        self.assertEqual(nice_time(dt, lang="hu-hu", use_24hour=True,
                                   use_ampm=False),
                         "tizenkilenc óra negyven")

        dt = datetime.datetime(2017, 1, 31,
                               1, 15, 00)
        self.assertEqual(nice_time(dt, lang="hu-hu", use_24hour=True),
                         "egy óra tizenöt")

        dt = datetime.datetime(2017, 1, 31,
                               1, 35, 00)
        self.assertEqual(nice_time(dt, lang="hu-hu"),
                         "egy óra harmincöt")

        dt = datetime.datetime(2017, 1, 31,
                               1, 45, 00)
        self.assertEqual(nice_time(dt, lang="hu-hu"),
                         "egy óra negyvenöt")

        dt = datetime.datetime(2017, 1, 31,
                               4, 50, 00)
        self.assertEqual(nice_time(dt, lang="hu-hu"),
                         "négy óra ötven")

        dt = datetime.datetime(2017, 1, 31,
                               5, 55, 00)
        self.assertEqual(nice_time(dt, lang="hu-hu"),
                         "öt óra ötvenöt")

        dt = datetime.datetime(2017, 1, 31,
                               5, 30, 00)
        self.assertEqual(nice_time(dt, lang="hu-hu", use_ampm=True),
                         "reggel öt óra harminc")
Exemplo n.º 39
0
    def test_convert_times(self):
        dt = datetime.datetime(2017, 1, 31,
                               13, 22, 3)

        # Verify defaults haven't changed
        self.assertEqual(nice_time(dt, lang="es-es"),
                         nice_time(dt, "es-es", True, False, False))

        self.assertEqual(nice_time(dt, lang="es"),
                         "la una y veintidós")
        self.assertEqual(nice_time(dt, lang="es", use_ampm=True),
                         "la una y veintidós de la tarde")
        self.assertEqual(nice_time(dt, lang="es", speech=False), "1:22")
        self.assertEqual(nice_time(dt, lang="es", speech=False,
                                   use_ampm=True), "1:22 PM")
        self.assertEqual(nice_time(dt, lang="es", speech=False,
                                   use_24hour=True), "13:22")
        self.assertEqual(nice_time(dt, lang="es", speech=False,
                                   use_24hour=True, use_ampm=True), "13:22")
        self.assertEqual(nice_time(dt, lang="es", use_24hour=True,
                                   use_ampm=True), "las trece veintidós")
        self.assertEqual(nice_time(dt, lang="es", use_24hour=True,
                                   use_ampm=False), "las trece veintidós")

        dt = datetime.datetime(2017, 1, 31,
                               13, 0, 3)
        self.assertEqual(nice_time(dt, lang="es"),
                         "la una en punto")
        self.assertEqual(nice_time(dt, lang="es", use_ampm=True),
                         "la una de la tarde")
        self.assertEqual(nice_time(dt, lang="es", speech=False),
                         "1:00")
        self.assertEqual(nice_time(dt, lang="es", speech=False,
                                   use_ampm=True), "1:00 PM")
        self.assertEqual(nice_time(dt, lang="es", speech=False,
                                   use_24hour=True), "13:00")
        self.assertEqual(nice_time(dt, lang="es", speech=False,
                                   use_24hour=True, use_ampm=True), "13:00")
        self.assertEqual(nice_time(dt, lang="es", use_24hour=True,
                                   use_ampm=True), "las trece cero cero")
        dt = datetime.datetime(2017, 1, 31,
                               13, 2, 3)
        self.assertEqual(nice_time(dt, lang="es", use_24hour=True),
                         "las trece cero dos")
        self.assertEqual(nice_time(dt, lang="es", use_ampm=True),
                         "la una y dos de la tarde")
        self.assertEqual(nice_time(dt, lang="es", speech=False),
                         "1:02")
        self.assertEqual(nice_time(dt, lang="es", speech=False,
                                   use_ampm=True), "1:02 PM")
        self.assertEqual(nice_time(dt, lang="es", speech=False,
                                   use_24hour=True), "13:02")
        self.assertEqual(nice_time(dt, lang="es", speech=False,
                                   use_24hour=True, use_ampm=True), "13:02")
        self.assertEqual(nice_time(dt, lang="es", use_24hour=True,
                                   use_ampm=True), "las trece cero dos")
        self.assertEqual(nice_time(dt, lang="es", use_24hour=True,
                                   use_ampm=False), "las trece cero dos")

        dt = datetime.datetime(2017, 1, 31,
                               0, 2, 3)
        self.assertEqual(nice_time(dt, lang="es"),
                         "las doce y dos")
        self.assertEqual(nice_time(dt, lang="es", use_ampm=True),
                         "las doce y dos de la madrugada")
        self.assertEqual(nice_time(dt, lang="es", use_24hour=True),
                         "las cero cero dos")
        self.assertEqual(nice_time(dt, lang="es", speech=False),
                         "12:02")
        self.assertEqual(nice_time(dt, lang="es", speech=False,
                                   use_ampm=True), "12:02 AM")
        self.assertEqual(nice_time(dt, lang="es", speech=False,
                                   use_24hour=True), "00:02")
        self.assertEqual(nice_time(dt, lang="es", speech=False,
                                   use_24hour=True,
                                   use_ampm=True), "00:02")
        self.assertEqual(nice_time(dt, lang="es", use_24hour=True,
                                   use_ampm=True), "las cero cero dos")
        self.assertEqual(nice_time(dt, lang="es", use_24hour=True,
                                   use_ampm=False), "las cero cero dos")

        dt = datetime.datetime(2017, 1, 31,
                               12, 15, 9)
        self.assertEqual(nice_time(dt, lang="es-es"),
                         "las doce y cuarto")
        self.assertEqual(nice_time(dt, lang="es-es", use_ampm=True),
                         "las doce y cuarto de la mañana")
        self.assertEqual(nice_time(dt, lang="es-es", speech=False),
                         "12:15")
        self.assertEqual(nice_time(dt, lang="es-es", speech=False,
                                   use_ampm=True),
                         "12:15 PM")
        self.assertEqual(nice_time(dt, lang="es-es", speech=False,
                                   use_24hour=True),
                         "12:15")
        self.assertEqual(nice_time(dt, lang="es-es", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "12:15")
        self.assertEqual(nice_time(dt, lang="es-es", use_24hour=True,
                                   use_ampm=True),
                         "las doce quince")
        self.assertEqual(nice_time(dt, lang="es-es", use_24hour=True,
                                   use_ampm=False),
                         "las doce quince")

        dt = datetime.datetime(2017, 1, 31,
                               19, 40, 49)
        self.assertEqual(nice_time(dt, lang="es-es"),
                         "las ocho menos veinte")
        self.assertEqual(nice_time(dt, lang="es-es", use_ampm=True),
                         "las ocho menos veinte de la tarde")
        self.assertEqual(nice_time(dt, lang="es-es", speech=False),
                         "7:40")
        self.assertEqual(nice_time(dt, lang="es-es", speech=False,
                                   use_ampm=True),
                         "7:40 PM")
        self.assertEqual(nice_time(dt, lang="es-es", speech=False,
                                   use_24hour=True),
                         "19:40")
        self.assertEqual(nice_time(dt, lang="es-es", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "19:40")
        self.assertEqual(nice_time(dt, lang="es-es", use_24hour=True,
                                   use_ampm=True),
                         "las diecinueve cuarenta")
        self.assertEqual(nice_time(dt, lang="es-es", use_24hour=True,
                                   use_ampm=False),
                         "las diecinueve cuarenta")

        dt = datetime.datetime(2017, 1, 31,
                               1, 15, 00)
        self.assertEqual(nice_time(dt, lang="es-es", use_24hour=True),
                         "la una quince")

        dt = datetime.datetime(2017, 1, 31,
                               1, 35, 00)
        self.assertEqual(nice_time(dt, lang="es-es"),
                         "las dos menos veinticinco")

        dt = datetime.datetime(2017, 1, 31,
                               1, 45, 00)
        self.assertEqual(nice_time(dt, lang="es-es"),
                         "las dos menos cuarto")

        dt = datetime.datetime(2017, 1, 31,
                               4, 50, 00)
        self.assertEqual(nice_time(dt, lang="es-es"),
                         "las cinco menos diez")

        dt = datetime.datetime(2017, 1, 31,
                               5, 55, 00)
        self.assertEqual(nice_time(dt, lang="es-es"),
                         "las seis menos cinco")

        dt = datetime.datetime(2017, 1, 31,
                               5, 30, 00)
        self.assertEqual(nice_time(dt, lang="es-es", use_ampm=True),
                         "las cinco y media de la madrugada")

        dt = datetime.datetime(2017, 1, 31,
                               23, 15, 9)
        self.assertEqual(nice_time(dt, lang="es-es", use_24hour=True,
                                   use_ampm=True),
                         "las veintitrés quince")
        self.assertEqual(nice_time(dt, lang="es-es", use_24hour=False,
                                   use_ampm=True),
                         "las once y cuarto de la noche")
Exemplo n.º 40
0
    def test_convert_times_de(self):
        dt = datetime.datetime(2017, 1, 31,
                               13, 22, 3)

        self.assertEqual(nice_time(dt, lang="de-de"),
                         "ein Uhr zweiundzwanzig")
        self.assertEqual(nice_time(dt, lang="de-de", use_ampm=True),
                         "ein Uhr zweiundzwanzig nachmittags")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False),
                         "1:22")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False,
                                   use_ampm=True),
                         "1:22 PM")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False,
                                   use_24hour=True),
                         "13:22")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "13:22")
        self.assertEqual(nice_time(dt, lang="de-de", use_24hour=True,
                                   use_ampm=True),
                         "dreizehn Uhr zweiundzwanzig")
        self.assertEqual(nice_time(dt, lang="de-de", use_24hour=True,
                                   use_ampm=False),
                         "dreizehn Uhr zweiundzwanzig")

        dt = datetime.datetime(2017, 1, 31,
                               13, 0, 3)
        self.assertEqual(nice_time(dt, lang="de-de"),
                         "ein Uhr")
        self.assertEqual(nice_time(dt, lang="de-de", use_ampm=True),
                         "ein Uhr nachmittags")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False),
                         "1:00")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False,
                                   use_ampm=True),
                         "1:00 PM")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False,
                                   use_24hour=True),
                         "13:00")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "13:00")
        self.assertEqual(nice_time(dt, lang="de-de", use_24hour=True,
                                   use_ampm=True),
                         "dreizehn Uhr")
        self.assertEqual(nice_time(dt, lang="de-de", use_24hour=True,
                                   use_ampm=False),
                         "dreizehn Uhr")

        dt = datetime.datetime(2017, 1, 31,
                               13, 2, 3)
        self.assertEqual(nice_time(dt, lang="de-de"),
                         "ein Uhr zwei")
        self.assertEqual(nice_time(dt, lang="de-de", use_ampm=True),
                         "ein Uhr zwei nachmittags")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False),
                         "1:02")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False,
                                   use_ampm=True),
                         "1:02 PM")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False,
                                   use_24hour=True),
                         "13:02")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "13:02")
        self.assertEqual(nice_time(dt, lang="de-de", use_24hour=True,
                                   use_ampm=True),
                         "dreizehn Uhr zwei")
        self.assertEqual(nice_time(dt, lang="de-de", use_24hour=True,
                                   use_ampm=False),
                         "dreizehn Uhr zwei")

        dt = datetime.datetime(2017, 1, 31,
                               0, 2, 3)
        self.assertEqual(nice_time(dt, lang="de-de"),
                         u"zwölf Uhr zwei")
        self.assertEqual(nice_time(dt, lang="de-de", use_ampm=True),
                         u"zwölf Uhr zwei nachts")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False),
                         "12:02")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False,
                                   use_ampm=True),
                         "12:02 AM")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False,
                                   use_24hour=True),
                         "00:02")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "00:02")
        self.assertEqual(nice_time(dt, lang="de-de", use_24hour=True,
                                   use_ampm=True),
                         "null Uhr zwei")
        self.assertEqual(nice_time(dt, lang="de-de", use_24hour=True,
                                   use_ampm=False),
                         "null Uhr zwei")

        dt = datetime.datetime(2017, 1, 31,
                               12, 15, 9)
        self.assertEqual(nice_time(dt, lang="de-de"),
                         u"zwölf Uhr fünfzehn")
        self.assertEqual(nice_time(dt, lang="de-de", use_ampm=True),
                         u"zwölf Uhr fünfzehn nachmittags")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False),
                         "12:15")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False,
                                   use_ampm=True),
                         "12:15 PM")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False,
                                   use_24hour=True),
                         "12:15")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "12:15")
        self.assertEqual(nice_time(dt, lang="de-de", use_24hour=True,
                                   use_ampm=True),
                         u"zwölf Uhr fünfzehn")
        self.assertEqual(nice_time(dt, lang="de-de", use_24hour=True,
                                   use_ampm=False),
                         u"zwölf Uhr fünfzehn")

        dt = datetime.datetime(2017, 1, 31,
                               19, 40, 49)
        self.assertEqual(nice_time(dt, lang="de-de"),
                         "sieben Uhr vierzig")
        self.assertEqual(nice_time(dt, lang="de-de", use_ampm=True),
                         "sieben Uhr vierzig abends")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False),
                         "7:40")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False,
                                   use_ampm=True),
                         "7:40 PM")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False,
                                   use_24hour=True),
                         "19:40")
        self.assertEqual(nice_time(dt, lang="de-de", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "19:40")
        self.assertEqual(nice_time(dt, lang="de-de", use_24hour=True,
                                   use_ampm=True),
                         "neunzehn Uhr vierzig")
        self.assertEqual(nice_time(dt, lang="de-de", use_24hour=True,
                                   use_ampm=False),
                         "neunzehn Uhr vierzig")

        dt = datetime.datetime(2017, 1, 31,
                               1, 15, 00)
        self.assertEqual(nice_time(dt, lang="de-de", use_24hour=True),
                         u"ein Uhr fünfzehn")

        dt = datetime.datetime(2017, 1, 31,
                               1, 35, 00)
        self.assertEqual(nice_time(dt, lang="de-de"),
                         u"ein Uhr fünfunddreißig")

        dt = datetime.datetime(2017, 1, 31,
                               1, 45, 00)
        self.assertEqual(nice_time(dt, lang="de-de"),
                         u"ein Uhr fünfundvierzig")

        dt = datetime.datetime(2017, 1, 31,
                               4, 50, 00)
        self.assertEqual(nice_time(dt, lang="de-de"),
                         u"vier Uhr fünfzig")

        dt = datetime.datetime(2017, 1, 31,
                               5, 55, 00)
        self.assertEqual(nice_time(dt, lang="de-de"),
                         u"fünf Uhr fünfundfünfzig")

        dt = datetime.datetime(2017, 1, 31,
                               5, 30, 00)
        self.assertEqual(nice_time(dt, lang="de-de", use_ampm=True),
                         u"fünf Uhr dreißig morgens")
Exemplo n.º 41
0
    def test_convert_times_fr(self):
        dt = datetime.datetime(2017, 1, 31,
                               13, 22, 3)

        self.assertEqual(nice_time(dt, lang="fr-fr"),
                         "une heure vingt-deux")
        self.assertEqual(nice_time(dt, lang="fr-fr", use_ampm=True),
                         "une heure vingt-deux de l'après-midi")
        self.assertEqual(nice_time(dt, lang="fr-fr", speech=False),
                         "1:22")
        self.assertEqual(nice_time(dt, lang="fr-fr", speech=False,
                                   use_ampm=True),
                         "1:22 PM")
        self.assertEqual(nice_time(dt, lang="fr-fr", speech=False,
                                   use_24hour=True),
                         "13:22")
        self.assertEqual(nice_time(dt, lang="fr-fr", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "13:22")
        self.assertEqual(nice_time(dt, lang="fr-fr", use_24hour=True,
                                   use_ampm=True),
                         "treize heures vingt-deux")
        self.assertEqual(nice_time(dt, lang="fr-fr", use_24hour=True,
                                   use_ampm=False),
                         "treize heures vingt-deux")

        dt = datetime.datetime(2017, 1, 31,
                               13, 0, 3)
        self.assertEqual(nice_time(dt, lang="fr-fr"),
                         "une heure")
        self.assertEqual(nice_time(dt, lang="fr-fr", use_ampm=True),
                         "une heure de l'après-midi")
        self.assertEqual(nice_time(dt, lang="fr-fr", speech=False),
                         "1:00")
        self.assertEqual(nice_time(dt, lang="fr-fr", speech=False,
                                   use_ampm=True),
                         "1:00 PM")
        self.assertEqual(nice_time(dt, lang="fr-fr", speech=False,
                                   use_24hour=True),
                         "13:00")
        self.assertEqual(nice_time(dt, lang="fr-fr", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "13:00")
        self.assertEqual(nice_time(dt, lang="fr-fr", use_24hour=True,
                                   use_ampm=True),
                         "treize heures")
        self.assertEqual(nice_time(dt, lang="fr-fr", use_24hour=True,
                                   use_ampm=False),
                         "treize heures")

        dt = datetime.datetime(2017, 1, 31,
                               13, 2, 3)
        self.assertEqual(nice_time(dt, lang="fr-fr"),
                         "une heure deux")
        self.assertEqual(nice_time(dt, lang="fr-fr", use_ampm=True),
                         "une heure deux de l'après-midi")
        self.assertEqual(nice_time(dt, lang="fr-fr", speech=False),
                         "1:02")
        self.assertEqual(nice_time(dt, lang="fr-fr", speech=False,
                                   use_ampm=True),
                         "1:02 PM")
        self.assertEqual(nice_time(dt, lang="fr-fr", speech=False,
                                   use_24hour=True),
                         "13:02")
        self.assertEqual(nice_time(dt, lang="fr-fr", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "13:02")
        self.assertEqual(nice_time(dt, lang="fr-fr", use_24hour=True,
                                   use_ampm=True),
                         "treize heures deux")
        self.assertEqual(nice_time(dt, lang="fr-fr", use_24hour=True,
                                   use_ampm=False),
                         "treize heures deux")

        dt = datetime.datetime(2017, 1, 31,
                               0, 2, 3)
        self.assertEqual(nice_time(dt, lang="fr-fr"),
                         "minuit deux")
        self.assertEqual(nice_time(dt, lang="fr-fr", use_ampm=True),
                         "minuit deux")
        self.assertEqual(nice_time(dt, lang="fr-fr", speech=False),
                         "12:02")
        self.assertEqual(nice_time(dt, lang="fr-fr", speech=False,
                                   use_ampm=True),
                         "12:02 AM")
        self.assertEqual(nice_time(dt, lang="fr-fr", speech=False,
                                   use_24hour=True),
                         "00:02")
        self.assertEqual(nice_time(dt, lang="fr-fr", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "00:02")
        self.assertEqual(nice_time(dt, lang="fr-fr", use_24hour=True,
                                   use_ampm=True),
                         "minuit deux")
        self.assertEqual(nice_time(dt, lang="fr-fr", use_24hour=True,
                                   use_ampm=False),
                         "minuit deux")

        dt = datetime.datetime(2017, 1, 31,
                               12, 15, 9)
        self.assertEqual(nice_time(dt, lang="fr-fr"),
                         "midi et quart")
        self.assertEqual(nice_time(dt, lang="fr-fr", use_ampm=True),
                         "midi et quart")
        self.assertEqual(nice_time(dt, lang="fr-fr", speech=False),
                         "12:15")
        self.assertEqual(nice_time(dt, lang="fr-fr", speech=False,
                                   use_ampm=True),
                         "12:15 PM")
        self.assertEqual(nice_time(dt, lang="fr-fr", speech=False,
                                   use_24hour=True),
                         "12:15")
        self.assertEqual(nice_time(dt, lang="fr-fr", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "12:15")
        self.assertEqual(nice_time(dt, lang="fr-fr", use_24hour=True,
                                   use_ampm=True),
                         "midi quinze")
        self.assertEqual(nice_time(dt, lang="fr-fr", use_24hour=True,
                                   use_ampm=False),
                         "midi quinze")

        dt = datetime.datetime(2017, 1, 31,
                               19, 40, 49)
        self.assertEqual(nice_time(dt, lang="fr-fr"),
                         "huit heures moins vingt")
        self.assertEqual(nice_time(dt, lang="fr-fr", use_ampm=True),
                         "huit heures moins vingt du soir")
        self.assertEqual(nice_time(dt, lang="fr-fr", speech=False),
                         "7:40")
        self.assertEqual(nice_time(dt, lang="fr-fr", speech=False,
                                   use_ampm=True),
                         "7:40 PM")
        self.assertEqual(nice_time(dt, lang="fr-fr", speech=False,
                                   use_24hour=True),
                         "19:40")
        self.assertEqual(nice_time(dt, lang="fr-fr", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "19:40")
        self.assertEqual(nice_time(dt, lang="fr-fr", use_24hour=True,
                                   use_ampm=True),
                         "dix-neuf heures quarante")
        self.assertEqual(nice_time(dt, lang="fr-fr", use_24hour=True,
                                   use_ampm=False),
                         "dix-neuf heures quarante")

        dt = datetime.datetime(2017, 1, 31,
                               1, 15, 00)
        self.assertEqual(nice_time(dt, lang="fr-fr", use_24hour=True),
                         "une heure quinze")

        dt = datetime.datetime(2017, 1, 31,
                               1, 35, 00)
        self.assertEqual(nice_time(dt, lang="fr-fr"),
                         "deux heures moins vingt-cinq")

        dt = datetime.datetime(2017, 1, 31,
                               1, 45, 00)
        self.assertEqual(nice_time(dt, lang="fr-fr"),
                         "deux heures moins le quart")

        dt = datetime.datetime(2017, 1, 31,
                               4, 50, 00)
        self.assertEqual(nice_time(dt, lang="fr-fr"),
                         "cinq heures moins dix")

        dt = datetime.datetime(2017, 1, 31,
                               5, 55, 00)
        self.assertEqual(nice_time(dt, lang="fr-fr"),
                         "six heures moins cinq")

        dt = datetime.datetime(2017, 1, 31,
                               5, 30, 00)
        self.assertEqual(nice_time(dt, lang="fr-fr", use_ampm=True),
                         "cinq heures et demi du matin")
Exemplo n.º 42
0
    def test_convert_times_sv(self):
        dt = datetime.datetime(2017, 1, 31, 13, 22, 3)

        self.assertEqual(nice_time(dt, lang="sv-se"),
                         "tjugotvå minuter över ett")
        self.assertEqual(nice_time(dt, lang="sv-se", use_ampm=True),
                         "tjugotvå minuter över ett på eftermiddagen")
        self.assertEqual(nice_time(dt, lang="sv-se", speech=False),
                         "01:22")
        self.assertEqual(nice_time(dt, lang="sv-se", speech=False,
                                   use_ampm=True),
                         "01:22 PM")
        self.assertEqual(nice_time(dt, lang="sv-se",
                                   speech=False, use_24hour=True),
                         "13:22")
        self.assertEqual(nice_time(dt, lang="sv-se", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "13:22")
        self.assertEqual(nice_time(dt, lang="sv-se", use_24hour=True,
                                   use_ampm=True),
                         "tretton tjugotvå")
        self.assertEqual(nice_time(dt, lang="sv-se", use_24hour=True,
                                   use_ampm=False),
                         "tretton tjugotvå")

        dt = datetime.datetime(2017, 1, 31, 13, 0, 3)
        self.assertEqual(nice_time(dt, lang="sv-se"), "ett")
        self.assertEqual(nice_time(dt, lang="sv-se", use_ampm=True),
                         "ett på eftermiddagen")
        self.assertEqual(nice_time(dt, lang="sv-se", speech=False),
                         "01:00")
        self.assertEqual(nice_time(dt, lang="sv-se", speech=False,
                                   use_ampm=True),
                         "01:00 PM")
        self.assertEqual(nice_time(dt, lang="sv-se", speech=False,
                                   use_24hour=True),
                         "13:00")
        self.assertEqual(nice_time(dt, lang="sv-se", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "13:00")
        self.assertEqual(nice_time(dt, lang="sv-se", use_24hour=True,
                                   use_ampm=True),
                         "tretton")
        self.assertEqual(nice_time(dt, lang="sv-se", use_24hour=True,
                                   use_ampm=False),
                         "tretton")

        dt = datetime.datetime(2017, 1, 31, 13, 2, 3)
        self.assertEqual(nice_time(dt, lang="sv-se"), "två minuter över ett")
        self.assertEqual(nice_time(dt, lang="sv-se", use_ampm=True),
                         "två minuter över ett på eftermiddagen")
        self.assertEqual(nice_time(dt, lang="sv-se", speech=False),
                         "01:02")
        self.assertEqual(nice_time(dt, lang="sv-se", speech=False,
                                   use_ampm=True),
                         "01:02 PM")
        self.assertEqual(nice_time(dt, lang="sv-se", speech=False,
                                   use_24hour=True),
                         "13:02")
        self.assertEqual(nice_time(dt, lang="sv-se", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "13:02")
        self.assertEqual(nice_time(dt, lang="sv-se", use_24hour=True,
                                   use_ampm=True),
                         "tretton noll två")
        self.assertEqual(nice_time(dt, lang="sv-se", use_24hour=True,
                                   use_ampm=False),
                         "tretton noll två")

        dt = datetime.datetime(2017, 1, 31, 0, 2, 3)
        self.assertEqual(nice_time(dt, lang="sv-se"), "två minuter över tolv")
        self.assertEqual(nice_time(dt, lang="sv-se", use_ampm=True),
                         "två minuter över tolv på natten")
        self.assertEqual(nice_time(dt, lang="sv-se", speech=False),
                         "12:02")
        self.assertEqual(nice_time(dt, lang="sv-se", speech=False,
                                   use_ampm=True),
                         "12:02 AM")
        self.assertEqual(nice_time(dt, lang="sv-se", speech=False,
                                   use_24hour=True),
                         "00:02")
        self.assertEqual(nice_time(dt, lang="sv-se", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "00:02")
        self.assertEqual(nice_time(dt, lang="sv-se", use_24hour=True,
                                   use_ampm=True),
                         "noll noll två")
        self.assertEqual(nice_time(dt, lang="sv-se", use_24hour=True,
                                   use_ampm=False),
                         "noll noll två")

        dt = datetime.datetime(2017, 1, 31, 12, 15, 9)
        self.assertEqual(nice_time(dt, lang="sv-se"), "kvart över tolv")
        self.assertEqual(nice_time(dt, lang="sv-se", use_ampm=True),
                         "kvart över tolv på eftermiddagen")
        self.assertEqual(nice_time(dt, lang="sv-se", speech=False),
                         "12:15")
        self.assertEqual(nice_time(dt, lang="sv-se", speech=False,
                                   use_ampm=True),
                         "12:15 PM")
        self.assertEqual(nice_time(dt, lang="sv-se", speech=False,
                                   use_24hour=True),
                         "12:15")
        self.assertEqual(nice_time(dt, lang="sv-se", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "12:15")
        self.assertEqual(nice_time(dt, lang="sv-se", use_24hour=True,
                                   use_ampm=True),
                         "tolv femton")
        self.assertEqual(nice_time(dt, lang="sv-se", use_24hour=True,
                                   use_ampm=False),
                         "tolv femton")

        dt = datetime.datetime(2017, 1, 31, 19, 40, 49)
        self.assertEqual(nice_time(dt, lang="sv-se"), "tjugo minuter i åtta")
        self.assertEqual(nice_time(dt, lang="sv-se", use_ampm=True),
                         "tjugo minuter i åtta på kvällen")
        self.assertEqual(nice_time(dt, lang="sv-se", speech=False),
                         "07:40")
        self.assertEqual(nice_time(dt, lang="sv-se", speech=False,
                                   use_ampm=True),
                         "07:40 PM")
        self.assertEqual(nice_time(dt, lang="sv-se", speech=False,
                                   use_24hour=True),
                         "19:40")
        self.assertEqual(nice_time(dt, lang="sv-se", speech=False,
                                   use_24hour=True, use_ampm=True),
                         "19:40")
        self.assertEqual(nice_time(dt, lang="sv-se", use_24hour=True,
                                   use_ampm=True),
                         "nitton fyrtio")
        self.assertEqual(nice_time(dt, lang="sv-se", use_24hour=True,
                                   use_ampm=False),
                         "nitton fyrtio")

        dt = datetime.datetime(2017, 1, 31, 1, 15, 00)
        self.assertEqual(nice_time(dt, lang="sv-se", use_24hour=True),
                         "ett femton")

        dt = datetime.datetime(2017, 1, 31, 1, 35, 00)
        self.assertEqual(nice_time(dt, lang="sv-se"),
                         "tjugofem minuter i två")

        dt = datetime.datetime(2017, 1, 31, 1, 45, 00)
        self.assertEqual(nice_time(dt, lang="sv-se"), "kvart i två")

        dt = datetime.datetime(2017, 1, 31, 4, 50, 00)
        self.assertEqual(nice_time(dt, lang="sv-se"), "tio i fem")

        dt = datetime.datetime(2017, 1, 31, 5, 55, 00)
        self.assertEqual(nice_time(dt, lang="sv-se"), "fem i sex")

        dt = datetime.datetime(2017, 1, 31, 5, 30, 00)
        self.assertEqual(nice_time(dt, lang="sv-se", use_ampm=True),
                         "halv sex på morgonen")
Exemplo n.º 43
0
    def test_pm(self):
        dt = datetime.datetime(2017, 1, 31,
                               13, 22, 3)

        # Verify defaults haven't changed
        self.assertEqual(nice_time(dt, lang="pt-pt"),
                         nice_time(dt, "pt-pt", True, False, False))

        self.assertEqual(nice_time(dt, lang="pt"),
                         "uma e vinte e dois")
        self.assertEqual(nice_time(dt, lang="pt", use_ampm=True),
                         "uma e vinte e dois da tarde")
        self.assertEqual(nice_time(dt, lang="pt", speech=False), "1:22")
        self.assertEqual(nice_time(dt, lang="pt", speech=False,
                                   use_ampm=True), "1:22 PM")
        self.assertEqual(nice_time(dt, lang="pt", speech=False,
                                   use_24hour=True), "13:22")
        self.assertEqual(nice_time(dt, lang="pt", speech=False,
                                   use_24hour=True, use_ampm=True), "13:22")
        self.assertEqual(nice_time(dt, lang="pt", use_24hour=True,
                                   use_ampm=True), "treze e vinte e dois")
        self.assertEqual(nice_time(dt, lang="pt", use_24hour=True,
                                   use_ampm=False), "treze e vinte e dois")

        dt = datetime.datetime(2017, 1, 31,
                               13, 0, 3)
        self.assertEqual(nice_time(dt, lang="pt"),
                         "uma em ponto")
        self.assertEqual(nice_time(dt, lang="pt", use_ampm=True),
                         "uma da tarde")
        self.assertEqual(nice_time(dt, lang="pt", speech=False),
                         "1:00")
        self.assertEqual(nice_time(dt, lang="pt", speech=False,
                                   use_ampm=True), "1:00 PM")
        self.assertEqual(nice_time(dt, lang="pt", speech=False,
                                   use_24hour=True), "13:00")
        self.assertEqual(nice_time(dt, lang="pt", speech=False,
                                   use_24hour=True, use_ampm=True), "13:00")
        self.assertEqual(nice_time(dt, lang="pt", use_24hour=True,
                                   use_ampm=True), "treze")
        dt = datetime.datetime(2017, 1, 31,
                               13, 2, 3)
        self.assertEqual(nice_time(dt, lang="pt", use_24hour=True),
                         "treze e dois")
        self.assertEqual(nice_time(dt, lang="pt", use_ampm=True),
                         "uma e dois da tarde")
        self.assertEqual(nice_time(dt, lang="pt", speech=False),
                         "1:02")
        self.assertEqual(nice_time(dt, lang="pt", speech=False,
                                   use_ampm=True), "1:02 PM")
        self.assertEqual(nice_time(dt, lang="pt", speech=False,
                                   use_24hour=True), "13:02")
        self.assertEqual(nice_time(dt, lang="pt", speech=False,
                                   use_24hour=True, use_ampm=True), "13:02")
        self.assertEqual(nice_time(dt, lang="pt", use_24hour=True,
                                   use_ampm=True), "treze e dois")
        self.assertEqual(nice_time(dt, lang="pt", use_24hour=True,
                                   use_ampm=False), "treze e dois")
Exemplo n.º 44
0
    def test_convert_times(self):
        dt = datetime.datetime(2017, 1, 31,
                               13, 22, 3)

        # Verify defaults haven't changed
        self.assertEqual(nice_time(dt, lang="it-it"),
                         nice_time(dt, "it-it", True, False, False))

        self.assertEqual(nice_time(dt, lang="it"),
                         "una e ventidue")
        self.assertEqual(nice_time(dt, lang="it", use_ampm=True),
                         "una e ventidue del pomeriggio")
        self.assertEqual(nice_time(dt, lang="it", speech=False), "1:22")
        self.assertEqual(nice_time(dt, lang="it", speech=False,
                                   use_ampm=True), "1:22 PM")
        self.assertEqual(nice_time(dt, lang="it", speech=False,
                                   use_24hour=True), "13:22")
        self.assertEqual(nice_time(dt, lang="it", speech=False,
                                   use_24hour=True, use_ampm=True), "13:22")
        self.assertEqual(nice_time(dt, lang="it", use_24hour=True,
                                   use_ampm=True), "tredici e ventidue")
        self.assertEqual(nice_time(dt, lang="it", use_24hour=True,
                                   use_ampm=False), "tredici e ventidue")

        dt = datetime.datetime(2017, 1, 31,
                               13, 0, 3)
        self.assertEqual(nice_time(dt, lang="it"),
                         "una in punto")
        self.assertEqual(nice_time(dt, lang="it", use_ampm=True),
                         "una del pomeriggio")
        self.assertEqual(nice_time(dt, lang="it", speech=False),
                         "1:00")
        self.assertEqual(nice_time(dt, lang="it", speech=False,
                                   use_ampm=True), "1:00 PM")
        self.assertEqual(nice_time(dt, lang="it", speech=False,
                                   use_24hour=True), "13:00")
        self.assertEqual(nice_time(dt, lang="it", speech=False,
                                   use_24hour=True, use_ampm=True), "13:00")
        self.assertEqual(nice_time(dt, lang="it", use_24hour=True,
                                   use_ampm=True), "tredici e zerozero")
        self.assertEqual(nice_time(dt, lang="it", use_24hour=True,
                                   use_ampm=False), "tredici e zerozero")

        dt = datetime.datetime(2017, 1, 31,
                               13, 2, 3)
        self.assertEqual(nice_time(dt, lang="it", use_24hour=True),
                         "tredici e zero due")
        self.assertEqual(nice_time(dt, lang="it", use_ampm=True),
                         "una e zero due del pomeriggio")
        self.assertEqual(nice_time(dt, lang="it", speech=False),
                         "1:02")
        self.assertEqual(nice_time(dt, lang="it", speech=False,
                                   use_ampm=True), "1:02 PM")
        self.assertEqual(nice_time(dt, lang="it", speech=False,
                                   use_24hour=True), "13:02")
        self.assertEqual(nice_time(dt, lang="it", speech=False,
                                   use_24hour=True, use_ampm=True), "13:02")
        self.assertEqual(nice_time(dt, lang="it", use_24hour=True,
                                   use_ampm=True), "tredici e zero due")
        self.assertEqual(nice_time(dt, lang="it", use_24hour=True,
                                   use_ampm=False), "tredici e zero due")

        dt = datetime.datetime(2017, 1, 31,
                               0, 2, 3)
        self.assertEqual(nice_time(dt, lang="it"),
                         "mezzanotte e zero due")
        self.assertEqual(nice_time(dt, lang="it", use_ampm=True),
                         "mezzanotte e zero due")
        self.assertEqual(nice_time(dt, lang="it", speech=False),
                         "12:02")
        self.assertEqual(nice_time(dt, lang="it", speech=False,
                                   use_ampm=True), "12:02 AM")
        self.assertEqual(nice_time(dt, lang="it", speech=False,
                                   use_24hour=True), "00:02")
        self.assertEqual(nice_time(dt, lang="it", speech=False,
                                   use_24hour=True,
                                   use_ampm=True), "00:02")
        self.assertEqual(nice_time(dt, lang="it", use_24hour=True,
                                   use_ampm=True), "zerozero e zero due")
        self.assertEqual(nice_time(dt, lang="it", use_24hour=True,
                                   use_ampm=False), "zerozero e zero due")