Skip to content

Instantly share code, notes, and snippets.

@spotco
Created December 9, 2025 23:43
Show Gist options
  • Select an option

  • Save spotco/971ec6c4c721b08a915dfab2704e55b7 to your computer and use it in GitHub Desktop.

Select an option

Save spotco/971ec6c4c721b08a915dfab2704e55b7 to your computer and use it in GitHub Desktop.
time.rb
$debug_time_offset = (0).weeks + (0).days + (0).seconds
$time_offset = (-8).hours # Midnight PST (-8:00 UTC)
def time()
return Time.now.utc + $time_offset + $debug_time_offset
end
def get_day_id
return ((time().beginning_of_day - ("2017-6-23".to_time(:utc) + $time_offset)) / 86400).to_i
end
def get_time_to_next_day
return ((time() + 1.day).beginning_of_day - time()).to_i
end
$day_of_week_offset = -3
def get_week_for_dayid(dayid)
return ((dayid + $day_of_week_offset) / 7).to_i
end
def get_day_of_week_for_dayid(dayid)
return (dayid + $day_of_week_offset) % 7
end
def get_week
return get_week_for_dayid(get_day_id())
end
def get_data_updated_time()
return 0
end
def get_time_to_next_week
return (6 - get_day_of_week_for_dayid(get_day_id())).days.to_i + get_time_to_next_day()
end
$month_offset = 10
$year_offset = 2019
def get_month(date=nil)
if date.nil? then date = time() end
return (date.month - $month_offset) + (date.year - $year_offset) * 12
end
def get_time_to_next_month(date=nil)
if date.nil? then date = time() end
return (date.end_of_month - date).to_i
end
def get_day
#called by game server
render :json => {
:Day => get_day_id(),
:Time => Time.now,
:SecondsToNextDay => get_time_to_next_day(),
:Week => get_week(),
:DataUpdatedTime => get_data_updated_time(),
:GlobalTime => Time.now.to_i,
:SecondsToNextWeek => get_time_to_next_week(),
:Month => get_month(),
:SecondsToNextMonth => get_time_to_next_month(),
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment