def test_parse_yesterday(): """ Parsing 'yesterday' relative to a moment goes bacward on the calendar """ pytest.debug_func() eoy = nldt.moment("2007-12-01") assert not hasattr(eoy, 'parse') prs = nldt.Parser() result = prs('yesterday', start=eoy) assert result() == '2007-11-30' mar1 = nldt.moment("2008-03-01") result = prs('yesterday', start=mar1) assert result() == "2008-02-29"
def test_parse_tomorrow(): """ Calling parse with 'tomorrow' and a moment object should return a moment set to the following day. """ pytest.debug_func() eoy = nldt.moment(txt['2010-end']) assert not hasattr(eoy, 'parse') prs = nldt.Parser() result = prs('tomorrow', start=eoy) assert result() == txt['2011-begin'] feb28 = nldt.moment(txt['leap-yester']) result = prs('tomorrow', start=feb28) assert result() == txt['leap-today']
def test_month_days_curyear(): """ Verify that month.days() for february this year does the right thing """ pytest.debug_func() mobj = nldt.month() now = nldt.moment() curyear = int(now('%Y')) exp = 29 if mobj.isleap(curyear) else 28 # payload assert mobj.days(2) == exp
def test_bug_pctsec(): """ given x = moment() x.epoch() should be equal to int(x('%s')) The bug was that the epoch value was being stored and reported as a float, which was causing int to throw a ValueError. """ pytest.debug_func() now = nldt.moment() assert now.epoch() == int(now("%s"))
def test_week_day_number(): """ Test week.day_number() """ pytest.debug_func() w = nldt.week() sat = nldt.moment("2000-01-01") sun = nldt.moment("2000-01-02") assert w.day_number(sat.epoch()) == 5 # payload assert w.day_number(sat) == 5 # payload with pytest.raises(TypeError) as err: # payload w.day_number(txt['xpr-tod']) == 14 assert txt["err-argmore"] in str(err) assert w.day_number(sat, count='mon1') == 6 # payload assert w.day_number(sun, count='mon1') == 7 # payload assert w.day_number(sat, count='sun0') == 6 # payload assert w.day_number(sun, count='sun0') == 0 # payload
def main(): """ Here is where we start """ opts = docopt.docopt(__doc__) if opts['--debug']: pdb.set_trace() expr = " ".join(opts['DATE_TIME_EXPR']) or 'now' fmt = opts['--format'] if opts['--format'] else default_format(expr) zone = opts['--zone'] if opts['--zone'] else default_zone(expr) prs = nldt.Parser() when = nldt.moment(opts['--when']) ref = prs(expr, start=when) print(ref(**{'fmt': fmt, 'otz': zone}))