How to use the datetime.date.fromordinal function in DateTime

To help you get started, we’ve selected a few DateTime examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github IronLanguages / ironpython2 / Tests / modules / misc / test_datetime.py View on Github external
#strftime
        self.assertEqual(x.strftime("%y-%a-%b"), "05-Tue-Mar")
        self.assertEqual(x.strftime("%Y-%A-%B"), "2005-Tuesday-March")
        self.assertEqual(x.strftime("%Y%m%d"), '20050322')

        #timetuple
        self.assertEqual(datetime.date(2005, 3, 22).timetuple(), (2005, 3, 22, 0, 0, 0, 1, 81, -1))

        #toordinal
        self.assertEqual(datetime.date(2005, 3, 22).toordinal(), 732027)

        #weekday
        self.assertEqual(datetime.date(2005, 3, 22).weekday(), 1)

        #fromordinal
        x = datetime.date.fromordinal(1234567)
        self.assertEqual(x.year, 3381)
        self.assertEqual(x.month, 2)
        self.assertEqual(x.day, 16)

        #fromtimestamp
        x = datetime.date.fromtimestamp(1000000000.0)
        self.assertEqual(x.year, 2001)
        self.assertEqual(x.month, 9)
        self.assertTrue(x.day == 8 or x.day == 9) # depends on the time zone

        #max
        x = datetime.date.max
        self.assertEqual(x.year, 9999)
        self.assertEqual(x.month, 12)
        self.assertEqual(x.day, 31)
github james-owen-ryan / talktown-testbed / game.py View on Github external
def get_date(self, ordinal_date=None):
        """Return a pretty-printed date for ordinal date."""
        if not ordinal_date:
            ordinal_date = self.ordinal_date
        year = datetime.date.fromordinal(ordinal_date).year
        month = datetime.date.fromordinal(ordinal_date).month
        day = datetime.date.fromordinal(ordinal_date).day
        month_ordinals_to_names = {
            1: "January", 2: "February", 3: "March", 4: "April", 5: "May", 6: "June", 7: "July",
            8: "August", 9: "September", 10: "October", 11: "November", 12: "December"
        }
        date = "{} of {} {}, {}".format(
            # Note: for retconning, the time of day will always be whatever the actual time of day
            # is at the beginning of the true simulation ("day", I assume), but this shouldn't matter
            self.time_of_day.title(), month_ordinals_to_names[month], day, year
        )
        return date
github chrthomsen / pygrametl / pygrametl / __init__.py View on Github external
(year, month, day) = fromdate.split('-')
    fromdate = date(int(year), int(month), int(day))

    (year, month, day) = todate.split('-')
    todate = date(int(year), int(month), int(day))

    start = fromdate.toordinal()
    if not fromdateincl:
        start += 1

    end = todate.toordinal()
    if todateincl:
        end += 1

    for i in range(start, end):
        d = date.fromordinal(i)
        res = {}
        res[key] = int(d.strftime('%Y%m%d'))
        for (att, attformat) in strings.iteritems():
            res[att] = d.strftime(attformat)
        for (att, attformat) in ints.iteritems():
            res[att] = int(d.strftime(attformat))
        if expander is not None:
            expander(d, res)
        yield res
github devconfcz / devconfcz / bin / typeform.py View on Github external
def _convert_datetime(dt):
    dt_format = '%Y-%m-%d'

    if dt == 'today':
        dt = str(datetime.date.today())
    elif dt == 'yesterday':
        dt = str(
            datetime.date.fromordinal(datetime.date.today().toordinal() - 1))

    epoch = time.mktime(time.strptime(dt, dt_format))

    return int(epoch)
github pymedusa / Medusa / medusa / tv / episode.py View on Github external
)
            return

        if self.location:
            log.debug(
                '{id}: {series} {ep} status is {status!r}. Location: {location}', {
                    'id': self.series.series_id,
                    'series': self.series.name,
                    'ep': episode_num(season, episode),
                    'status': statusStrings[self.status].upper(),
                    'location': self.location,
                }
            )

        if not os.path.isfile(self.location):
            if (self.airdate >= date.today() or self.airdate == date.fromordinal(1)) and \
                    self.status in (UNAIRED, UNKNOWN, WANTED):
                # Need to check if is UNAIRED otherwise code will step into second 'IF'
                # and make episode as default_ep_status
                # If is a leaked episode and user manually snatched, it will respect status
                # If is a fake (manually snatched), when user set as FAILED, status will be WANTED
                # and code below will make it UNAIRED again
                self.status = UNAIRED
                log.debug(
                    '{id}: {series} {ep} airs in the future or has no air date, marking it {status}', {
                        'id': self.series.series_id,
                        'series': self.series.name,
                        'ep': episode_num(season, episode),
                        'status': statusStrings[self.status].upper(),
                    }
                )
            elif self.status in (UNAIRED, UNKNOWN):
github lino-framework / lino / obsolete / src / lino / adamo / qtconn.py View on Github external
def day(s):
    d=datetime.date.fromordinal(s)
    return d.day
github pymedusa / Medusa / sickbeard / tv.py View on Github external
# get latest aired episode to compare against today - graceperiod and today + graceperiod
        main_db_con = db.DBConnection()
        sql_result = main_db_con.select(
            b'SELECT '
            b'  IFNULL(MAX(airdate), 0) as last_aired '
            b'FROM '
            b'  tv_episodes '
            b'WHERE '
            b'  showid = ? '
            b'  AND season > 0 '
            b'  AND airdate > 1 '
            b'  AND status > 1',
            [self.indexerid])

        if sql_result and sql_result[0][b'last_aired'] != 0:
            last_airdate = datetime.date.fromordinal(sql_result[0][b'last_aired'])
            if (update_date - graceperiod) <= last_airdate <= (update_date + graceperiod):
                return True

        # get next upcoming UNAIRED episode to compare against today + graceperiod
        sql_result = main_db_con.select(
            b'SELECT '
            b'  IFNULL(MIN(airdate), 0) as airing_next '
            b'FROM '
            b'  tv_episodes '
            b'WHERE '
            b'  showid = ? '
            b'  AND season > 0 '
            b'  AND airdate > 1 '
            b'  AND status = 1',
            [self.indexerid])
github pymedusa / Medusa / medusa / metadata / mede8er.py View on Github external
except (IndexerEpisodeNotFound, IndexerSeasonNotFound):
                log.info(
                    'Unable to find episode {ep_num} on {indexer}...'
                    ' has it been removed? Should I delete from db?', {
                        'ep_num': episode_num(ep_to_write.season, ep_to_write.episode),
                        'indexer': indexerApi(ep_obj.series.indexer).name,
                    }
                )
                return None

            if ep_to_write == ep_obj:
                # root (or single) episode

                # default to today's date for specials if firstaired is not set
                if ep_to_write.season == 0 and not getattr(my_ep, 'firstaired', None):
                    my_ep['firstaired'] = text_type(datetime.date.fromordinal(1))

                if not (getattr(my_ep, 'episodename', None) and getattr(my_ep, 'firstaired', None)):
                    return None

                episode = movie

                if ep_to_write.name:
                    episode_name = etree.SubElement(episode, 'title')
                    episode_name.text = ep_to_write.name

                season_number = etree.SubElement(episode, 'season')
                season_number.text = text_type(ep_to_write.season)

                episode_number = etree.SubElement(episode, 'episode')
                episode_number.text = text_type(ep_to_write.episode)
github pymedusa / Medusa / medusa / tv / series.py View on Github external
b'  IFNULL(MIN(airdate), 0) as airing_next '
            b'FROM '
            b'  tv_episodes '
            b'WHERE '
            b'  showid = ? '
            b'  AND season > 0 '
            b'  AND airdate > 1 '
            b'  AND status = 1',
            [self.series_id])

        if sql_result and sql_result[0][b'airing_next'] != 0:
            next_airdate = datetime.date.fromordinal(sql_result[0][b'airing_next'])
            if next_airdate <= (update_date + graceperiod):
                return True

        last_update_indexer = datetime.date.fromordinal(self.last_update_indexer)

        # in the first year after ended (last airdate), update every 30 days
        if (update_date - last_airdate) < datetime.timedelta(days=450) and (
                (update_date - last_update_indexer) > datetime.timedelta(days=30)):
            return True

        return False
github midgetspy / Sick-Beard / sickbeard / tv.py View on Github external
raise exceptions.MultipleDBEpisodesException("Your DB has two records for the same show somehow.")
        elif len(sqlResults) == 0:
            logger.log(str(self.show.tvdbid) + ": Episode " + str(self.season) + "x" + str(self.episode) + " not found in the database", logger.DEBUG)
            return False
        else:
            #NAMEIT logger.log(u"AAAAA from" + str(self.season)+"x"+str(self.episode) + " -" + self.name + " to " + str(sqlResults[0]["name"]))
            if sqlResults[0]["name"] != None:
                self.name = sqlResults[0]["name"]
            self.season = season
            self.episode = episode
            if sqlResults[0]["absolute_episode"] != None:
                self.absolute_episode = int(sqlResults[0]["absolute_episode"])
            self.description = sqlResults[0]["description"]
            if self.description == None:
                self.description = ""
            self.airdate = datetime.date.fromordinal(int(sqlResults[0]["airdate"]))
            #logger.log(u"1 Status changes from " + str(self.status) + " to " + str(sqlResults[0]["status"]), logger.DEBUG)
            self.status = int(sqlResults[0]["status"])

            # don't overwrite my location
            if sqlResults[0]["location"] != "" and sqlResults[0]["location"] != None:
                self.location = os.path.normpath(sqlResults[0]["location"])

            self.tvdbid = int(sqlResults[0]["tvdbid"])

            return True