def _cmp_date(self, item, dt): assert_equal(DateArithmetic.parse(item), dt.strftime("%Y-%m-%d"))
def parse(*ymdh): return DateArithmetic.parse('ymdh+1', datetime.datetime(*ymdh))
def test_daynumber_minus(self): daynum = self.now.toordinal() - 1 assert_equal(DateArithmetic.parse('daynumber-1'), daynum)
def test_hour_minus(self): hour = "%02d" % ((int(self.now.strftime("%H")) - 1) % 24) assert_equal(DateArithmetic.parse('hour-1'), hour)
def test_unixtime(self): timestamp = int(self.now.timestamp()) assert_equal(DateArithmetic.parse('unixtime'), timestamp)
def test_unixtime_minus(self): timestamp = int(self.now.timestamp()) - 99 assert_equal(DateArithmetic.parse('unixtime-99'), timestamp)
def test_unixtime_plus(self): timestamp = int(timeutils.to_timestamp(self.now)) + 100 assert_equal(DateArithmetic.parse('unixtime+100'), timestamp)
def test_unixtime_minus(self): timestamp = int(timeutils.to_timestamp(self.now)) - 99 assert_equal(DateArithmetic.parse('unixtime-99'), timestamp)
def _cmp_year(self, item, dt): assert_equal(DateArithmetic.parse(item), dt.strftime("%Y"))
def test_unixtime(self): timestamp = int(timeutils.to_timestamp(self.now)) assert_equal(DateArithmetic.parse('unixtime'), timestamp)
def _cmp_month(self, item, dt): assert_equal(DateArithmetic.parse(item), dt.strftime("%m"))
def parse(*ymdhm): return DateArithmetic.parse('ymdhm-1', datetime.datetime(*ymdhm))
def test_daynumber(self): daynum = self.now.toordinal() assert_equal(DateArithmetic.parse('daynumber'), daynum)
def test_unixtime_plus(self): timestamp = int(self.now.timestamp()) + 100 assert_equal(DateArithmetic.parse('unixtime+100'), timestamp)
def test_hour(self): hour = self.now.strftime("%H") assert_equal(DateArithmetic.parse('hour'), hour)
def test_bad_date_format(self): assert DateArithmetic.parse('~~') is None