-
-
Save rawiriblundell/d731a58bfbd7d56b2ad33dbba83cca73 to your computer and use it in GitHub Desktop.
Figure out the days where daylight savings will change
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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