Improving the Dropbox sync

:  ~ 45 sec read

Sometimes I have an idea to write about, but I don't really want to post it now, since I want to spread the posts out, so I will just prepare it for future posting. The problem is that right now the sync command tries to add all files, so I came up with a way to only parse files with a date in the past:

def time_from_string(string)
  date_matches = string.match(/(\d{4})-(\d{2})-(\d{2})-(\d{4})/)
  time_zone = Time.now.getlocal.zone
  time = Date._strptime("#{date_matches[4]} #{time_zone}", '%H%M %Z')
  
  DateTime.new(date_matches[1].to_i, date_matches[2].to_i, date_matches[3].to_i, time[:hour], time[:min], 0, time[:zone]).to_time
end

get '/sync_command' do
  [...]
  client_metadata.each do |file|
    next if DateTime.now.to_time < time_from_string(datetime)
  [...]
end