Python pendulum.today() Examples

The following are 30 code examples of pendulum.today(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pendulum , or try the search function .
Example #1
Source File: date.py    From pendulum with MIT License 6 votes vote down vote up
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 
Example #2
Source File: test_diff.py    From pendulum with MIT License 6 votes vote down vote up
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)) 
Example #3
Source File: test_diff.py    From pendulum with MIT License 5 votes vote down vote up
def test_diff_for_humans_other_and_future_day(today):
    assert "1 day after" == today.diff_for_humans(today.subtract(days=1)) 
Example #4
Source File: test_diff.py    From pendulum with MIT License 5 votes vote down vote up
def test_diff_for_humans_now_and_future_months(today):
    assert "in 2 months" == today.add(months=2).diff_for_humans() 
Example #5
Source File: test_diff.py    From pendulum with MIT License 5 votes vote down vote up
def test_diff_for_humans_now_and_nearly_future_year(today):
    assert "in 11 months" == today.add(months=11).diff_for_humans() 
Example #6
Source File: test_diff.py    From pendulum with MIT License 5 votes vote down vote up
def test_diff_for_humans_now_and_future_year(today):
    assert "in 1 year" == today.add(years=1).diff_for_humans() 
Example #7
Source File: test_diff.py    From pendulum with MIT License 5 votes vote down vote up
def test_diff_for_humans_now_and_future_years(today):
    assert "in 2 years" == today.add(years=2).diff_for_humans() 
Example #8
Source File: test_diff.py    From pendulum with MIT License 5 votes vote down vote up
def test_diff_for_humans_other_and_day(today):
    assert "1 day before" == today.diff_for_humans(today.add(days=1)) 
Example #9
Source File: test_diff.py    From pendulum with MIT License 5 votes vote down vote up
def test_diff_for_humans_other_and_nearly_week(today):
    assert "6 days before" == today.diff_for_humans(today.add(days=6)) 
Example #10
Source File: test_diff.py    From pendulum with MIT License 5 votes vote down vote up
def test_diff_for_humans_other_and_week(today):
    assert "1 week before" == today.diff_for_humans(today.add(weeks=1)) 
Example #11
Source File: test_diff.py    From pendulum with MIT License 5 votes vote down vote up
def test_diff_for_humans_other_and_weeks(today):
    assert "2 weeks before" == today.diff_for_humans(today.add(weeks=2)) 
Example #12
Source File: test_diff.py    From pendulum with MIT License 5 votes vote down vote up
def test_diff_for_humans_other_and_nearly_month(today):
    assert "3 weeks before" == today.diff_for_humans(today.add(weeks=3)) 
Example #13
Source File: test_diff.py    From pendulum with MIT License 5 votes vote down vote up
def test_diff_for_humans_other_and_nearly_year(today):
    assert "11 months before" == today.diff_for_humans(today.add(months=11)) 
Example #14
Source File: test_diff.py    From pendulum with MIT License 5 votes vote down vote up
def test_diff_for_humans_other_and_year(today):
    assert "1 year before" == today.diff_for_humans(today.add(years=1)) 
Example #15
Source File: test_diff.py    From pendulum with MIT License 5 votes vote down vote up
def test_diff_for_humans_other_and_years(today):
    assert "2 years before" == today.diff_for_humans(today.add(years=2)) 
Example #16
Source File: test_diff.py    From pendulum with MIT License 5 votes vote down vote up
def test_diff_for_humans_now_and_nearly_future_month(today):
    assert "in 3 weeks" == today.add(weeks=3).diff_for_humans() 
Example #17
Source File: test_diff.py    From pendulum with MIT License 5 votes vote down vote up
def test_diff_for_humans_other_and_future_days(today):
    assert "2 days after" == today.diff_for_humans(today.subtract(days=2)) 
Example #18
Source File: test_diff.py    From pendulum with MIT License 5 votes vote down vote up
def test_diff_for_humans_other_and_future_week(today):
    assert "1 week after" == today.diff_for_humans(today.subtract(weeks=1)) 
Example #19
Source File: test_diff.py    From pendulum with MIT License 5 votes vote down vote up
def test_diff_for_humans_other_and_future_weeks(today):
    assert "2 weeks after" == today.diff_for_humans(today.subtract(weeks=2)) 
Example #20
Source File: test_diff.py    From pendulum with MIT License 5 votes vote down vote up
def test_diff_for_humans_other_and_nearly_future_month(today):
    assert "3 weeks after" == today.diff_for_humans(today.subtract(weeks=3)) 
Example #21
Source File: test_diff.py    From pendulum with MIT License 5 votes vote down vote up
def test_diff_for_humans_other_and_future_month():
    with pendulum.test(pendulum.datetime(2016, 3, 1)):
        today = pendulum.today().date()

        assert "4 weeks after" == today.diff_for_humans(today.subtract(weeks=4))
        assert "1 month after" == today.diff_for_humans(today.subtract(months=1))

    with pendulum.test(pendulum.datetime(2017, 2, 28)):
        today = pendulum.today().date()

        assert "1 month after" == today.diff_for_humans(today.subtract(weeks=4)) 
Example #22
Source File: test_diff.py    From pendulum with MIT License 5 votes vote down vote up
def test_diff_for_humans_other_and_future_months(today):
    assert "2 months after" == today.diff_for_humans(today.subtract(months=2)) 
Example #23
Source File: test_diff.py    From pendulum with MIT License 5 votes vote down vote up
def test_diff_for_humans_other_and_future_year(today):
    assert "1 year after" == today.diff_for_humans(today.subtract(years=1)) 
Example #24
Source File: test_diff.py    From pendulum with MIT License 5 votes vote down vote up
def test_diff_for_humans_other_and_future_years(today):
    assert "2 years after" == today.diff_for_humans(today.subtract(years=2)) 
Example #25
Source File: test_diff.py    From pendulum with MIT License 5 votes vote down vote up
def test_diff_for_humans_absolute_days(today):
    assert "2 days" == today.diff_for_humans(today.subtract(days=2), True)
    assert "2 days" == today.diff_for_humans(today.add(days=2), True) 
Example #26
Source File: test_diff.py    From pendulum with MIT License 5 votes vote down vote up
def test_diff_for_humans_absolute_weeks(today):
    assert "2 weeks" == today.diff_for_humans(today.subtract(weeks=2), True)
    assert "2 weeks" == today.diff_for_humans(today.add(weeks=2), True) 
Example #27
Source File: test_diff.py    From pendulum with MIT License 5 votes vote down vote up
def test_diff_for_humans_absolute_months(today):
    assert "2 months" == today.diff_for_humans(today.subtract(months=2), True)
    assert "2 months" == today.diff_for_humans(today.add(months=2), True) 
Example #28
Source File: test_construct.py    From pendulum with MIT License 5 votes vote down vote up
def test_today():
    today = pendulum.today()
    assert isinstance(today, DateTime) 
Example #29
Source File: test_diff.py    From pendulum with MIT License 5 votes vote down vote up
def test_diff_for_humans_now_and_days(today):
    assert "2 days ago" == today.subtract(days=2).diff_for_humans() 
Example #30
Source File: plugin.py    From limnoria-plugins with Do What The F*ck You Want To Public License 5 votes vote down vote up
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)