def _monthDays(self, geezDay = False, weekDayName = False): result = [0] * 4 yr = Et.EtDateTime(self.year,self.month) monthBeginning = yr.getWeekday() if yr.getMonth() == 13: if yr.isLeap(): daysInMonth = 6 else: daysInMonth = 5 else: daysInMonth = 30 for i in range(daysInMonth): if (geezDay): result[0] = self.year result[1] = self.month result[2] = constants.Constants().dayNumbers[i] if weekDayName: result[3] = constants.Constants().weekdays[monthBeginning] else: result[3] = monthBeginning else: result[0] = self.year result[1] = self.month result[2] = i + 1 if weekDayName: result[3] = constants.Constants().weekdays[monthBeginning] else: result[3] = monthBeginning monthBeginning = (monthBeginning + 1) % 7; return result;
def today(cls): localtime = str(datetime.now(timezone.utc).astimezone(pytz.timezone("Africa/Addis_Ababa"))) lst_now = Et.EtDateTime().parse(localtime) year = lst_now[0] month = lst_now[1] day = lst_now[2] hour = lst_now[3] minute = lst_now[4] second = lst_now[5] millisecond = lst_now[6] res = util.Util().gregorianToEthiopic(year, month, day) return ETC(res[0], res[1], res[2])
def __init__(self, year=None): if year == None: localtime = datetime.now(timezone.utc).astimezone( pytz.timezone("Africa/Addis_Ababa")) lst_now = etDateTime.EtDateTime()._parse(str(localtime)) year, month, day = lst_now[0], lst_now[1], lst_now[2] Ethiopia_day = util.Util().gregorianToEthiopic(year, month, day) self.__year = Ethiopia_day[0] else: self.__year = year self.ameteAlem = 5500 + self.__year self.rabeet = self.ameteAlem // 4 self.wenber = util.Util().getWenber(5500, self.__year) self.abekte = self.wenber * 11 % 30 if self.wenber == 0: self.metkih = 30 else: self.metkih = self.wenber * 19 % 30
def __init__(self, year, month, day): self.year = year self.month = month self.day = day self.etDateTime = Et.EtDateTime(year, month, day)
def isisAtSameMomentAs(self): self.assertTrue(etDateTimeTest.etd.isAtSameMomentAs(etDateTime.EtDateTime(etDateTimeTest.etd.getYear(),etDateTimeTest.etd.getMonth(),etDateTimeTest.etd.getDay(),etDateTimeTest.etd.getHour(),etDateTimeTest.etd.getMinute(),etDateTimeTest.etd.getSecond(),etDateTimeTest.etd.getMillisecond())))
def isBefore(self): self.assertTrue(etDateTimeTest.ec.isBefore(etDateTime.EtDateTime(2020)))
def isAfter(self): self.assertTrue(etDateTimeTest.e.isAfter(etDateTime.EtDateTime(2001)))
class etDateTimeTest(unittest.TestCase): ec = etDateTime.EtDateTime(2012, 7, 7) e = etDateTime.EtDateTime(2010) et = etDateTime.EtDateTime().parse("2012-07-07 15:12:17.500") etd = etDateTime.EtDateTime().now() ecc = etDateTime.EtDateTime().fromMillisecondsSinceEpoch(1585731446021) def getYear(self): self.assertEqual(2012,etDateTimeTest.ec.getYear()) self.assertEqual(2010,etDateTimeTest.e.getYear()) self.assertEqual(2012,etDateTimeTest.et.getYear()) self.assertEqual(2012,etDateTimeTest.ecc.getYear()) def getMonth(self): self.assertEqual(7,etDateTimeTest.ec.getMonth()) self.assertEqual(1,etDateTimeTest.e.getMonth()) self.assertEqual(7,etDateTimeTest.et.getMonth()) self.assertEqual(7,etDateTimeTest.ecc.getMonth()) def getDay(self): self.assertEqual(7,etDateTimeTest.ec.getDay()) self.assertEqual(1,etDateTimeTest.e.getDay()) self.assertEqual(7,etDateTimeTest.et.getDay()) self.assertEqual(23,etDateTimeTest.ecc.getDay()) def getDayGeez(self): self.assertEqual("፯",etDateTimeTest.ec.getDayGeez()) self.assertEqual("፯",etDateTimeTest.et.getDayGeez()) self.assertEqual("፳፫",etDateTimeTest.ecc.getDayGeez()) def getMonthGeez(self): self.assertEqual("መጋቢት",etDateTimeTest.ec.getMonthGeez()) def to_String(self): self.assertEqual("2012-07-07 09:12:17.500", etDateTimeTest.et.to_String()) self.assertEqual("2012-07-23 08:57:26.021",etDateTimeTest.ecc.to_String()) def getHour(self): self.assertEqual(9, etDateTimeTest.et.getHour()) self.assertEqual(8, etDateTimeTest.ecc.getHour()) def getMinute(self): self.assertEqual(12,etDateTimeTest.et.getMinute()) self.assertEqual(57,etDateTimeTest.ecc.getMinute()) def getSecond(self): self.assertEqual(17,etDateTimeTest.et.getSecond()) self.assertEqual(26,etDateTimeTest.ecc.getSecond()) def getMillisecond(self): self.assertEqual(500, etDateTimeTest.et.getMillisecond()) self.assertEqual(21,etDateTimeTest.ecc.getMillisecond()) def isAfter(self): self.assertTrue(etDateTimeTest.e.isAfter(etDateTime.EtDateTime(2001))) def isBefore(self): self.assertTrue(etDateTimeTest.ec.isBefore(etDateTime.EtDateTime(2020))) def isisAtSameMomentAs(self): self.assertTrue(etDateTimeTest.etd.isAtSameMomentAs(etDateTime.EtDateTime(etDateTimeTest.etd.getYear(),etDateTimeTest.etd.getMonth(),etDateTimeTest.etd.getDay(),etDateTimeTest.etd.getHour(),etDateTimeTest.etd.getMinute(),etDateTimeTest.etd.getSecond(),etDateTimeTest.etd.getMillisecond())))