當前位置: 首頁>>代碼示例>>Python>>正文


Python pendulum.today方法代碼示例

本文整理匯總了Python中pendulum.today方法的典型用法代碼示例。如果您正苦於以下問題:Python pendulum.today方法的具體用法?Python pendulum.today怎麽用?Python pendulum.today使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pendulum的用法示例。


在下文中一共展示了pendulum.today方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: is_anniversary

# 需要導入模塊: import pendulum [as 別名]
# 或者: from pendulum import today [as 別名]
def is_anniversary(self, dt=None):
        """
        Check if its the anniversary.

        Compares the date/month values of the two dates.

        :rtype: bool
        """
        if dt is None:
            dt = Date.today()

        instance = self.__class__(dt.year, dt.month, dt.day)

        return (self.month, self.day) == (instance.month, instance.day)

    # the additional method for checking if today is the anniversary day
    # the alias is provided to start using a new name and keep the backward compatibility
    # the old name can be completely replaced with the new in one of the future versions 
開發者ID:sdispater,項目名稱:pendulum,代碼行數:20,代碼來源:date.py

示例2: test_diff_for_humans_other_and_month

# 需要導入模塊: import pendulum [as 別名]
# 或者: from pendulum import today [as 別名]
def test_diff_for_humans_other_and_month():
    with pendulum.test(pendulum.datetime(2016, 3, 1)):
        today = pendulum.today().date()

        assert "4 weeks before" == today.diff_for_humans(today.add(weeks=4))
        assert "1 month before" == today.diff_for_humans(today.add(months=1))

    with pendulum.test(pendulum.datetime(2017, 3, 31)):
        today = pendulum.today().date()

        assert "1 month before" == today.diff_for_humans(today.add(months=1))

    with pendulum.test(pendulum.datetime(2017, 4, 30)):
        today = pendulum.today().date()

        assert "1 month before" == today.diff_for_humans(today.add(months=1))

    with pendulum.test(pendulum.datetime(2017, 1, 31)):
        today = pendulum.today().date()

        assert "1 month before" == today.diff_for_humans(today.add(weeks=4)) 
開發者ID:sdispater,項目名稱:pendulum,代碼行數:23,代碼來源:test_diff.py

示例3: __init__

# 需要導入模塊: import pendulum [as 別名]
# 或者: from pendulum import today [as 別名]
def __init__(self, irc):
        self.__parent = super(CFB, self)
        self.__parent.__init__(irc)

        self.SCOREBOARD = (
            "http://site.api.espn.com/apis/site/v2/sports/"
            "football/college-football/scoreboard"
        )

        self.FUZZY_DAYS = [
            "yesterday",
            "tonight",
            "today",
            "tomorrow",
            "sun",
            "mon",
            "tue",
            "wed",
            "thu",
            "fri",
            "sat",
        ]

        self._current_week = 0
        self._cfb_byes = {}

        with open(
            "{0}/abbrv.json".format(os.path.dirname(os.path.abspath(__file__))), "r"
        ) as json_file:
            self.abbrv = json.load(json_file)

        if not self.abbrv:
            self.abbrv = requests.get(
                "https://raw.githubusercontent.com/diagonalfish/FootballBotX2/master/abbrv.json"
            )
            self.abbrv = json.loads(self.abbrv.content) 
開發者ID:oddluck,項目名稱:limnoria-plugins,代碼行數:38,代碼來源:plugin.py

示例4: cfb

# 需要導入模塊: import pendulum [as 別名]
# 或者: from pendulum import today [as 別名]
def cfb(self, irc, msg, args, optlist, team=None):
        """[--conf #] [--week #] [<team>]
        Fetches CFB Scores. Defaults to current week and AP Top 25 teams.
        Use --conf # (ESPN league #) to fetch a specific conference.
        Use --week # to look up a specific week.
        """

        optlist = dict(optlist)
        week = optlist.get("week")
        conf = optlist.get("conf")
        games = None

        team = self._parseInput(team)

        if (conf == 80 or conf == 81 or conf == 35) and not team:
            irc.reply("ERROR: You must provide a team")
            return

        if week or conf or team == "today":
            games = self._fetchGames(team, conf, week)

        if not games:
            games = self._fetchGames(team, conf)
            if not games:
                irc.reply("No games found")
                return

        games = self._parseGames(games, team)
        games = self._sortGames(games)

        reply_string = self._replyAsString(team, games)

        reply = " | ".join(reply_string)
        irc.reply(reply, prefixNick=False) 
開發者ID:oddluck,項目名稱:limnoria-plugins,代碼行數:36,代碼來源:plugin.py

示例5: test_days_ago

# 需要導入模塊: import pendulum [as 別名]
# 或者: from pendulum import today [as 別名]
def test_days_ago(self):
        today = pendulum.today()
        today_midnight = pendulum.instance(datetime.fromordinal(today.date().toordinal()))

        self.assertTrue(dates.days_ago(0) == today_midnight)

        self.assertTrue(dates.days_ago(100) == today_midnight + timedelta(days=-100))

        self.assertTrue(dates.days_ago(0, hour=3) == today_midnight + timedelta(hours=3))
        self.assertTrue(dates.days_ago(0, minute=3) == today_midnight + timedelta(minutes=3))
        self.assertTrue(dates.days_ago(0, second=3) == today_midnight + timedelta(seconds=3))
        self.assertTrue(dates.days_ago(0, microsecond=3) == today_midnight + timedelta(microseconds=3)) 
開發者ID:apache,項目名稱:airflow,代碼行數:14,代碼來源:test_dates.py

示例6: is_future

# 需要導入模塊: import pendulum [as 別名]
# 或者: from pendulum import today [as 別名]
def is_future(self):
        """
        Determines if the instance is in the future, ie. greater than now.

        :rtype: bool
        """
        return self > self.today() 
開發者ID:sdispater,項目名稱:pendulum,代碼行數:9,代碼來源:date.py

示例7: is_past

# 需要導入模塊: import pendulum [as 別名]
# 或者: from pendulum import today [as 別名]
def is_past(self):
        """
        Determines if the instance is in the past, ie. less than now.

        :rtype: bool
        """
        return self < self.today() 
開發者ID:sdispater,項目名稱:pendulum,代碼行數:9,代碼來源:date.py

示例8: diff

# 需要導入模塊: import pendulum [as 別名]
# 或者: from pendulum import today [as 別名]
def diff(self, dt=None, abs=True):
        """
        Returns the difference between two Date objects as a Period.

        :type dt: Date or None

        :param abs: Whether to return an absolute interval or not
        :type abs: bool

        :rtype: Period
        """
        if dt is None:
            dt = self.today()

        return Period(self, Date(dt.year, dt.month, dt.day), absolute=abs) 
開發者ID:sdispater,項目名稱:pendulum,代碼行數:17,代碼來源:date.py

示例9: diff_for_humans

# 需要導入模塊: import pendulum [as 別名]
# 或者: from pendulum import today [as 別名]
def diff_for_humans(self, other=None, absolute=False, locale=None):
        """
        Get the difference in a human readable format in the current locale.

        When comparing a value in the past to default now:
        1 day ago
        5 months ago

        When comparing a value in the future to default now:
        1 day from now
        5 months from now

        When comparing a value in the past to another value:
        1 day before
        5 months before

        When comparing a value in the future to another value:
        1 day after
        5 months after

        :type other: Date

        :param absolute: removes time difference modifiers ago, after, etc
        :type absolute: bool

        :param locale: The locale to use for localization
        :type locale: str

        :rtype: str
        """
        is_now = other is None

        if is_now:
            other = self.today()

        diff = self.diff(other)

        return pendulum.format_diff(diff, is_now, absolute, locale)

    # MODIFIERS 
開發者ID:sdispater,項目名稱:pendulum,代碼行數:42,代碼來源:date.py

示例10: today

# 需要導入模塊: import pendulum [as 別名]
# 或者: from pendulum import today [as 別名]
def today(cls):
        return pendulum.today().date() 
開發者ID:sdispater,項目名稱:pendulum,代碼行數:4,代碼來源:date.py

示例11: today

# 需要導入模塊: import pendulum [as 別名]
# 或者: from pendulum import today [as 別名]
def today():
    return pendulum.today().date() 
開發者ID:sdispater,項目名稱:pendulum,代碼行數:4,代碼來源:test_diff.py

示例12: test_diff_in_years_vs_default_now

# 需要導入模塊: import pendulum [as 別名]
# 或者: from pendulum import today [as 別名]
def test_diff_in_years_vs_default_now(today):
    assert 1 == today.subtract(years=1).diff().in_years() 
開發者ID:sdispater,項目名稱:pendulum,代碼行數:4,代碼來源:test_diff.py

示例13: test_diff_in_months_vs_default_now

# 需要導入模塊: import pendulum [as 別名]
# 或者: from pendulum import today [as 別名]
def test_diff_in_months_vs_default_now(today):
    assert 12 == today.subtract(years=1).diff().in_months() 
開發者ID:sdispater,項目名稱:pendulum,代碼行數:4,代碼來源:test_diff.py

示例14: test_diff_in_days_vs_default_now

# 需要導入模塊: import pendulum [as 別名]
# 或者: from pendulum import today [as 別名]
def test_diff_in_days_vs_default_now(today):
    assert 7 == today.subtract(weeks=1).diff().in_days() 
開發者ID:sdispater,項目名稱:pendulum,代碼行數:4,代碼來源:test_diff.py

示例15: test_diff_for_humans_now_and_day

# 需要導入模塊: import pendulum [as 別名]
# 或者: from pendulum import today [as 別名]
def test_diff_for_humans_now_and_day(today):
    assert "1 day ago" == today.subtract(days=1).diff_for_humans() 
開發者ID:sdispater,項目名稱:pendulum,代碼行數:4,代碼來源:test_diff.py


注:本文中的pendulum.today方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。