Skip to content

Instantly share code, notes, and snippets.

@funkytwig
Last active August 20, 2017 12:39
Show Gist options
  • Save funkytwig/b47551e98e8698ebb59310286982a6ce to your computer and use it in GitHub Desktop.
Save funkytwig/b47551e98e8698ebb59310286982a6ce to your computer and use it in GitHub Desktop.
def start_time=( t )
h = 99 # hour
m = 99 # minute
t_in = t
t = t.upcase
t = t.gsub('P.M', 'PM' )
t = t.gsub('A.M', 'AM' )
t = t.gsub('P.M.', 'PM' )
t = t.gsub('A.M.', 'AM' )
if t.index("AM") || t.index("PM") then
p "Event.time has AM/PM" if $DEBUG
if t.length < 5 then # just houres and AM/PM
p "Event.time len < 5, no minutes" if $DEBUG
if t.length == 3 then # hour < 10
p "Event.time len len=3, no minutes" if $DEBUG
t = "0" + "0"
end
hour=t[0,2]
min = "00"
else # Has hours and minutes
t = t.gsub(".",":")
colon_pos = t.index(':')
# hour just be single didgit
if colon_pos==1 then t = "0" + t end
hour=t[0,2]
if colon_pos then # there are minutes
min = t[colon_pos+2,2]
else
min = "00"
end
end # if t.length < 5 then
else # no AM/PM
if t.length < 3 then
raise "Event.time to short #{t}"
elsif t.length == 4 then # HHMM
h = t[0,2]
m = t[2,2]
elsif t.length == 5 then # HH?HH
h = t[0,2]
m = t[3,2]
else
raise "Event.time to long #{t}"
end
end # has AM/PM
if t.index('PM') then
p "Event.time PM so add 12 houres (unless 12)" if $DEBUG # !need to code the unless 12!
hour = hour.to_i + 12
end
t = h.to_i.to_s.rjust(2, '0') + ":" + m.to_i.to_s.rjust(2, '0')
if $DEBUG then
p "Event.start_time=#{t.to_s} (input =#{t_in.to_s} hour=#{h.to_s} minute=#{m.to_s})"
end
@start_time = t
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment