Skip to content

Instantly share code, notes, and snippets.

@rawiriblundell
Created March 8, 2018 02:29
Show Gist options
  • Save rawiriblundell/d731a58bfbd7d56b2ad33dbba83cca73 to your computer and use it in GitHub Desktop.
Save rawiriblundell/d731a58bfbd7d56b2ad33dbba83cca73 to your computer and use it in GitHub Desktop.
Figure out the days where daylight savings will change
# Function to figure out daylight savings dates for the current year
dst() {
local TZ
# RHEL7 / systemd
if command -v timedatectl >/dev/null 2>&1; then
TZ=$(timedatectl status | awk -F ': ' '/Time zone/{print $2}' | awk '{print $1}')
# RHEL5, RHEL6 and similar aged CentOS/Fedora/etc
elif [[ -r /etc/sysconfig/clock ]]; then
TZ=$(awk -F "=" '/ZONE/{print $2}' /etc/sysconfig/clock)
# Older Debian family
elif [[ -r /etc/timezone ]]; then
TZ=$(</etc/timezone)
# Solaris 11
elif command -v nlsadm >/dev/null 2>&1; then
TZ=$(nlsadm get-timezone | cut -d '=' -f2)
# Older Solaris
elif [[ -r /etc/TIMEZONE ]]; then
TZ=$(nawk -F '=' '/TZ=/{print $2}' /etc/TIMEZONE)
fi
zdump -v "${TZ:-NZ}" \
| grep "$(date '+%Y').*isdst=1" \
| tail -n 2 \
| awk '{print $4, $3, $6}'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment