Stupid Author Geek Tricks

I am super fussy about time in my writing. I hate a sense that time isn’t a factor in the stories I write. With time, comes cycles; tides, moons, who is on shift, when’s the poker-gang meeting and such. With “Afterliving for Guys”, time is especially important; most of the main characters are vampires. They’re dead in short order if their watch is wrong.

To help with keeping track of the movement of time, I actually wrote a simple Ruby-script program to let me keep moving the clock and calendar forward. It’s pretty straightforward; you give it a start point, and then a series of time increments to move the clock forward, and if it should introduce some “fuzz” so that times are much less likely to be repeated on narrow scales.

Michels-iMac%
./afterlivingFG.clocktick.rbx "Wednesday, 23rd October, 1996,  8:13pm" "2h 30m 11h 24m" +fuzz
(adding 13 minutes of 'fuzz')
(adding 4 minutes of 'fuzz')
(adding 79 minutes of 'fuzz')
(adding 4 minutes of 'fuzz')
Thursday, 24th October, 1996, 11:48am

So in the example above, you can see what I mean. The first argument (“Wednesday, 23rd October, 1996, 8:13pm“) is the point time moves forward from. The second argument (“2h 30m 11h 24m“) is a set of time adjustments that are applied in succession, with the “units” being pretty common ones. The last argument (+fuzz) signals the application to add a random amount of extra time to the requested step forward. The last line in the example is the resulting new current time.

In case someone else can make use of this, here is the sample code:

#! env ruby
require 'date'

seconds = 1
minutes = 60 * seconds
hours = 60 * minutes
days = 24 * hours
weeks = 7 * days

current_dtg = DateTime.parse(ARGV[0].to_s).to_time
increment_text_blob = ARGV[1].to_s

if ARGV[2].to_s == "+fuzz"
  add_fuzz = true
else
  add_fuzz = false
end

increment_text_set = increment_text_blob.split(" ")
updated_time = current_dtg

increment_text_set.each { |request|
  increment_amount = request[0..request.length-1].to_i
  increment_unit = request[-1]

  time_change = case increment_unit
    when "m"
      increment_amount * minutes
    when "h"
      increment_amount * hours
    when "d"
      increment_amount * days
    when "w"
      increment_amount * weeks
  end

  if add_fuzz
    fuzz = (Random.rand(11...22)/100.0 * time_change.to_f).to_i
    phrase = "#{fuzz/minutes} minutes"
    phrase = "a few seconds" if (fuzz/minutes) < 1.0
    puts "(adding #{phrase} of 'fuzz')"
    time_change = time_change + fuzz
  end
  updated_time = updated_time + time_change
  }

date_suffix = case updated_time.to_date.mday.to_s[-1]
  when "1"
    "st"
  when "2"
    "nd"
  when "3"
    "rd"
  else
    "th"
end

if updated_time.to_date.mday == 11
  date_suffix = "th"
end

book_time_string = "%A, %-d#{date_suffix} %B, %Y, %l:%M%P"
puts updated_time.strftime(book_time_string)

It’s pure Ruby; no additional gems required to make it work. I’m aware that a couple of easily available gems would have spared a bit of wheel re-invention, but it almost takes longer to go find the gems and their use-references than just writing the few lines here that get it done.

Another item to note is that the “fuzz factor” is a random value between 11 and 22 percent. Obviously, that’s seasoning. Give it a think and decide if a better range makes better sense for your projects.

If you wind up using this, or porting to PHP or something else, please let me know. I’d love to hear from you in the comments. Cheers, all.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.