示例#1
0
    def set_datetime(self, date, time):
        if not self.check_sanity():
            # if clock are insane: try to reset it
            self.reset_clock()
            # if clock are still insane: return False
            if not self.check_sanity():
                return False
        year = int(date[0])
        month = int(date[1])
        day = int(date[2])
        hour = int(time[0])
        minute = int(time[1])
        second = int(time[2])
        if year < 1900 or year > 3000:
            year = 2017
            print("year   out of range, set to default")
        if month not in range(1, 13):
            month = 1
            print("month  out of range, set to default")
        if day not in range(1, 32):
            day = 1
            print("day    out of range, set to default")
        if hour not in range(0, 24):
            hour = 0
            print("hour   out of range, set to default")
        if minute not in range(0, 60):
            minute = 0
            print("minute out of range, set to default")
        if second not in range(0, 60):
            second = 0
            print("second out of range, set to default")

        ds1302.set_date(year, month, day)
        ds1302.set_time(hour, minute, second)
        return True
示例#2
0
 def set_datetime(self, dt):
     if not self.check_sanity():
         # if clock are insane: try to reset it
         self.reset_clock()
         # if clock are still insane: return False
         if not self.check_sanity():
             return False
     ds1302.set_date(dt.year, dt.month, dt.day)
     ds1302.set_time(dt.hour, dt.minute, dt.second)
     return True
	def set_datetime(self, dt):
		if not self.check_sanity():
			# if clock are insane: try to reset it
			self.reset_clock()
			# if clock are still insane: return False
			if not self.check_sanity():
				return False
		ds1302.set_date(dt.year, dt.month, dt.day)
		ds1302.set_time(dt.hour, dt.minute, dt.second)
		return True
示例#4
0
def setup():
    print ''
    print ''
    print rtc.get_datetime()
    print ''
    print ''
    a = raw_input("Do you want to setup date and time?(y/n) ")
    if a == 'y' or a == 'Y':
        date = raw_input("Input date:(YYYY MM DD) ")
        time = raw_input("Input time:(HH MM SS) ")
        date = date.split()
        time = time.split()
        print ''
        print ''
        ds1302.set_date(int(date[0]), int(date[1]), int(date[2]))
        ds1302.set_time(int(time[0]), int(time[1]), int(time[2]))
        dt = rtc.get_datetime()
        print "You set the date and time to:", dt
示例#5
0
def setup():
	print ''
	print ''
	print rtc.get_datetime()
	print ''
	print ''
	a = raw_input( "Do you want to setup date and time?(y/n) ")
	if a == 'y' or a == 'Y':
		date = raw_input("Input date:(YYYY MM DD) ")
		time = raw_input("Input time:(HH MM SS) ")
		date = date.split()
		time = time.split()
		print ''
		print ''
		ds1302.set_date(int(date[0]), int(date[1]), int(date[2]))
		ds1302.set_time(int(time[0]), int(time[1]), int(time[2]))
		dt = rtc.get_datetime()
		print "You set the date and time to:", dt
示例#6
0
 def get_datetime(self):
     if not self.check_sanity():
         # if clock are insane: try to reset it
         self.reset_clock()
         # if clock are still insane: return None
         if not self.check_sanity():
             return None
     year, month, date = ds1302.get_date()
     hour, minute, second = ds1302.get_time()
     if self.rangechecks:
         if year < 2000 or year > 3000:
             ds1302.set_date(2000, month, date)
             return self.get_datetime()
         if month not in range(1, 13):
             ds1302.set_date(year, 1, date)
             return self.get_datetime()
         if date not in range(1, 32):
             ds1302.set_date(year, month, 1)
             return self.get_datetime()
         if hour not in range(0, 24):
             ds1302.set_time(0, minute, second)
             return self.get_datetime()
         if minute not in range(0, 60):
             ds1302.set_time(hour, 0, second)
             return self.get_datetime()
         if second not in range(0, 60):
             ds1302.set_time(hour, minute, 0)
             return self.get_datetime()
     return datetime(year, month, date, hour, minute, second)
示例#7
0
	def get_datetime(self):
		if not self.check_sanity():
			# if clock are insane: try to reset it
			self.reset_clock()
			# if clock are still insane: return None
			if not self.check_sanity():
				return None
		year, month, date = ds1302.get_date()
		hour, minute, second = ds1302.get_time()
		if self.rangechecks:
			if year < 2000 or year > 3000:
				ds1302.set_date(2000, month, date)
				return self.get_datetime()
			if month not in range(1, 13):
				ds1302.set_date(year, 1, date)
				return self.get_datetime()
			if date not in range(1, 32):
				ds1302.set_date(year, month, 1)
				return self.get_datetime()
			if hour not in range(0, 24):
				ds1302.set_time(0, minute, second)
				return self.get_datetime()
			if minute not in range(0, 60):
				ds1302.set_time(hour, 0, second)
				return self.get_datetime()
			if second not in range(0, 60):
				ds1302.set_time(hour, minute, 0)
				return self.get_datetime()
		return datetime(year, month, date,
						hour, minute, second)