本文整理汇总了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
示例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))
示例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)
示例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)
示例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))
示例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()
示例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()
示例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)
示例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
示例10: today
# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import today [as 别名]
def today(cls):
return pendulum.today().date()
示例11: today
# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import today [as 别名]
def today():
return pendulum.today().date()
示例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()
示例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()
示例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()
示例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()