<s> import datetime as dt <EOL> def val_ago ( value , unit = "<STR_LIT>" ) : <EOL> if value == <NUM_LIT:1> : <EOL> return "<STR_LIT>" . format ( value , unit ) <EOL> else : <EOL> return "<STR_LIT>" . format ( value , unit ) <EOL> def human_date ( dateval , nowfunc = dt . datetime . now ) : <EOL> now = nowfunc ( ) <EOL> delta = now - dateval <EOL> days = delta . days <EOL> if days == <NUM_LIT:0> : <EOL> seconds = delta . seconds <EOL> minutes = seconds / <NUM_LIT> <EOL> hours = minutes / <NUM_LIT> <EOL> if hours > <NUM_LIT:0> : <EOL> return val_ago ( hours , unit = "<STR_LIT>" ) <EOL> if minutes > <NUM_LIT:0> : <EOL> return val_ago ( minutes , unit = "<STR_LIT>" ) <EOL> return val_ago ( seconds , unit = "<STR_LIT>" ) <EOL> elif <NUM_LIT:0> < days < <NUM_LIT:7> : <EOL> return val_ago ( days , unit = "<STR_LIT>" ) <EOL> else : <EOL> return dateval . strftime ( "<STR_LIT>" ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> jan1 = dt . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> def test_case ( expected , ** kwargs ) : <EOL> val = jan1 - dt . timedelta ( ** kwargs ) <EOL> human = human_date ( val , nowfunc = lambda : jan1 ) <EOL> assert human == expected , human <EOL> test_case ( "<STR_LIT>" , days = <NUM_LIT:1> ) <EOL> test_case ( "<STR_LIT>" , days = <NUM_LIT:2> ) <EOL> test_case ( "<STR_LIT>" , seconds = <NUM_LIT:5> ) <EOL> test_case ( "<STR_LIT>" , seconds = <NUM_LIT> * <NUM_LIT:2> ) <EOL> test_case ( "<STR_LIT>" , seconds = <NUM_LIT> * <NUM_LIT> * <NUM_LIT:3> ) <EOL> test_case ( "<STR_LIT>" , days = <NUM_LIT:7> ) </s>
