x may store thousands of days . We find correct year and offset in the year .
x -= remDays NEW_LINE y2 = y1 + 1 NEW_LINE if isLeap ( y2 ) : NEW_LINE INDENT y2days = 366 NEW_LINE DEDENT else : NEW_LINE INDENT y2days = 365 NEW_LINE DEDENT while ( x >= y2days ) : NEW_LINE INDENT x -= y2days NEW_LINE y2 += 1 NEW_LINE if isLeap ( y2 ) : NEW_LINE INDENT y2days = 366 NEW_LINE DEDENT else : NEW_LINE INDENT y2days = 365 NEW_LINE DEDENT DEDENT offset2 = x NEW_LINE