Skip to content

Instantly share code, notes, and snippets.

@helamonster
Created August 12, 2019 15:02
Show Gist options
  • Save helamonster/cfbed94c9784f3f20b644dd67b52adc0 to your computer and use it in GitHub Desktop.
Save helamonster/cfbed94c9784f3f20b644dd67b52adc0 to your computer and use it in GitHub Desktop.
Use a "sane" date format in terminal and applications
# Use a "sane" date format in terminal and applications
# Jeremy Bryan Smith <[email protected]>
# The following environment variables can be set in your terminal's profile config file.
# For BASH this typically is ~/.bash_profile for your user or /etc/profile for system-wide.
# What is a "sane" date format?
# * I consider a "sane" date format a format that:
# * Uses 24-hour time format instead of the AM/PM nonsense.
# * Begins with the most significant number and ends with the least significant number.
# * Has a consistent width (e.g. all numbers that can consist of multiple digits are
# zero-padded so that they contain the maximum possible number of digits).
# For example, in this order: Year, month, day, hour, minute, second
# And zero padded, such as: 2019-08-12 09:36
# Example: ISO 8601 <https://en.wikipedia.org/wiki/ISO_8601>
# * Yes, I am aware that once the year moves from 9999 to 10000 this will break.
# When that time comes, I'm sure the ISO standard and strftime() will be updated.
# * Don't even get me started on time zones... ugh!
# Why use a "sane" date format?
# * So that all text in a table or file listing lines up.
# * So that the date is string sortable.
#
# Consider this terrible listing:
# 12/9/2019 9:21:06 PM
# 3/12/2013 10:03:59 AM
# 1/1/2020 1:31:00 AM
#
# That is a horrendous eye sore! And you can not string sort!
# Many applications may not be aware of a table column's data type and will not be
# able to sort a table by the date with this terrible format.
#
# However, consider the same dates above, but sanely formatted:
# 2019-09-12 21:21:06
# 2013-12-03 10:03:59
# 2020-01-01 01:31:00
#
# Ahh, much better :-)
# * What can you, as an application developer, do to help?
# * Never hard-code date formats. Anywhere. Ever. At least use the system
# locale's format, and ideally, allow the user to configure the format.
# * Submit patches for poor applications that don't follow this rule.
# Use US English variant of UTF-8 character encoding
export LC_ALL=en_US.utf8
export LANG=en_US.utf8
# ...Except for the time format: Use ISO 8601 style (courtesey of the Danes)
export LC_TIME=en_DK.utf8
# Use an ISO 8601 style date format for the 'ls' command
alias 'ls=ls --time-style "+%Y-%m-%d %H:%M:%S %z" --color=auto'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment