All pastes #759322 Raw Edit

Magically finding the year?

public text v1 · immutable
·published 2007-11-03 01:10 UTC
rendered paste body
# Here is what I know: 
# ++ Year, month, day, hour, minute the log was created
# ++ Year, month, day, hour, minute the log was last modified
# ++ Month, day, hour, minute that each line in the log was recorded
#
# I need to know what YEAR each line in the log is
# What is the best way to do this?


#
# Takes a fairly good guess as to whether a year has advanced in
# the log. This may not always be accurate if, say, an entire year
# to-the-minute passes since the last item inserted into the log.
#
# dttm_last is a datetime() that has the date and time the log was CREATED
# 
if linemonth < dttm_last.month or
		(linemonth == dttm_last.month and
			(lineday < dttm_last.day or
				(lineday == dttm_last.day and
					(linehour < dttm_last.hour or
						(linehour == dttm_last.hour and lineminute < dttm_last.minute)
					)
				)
			)
		):
	dttm_last = datetime(dttm_last.year + 1, linemonth, lineday, linehour, lineminute)
else:
	dttm_last = datetime(dttm_last.year, linemonth, lineday, linehour, lineminute)