logic with a time check.

This post started out as a question but I figured it out so here is what I've learned.

This is the bit of code that i am working on currently that allows you to check time.
 

  #=============================================================================  # * Get Event Time by Index  #=============================================================================  def self.event_time(index)      evtime = {  :year => Time_Events[index][:time][5],                  :month => Time_Events[index][:time][4],                  :day => Time_Events[index][:time][3],                  :hour => Time_Events[index][:time][2],                  :minute => Time_Events[index][:time][1],                  :second => Time_Events[index][:time][0],                }    return evtime  end    #=============================================================================  # * Events Update? by Index  #=============================================================================  def self.events_update?(index)    return false if $game_system.event_activation_states[index] == true    time = false, st = system_time, et = event_time(index)    et.each_key { |i|      if et.is_a?(String)        next      else        if st > et          return true        else          if st == et            time = true          else            return false          end        end      end    }    return time  endThe System Time is set up the same exact way. Whenever you check a time against another time you should start with the most priority.

For this example if the system time's year is greater then the event times year then obviously the rest of the times do not matter and so on.
Consider converting the system time into a frame count, with frame count 0 as the beginning of time. Then you can simply compare two integers.


Of course, frame counts do not support time zones, but it doesn't look like an issue for you.
I thought about that too, my only problem is the conversion from seconds to frames. It's just a lot more typing if you have to tell it how to convert it, unless you know of an easier way to write it all out.
If one second is n frames, then two seconds is 2n frames, so m seconds is m*n frames.

Code:
def to_frames(numSecs)  numSecs * Graphics.frame_rateend
but wouldn't i still have to do that for mins. hours and so on

Sorry I type too fast and I don't always check what I wrote like I should.
Are you telling me that you'd rather solve a harder problem because you don't want to type one line of code?

Code:
t = Time.nowt.hours * 24 + t.mins * 60 + t.secs * 60 + ...
After looking at the docs, you can even just say

Code:
Time.now.to_i
To get the current time in seconds since...whatever time they designated as the start time.
Beautiful.

Time.now.to_iI've seen and used Time.now and forgot about it completely.

I don't know... that might be enough to rewrite. I think it can be a lot shorter now and probably less memory too. Thank you Tsuki. 😀

Original thread: https://forums.rpgmakerweb.com/threads/logic-with-a-time-check.21034/