120
120
# TODO check settings!
121
121
ignore_dot_files = True
123
# For time calculations
124
seconds_per_day = 86400 # 60 * 60 * 24
126
timezone_offset = time.altzone
128
timezone_offset = time.timezone
131
124
# application/json is the "best" content type but is not good for
132
125
# debugging because Firefox just tries to download it
278
271
d["type_nice"] = util.nice_filetype(fullpath)
279
272
d["mtime"] = file_stat.st_mtime
280
d["mtime_nice"] = make_date_nice(file_stat.st_mtime)
281
d["mtime_short"] = make_date_nice_short(file_stat.st_mtime)
273
d["mtime_nice"] = common.date.make_date_nice(file_stat.st_mtime)
274
d["mtime_short"] = common.date.make_date_nice_short(file_stat.st_mtime)
284
277
def file_to_fileinfo(path, filename):
341
334
d.update(_stat_fileinfo(fullpath, wrapped))
343
336
return filename, d
345
def make_date_nice(seconds_since_epoch):
346
"""Given a number of seconds elapsed since the epoch,
347
generates a string representing the date/time in human-readable form.
348
"ddd mmm dd, yyyy h:m a"
350
#return time.ctime(seconds_since_epoch)
351
return time.strftime("%a %b %d %Y, %I:%M %p",
352
time.localtime(seconds_since_epoch))
354
def make_date_nice_short(seconds_since_epoch):
355
"""Given a number of seconds elapsed since the epoch,
356
generates a string representing the date in human-readable form.
357
Does not include the time.
358
This function generates a very compact representation."""
359
# Use a "naturalisation" algorithm.
360
days_ago = (int(time.time() - timezone_offset) / seconds_per_day
361
- int(seconds_since_epoch - timezone_offset) / seconds_per_day)
363
# Dates today or yesterday, return "today" or "yesterday".
369
return str(days_ago) + " days ago"
370
# Dates in the last 5 days, return "n days ago".
371
# Other dates, return a short date format.
372
# If within the same year, omit the year (mmm dd)
373
if time.localtime(seconds_since_epoch).tm_year==time.localtime().tm_year:
374
return time.strftime("%b %d", time.localtime(seconds_since_epoch))
375
# Else, include the year (mmm dd, yyyy)
377
return time.strftime("%b %d, %Y", time.localtime(seconds_since_epoch))