Created
January 13, 2025 04:17
-
-
Save bchase/9ea11fc91c98898aa8067326bfa4ea34 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
# require 'pathname' | |
require 'active_support/all' # DateTime | |
# M 2025-01-13 09-18 | |
# T 2025-01-14 07-16 | |
# W 2025-01-15 09-18 ? | |
# R 2025-01-16 y | |
tz_os = DateTime.now.offset | |
filepath = ARGV[0] | |
target_tz = ARGV[1] | |
line_re = %r"(\d{4}[-]\d{2}[-]\d{2})\s+((\d{2})[-](\d{2}))" | |
local = | |
Pathname.new(filepath) | |
.readlines | |
.map(&:chomp) | |
.map {|line| | |
line.match(line_re) | |
} | |
.reject(&:nil?) | |
.map {|m| | |
date = m[1] | |
[m[3], m[4]] | |
.map {|hour| | |
DateTime | |
.parse("#{date} #{hour}:00") | |
.change(offset: tz_os) | |
} | |
} | |
remote = | |
local | |
.map {|times| | |
times.map{|time| time.in_time_zone(target_tz)} | |
} | |
def date_str(dt) | |
dt.strftime("(#{dow_str(dt)}) %Y-%m-%d") | |
end | |
def time_str(dt) | |
dt.strftime('%l %p') | |
end | |
def date_and_time_str(dt) | |
[ | |
date_str(dt), | |
time_str(dt), | |
] | |
.join(" ") | |
end | |
def dow_str(dt) | |
%w[ | |
Sun | |
Mon | |
Tue | |
Wed | |
Thu | |
Fri | |
Sat | |
][dt.strftime("%w").to_i] | |
end | |
puts "Timezone: #{target_tz}" | |
remote.each do |(start, finish)| | |
print date_and_time_str(start) | |
print " to " | |
if start.day == finish.day | |
print time_str(finish) | |
else | |
print date_and_time_str(finish) | |
end | |
puts | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment