def set_date(self, year, month): """ Sets the calendar to show the monthly calendar of given month and year. It prepares other information required to show the calendar """ self.year = int(year) self.month = int(month) # Make sure month and year are within limits if self.year < 2000 or (self.year == 2000 and self.month == 1): raise Http404 if self.year > 2080: raise Http404 self.calendar = NepCal.monthdatescalendar(self.year, self.month) self.firstdate = NepDate(self.year, self.month, 1) self.prevmonth = self.firstdate self.nextmonth = self.firstdate try: self.prevmonth = NepDate( self.year - 1 if self.month == 1 else self.year, 12 if self.month == 1 else self.month - 1, 1) except: pass # Do nothing on overflow try: self.nextmonth = NepDate( self.year + 1 if self.month == 12 else self.year, 1 if self.month == 12 else self.month + 1, 1) except: pass
def test_nepdate_tithi(self): d = NepDate(2069, 2, 3) self.assertEqual(d.tithi, 11) with self.assertRaises(ValueError): a = NepDate(2031, 1, 1).update().tithi with self.assertRaises(ValueError): a = NepDate(2091, 1, 1).update().tithi
def test_events(self): """ Test the events """ # TODO: Add more tests nep_date = NepDate(2033, 1, 1) nep_date.update() self.assertEqual(nep_date.events_list(), [(u"नेपाली नयाँ वर्ष", 1)]) self.assertEqual(NepDate(2073, 9, 17).update().events_list(), [(u"अंग्रेजी नयाँ वर्ष", 0)]) self.assertEqual(NepDate(2073, 9, 17).update().events_name(), [u"अंग्रेजी नयाँ वर्ष"]) self.assertTrue(NepDate(2053, 1, 11).update().is_event_holiday()) self.assertTrue(NepDate(2054, 1, 11).update().is_holiday())
def test_values_bs_range(self): self.assertTrue(check_valid_bs_range(NepDate(2000, 1, 1))) # Year less than min year with self.assertRaises(ValueError): check_valid_bs_range(NepDate(1999, 12, 30)) # Year greater than max year with self.assertRaises(ValueError): check_valid_bs_range(NepDate(2100, 1, 1)) # Month not in range with self.assertRaises(ValueError): check_valid_bs_range(NepDate(2050, 13, 1)) # Day not in range with self.assertRaises(ValueError): check_valid_bs_range(NepDate(2000, 1, 31)) with self.assertRaises(ValueError): check_valid_bs_range(NepDate(2078, 8, 30)) self.assertTrue(check_valid_bs_range(NepDate(2000, 1, 30))) self.assertTrue(check_valid_bs_range(NepDate(2064, 3, 32)))
def test_events(self): """ Test the events """ #TODO: Add more tests nep_date = NepDate(2033,1,1) nep_date.update() self.assertEqual(nep_date.events_list(), [(u"नेपाली नयाँ वर्ष",1)]) self.assertEqual(NepDate(2073,9,17).update().events_list(), [(u"अंग्रेजी नयाँ वर्ष",0)]) self.assertEqual(NepDate(2073,9,17).update().events_name(), [u"अंग्रेजी नयाँ वर्ष"]) self.assertTrue(NepDate(2053,1,11).update().is_event_holiday()) self.assertTrue(NepDate(2054,1,11).update().is_holiday())
def get_context_data(self, **kwargs): context = super(HomeView, self).get_context_data(**kwargs) today = NepDate.today() self.set_date(today.year, today.month) context.update(self.get_context()) context['title'] = "Nepali Calendar : नेपाली पात्रो " return context
def inject_date_params(request): """ Injects a 'today' variable in template context """ return { 'today': NepDate.today(), 'nepcal_values': values, }
def from_ad_date(cls, dt): if dt is None: return None if isinstance(dt, py_datetime.datetime): dt = py_datetime.date(dt.year, dt.month, dt.day) if dt < values.START_EN_DATE: return date.min if dt > values.END_EN_DATE: return date.max ne_dte = NepDate.from_ad_date(dt) return NeDate(ne_dte.year, ne_dte.month, ne_dte.day).update()
def get_context_data(self, **kwargs): context = super(MonthlyCalendar, self).get_context_data(**kwargs) # Get the current year and month today = NepDate.today() if 'year' in self.kwargs: year = self.kwargs['year'] else: year = today.year if 'month' in self.kwargs: month = self.kwargs['month'] else: month = today.month self.set_date(year, month) context.update(self.get_context()) context['title'] = "Nepali Calendar: %s , वि.सं. %s - नेपाली पात्रो " % ( self.firstdate.month_name(), self.firstdate.ne_year) return context
def get_context_data(self, **kwargs): context = super(MonthlyCalendar, self).get_context_data(**kwargs) # Get the current year and month today = NepDate.today() if 'year' in self.kwargs: year = self.kwargs['year'] else: year = today.year if 'month' in self.kwargs: month = self.kwargs['month'] else: month = today.month self.set_date(year, month) context.update(self.get_context()) context[ 'title'] = "Nepali Calendar: %s , वि.सं. %s - नेपाली पात्रो " % ( self.firstdate.month_name(), self.firstdate.ne_year) return context
def today(cls): nep_today = NepDate.today() return NeDate(nep_today.year, nep_today.month, nep_today.day).update()
def step_impl(context): assert (NepDate.today() == context.response)
def test_nepdate_tithi_name(self): self.assertEqual(NepDate(2069, 4, 15).ne_tithi_name(), u"द्वादशी") pass