module Briar::Picker::DateManipulation

Public Instance Methods

args_for_change_date_on_picker(options) click to toggle source
# File lib/briar/picker/date_picker_manipulation.rb, line 68
def args_for_change_date_on_picker(options)
  args = []
  if options.has_key?(:notify_targets)
    args << options[:notify_targets] ? 1 : 0
  else
    args << 1
  end

  if options.has_key?(:animate)
    args << options[:animate] ? 1 : 0
  else
    args << 1
  end
  args
end
brief_date_strings_are_equivalent(a, b) click to toggle source
# File lib/briar/picker/date_picker_manipulation.rb, line 270
def brief_date_strings_are_equivalent (a, b)
  a_iso_str = Date.parse(a).strftime(BRIAR_PICKER_ISO8601_BRIEF_DATE_FMT)
  b_iso_str = Date.parse(b).strftime(BRIAR_PICKER_ISO8601_BRIEF_DATE_FMT)
  a_iso_str.eql? b_iso_str
end
brief_date_time_strings_are_equivalent(a, b) click to toggle source
# File lib/briar/picker/date_picker_manipulation.rb, line 277
def brief_date_time_strings_are_equivalent (a, b)
  a_iso_str = Date.parse(a).strftime(BRIAR_PICKER_ISO8601_BRIEF_DATE_TIME_FMT)
  b_iso_str = Date.parse(b).strftime(BRIAR_PICKER_ISO8601_BRIEF_DATE_TIME_FMT)
  a_iso_str.eql? b_iso_str
end
change_date_on_picker_with_date(date, options = {:animate => true, :picker_id => nil, :notify_targets => true}) click to toggle source
# File lib/briar/picker/date_picker_manipulation.rb, line 215
def change_date_on_picker_with_date (date, options = {:animate => true,
                                                      :picker_id => nil,
                                                      :notify_targets => true})
  picker_id = picker_id_from_options options
  target_dt = target_date_for_change_date_on_picker_with_date date, picker_id
  change_picker_date_time target_dt, options
end
change_date_on_picker_with_date_str(date_str, options = {:animate => true, :picker_id => nil, :notify_targets => true}) click to toggle source
# File lib/briar/picker/date_picker_manipulation.rb, line 206
def change_date_on_picker_with_date_str (date_str, options = {:animate => true,
                                                              :picker_id => nil,
                                                              :notify_targets => true})
  picker_id = picker_id_from_options options
  target_dt = target_date_for_change_date_on_picker_with_date_str date_str, picker_id
  change_picker_date_time target_dt, options
end
change_picker_date_time(target_dt, options = {:convert_time_to_utc => false, :animate => true, :picker_id => nil, :notify_targets => true}) click to toggle source
# File lib/briar/picker/date_picker_manipulation.rb, line 140
def change_picker_date_time (target_dt, options = {:convert_time_to_utc => false,
                                                   :animate => true,
                                                   :picker_id => nil,
                                                   :notify_targets => true})


  picker_id = picker_id_from_options options
  unless picker_is_in_time_mode picker_id or picker_is_in_date_and_time_mode picker_id
    screenshot_and_raise 'picker is not in date time or time mode'
  end


  should_see_date_picker picker_id


  convert = convert_to_utc_from_options options


  ensure_can_change_picker_to_date target_dt, picker_id


  target_str = convert_date_time_to_objc_fmt target_dt, convert
  fmt_str = date_format_for_target(:objc, convert ? :zoned : :default)


  args = args_for_change_date_on_picker options


  query_str = query_string_for_picker picker_id


  views_touched = map(query_str, :changeDatePickerDate, target_str, fmt_str, *args)

  msg = "could not change date on picker to '#{target_dt}' using query '#{query_str}' with options '#{options}'"
  views_touched = assert_map_results(views_touched, msg)

  set_briar_date_picker_variables target_dt, options

  step_pause
  views_touched
end
change_time_on_picker_with_time(time, options = {:convert_time_to_utc => false, :animate => true, :picker_id => nil, :notify_targets => true}) click to toggle source
# File lib/briar/picker/date_picker_manipulation.rb, line 196
def change_time_on_picker_with_time (time, options = {:convert_time_to_utc => false,
                                                      :animate => true,
                                                      :picker_id => nil,
                                                      :notify_targets => true})
  convert = convert_to_utc_from_options options
  picker_id = picker_id_from_options options
  target_dt = target_date_for_change_time_on_picker_with_time time, convert, picker_id
  change_picker_date_time target_dt, options
end
change_time_on_picker_with_time_str(time_str, options = {:convert_time_to_utc => false, :animate => true, :picker_id => nil, :notify_targets => true}) click to toggle source
# File lib/briar/picker/date_picker_manipulation.rb, line 182
def change_time_on_picker_with_time_str (time_str, options = {:convert_time_to_utc => false,
                                                              :animate => true,
                                                              :picker_id => nil,
                                                              :notify_targets => true})

  convert = convert_to_utc_from_options options
  picker_id = picker_id_from_options options

  target_dt = target_date_for_change_time_on_picker_with_time_str time_str, convert, picker_id

  change_picker_date_time target_dt, options
end
convert_date_time_to_objc_fmt(date_time, convert=false) click to toggle source
# File lib/briar/picker/date_picker_manipulation.rb, line 63
def convert_date_time_to_objc_fmt (date_time, convert=false)
  format = date_format_for_target(:ruby, convert ? :zoned : :default)
  date_time.strftime(format).squeeze(' ').strip
end
date_format_for_target(target, zoned) click to toggle source
# File lib/briar/picker/date_picker_manipulation.rb, line 55
def date_format_for_target (target, zoned)
  res = BRIAR_DATE_CONVERSION_FORMATS[target][zoned]
  if res.nil?
    screenshot_and_raise "could not find format for target '#{target}' and zone '#{zoned}'"
  end
  res
end
ensure_can_change_picker_to_date(target_dt, picker_id=nil) click to toggle source

pickers that use utc (reminders, alerts, etc. do no usually have min/max dates

# File lib/briar/picker/date_picker_manipulation.rb, line 123
def ensure_can_change_picker_to_date(target_dt, picker_id=nil)
  max_date = maximum_date_time_from_picker picker_id
  if max_date and target_dt > max_date
    puts "\ntarget: '#{target_dt}'"
    puts "   max: '#{max_date}'"
    screenshot_and_raise "cannot change time to '#{target_dt}' because the picker has a maximum date of '#{max_date}'"
  end

  min_date = minimum_date_time_from_picker picker_id
  if min_date and target_dt < min_date
    p "target: '#{target_dt}'"
    p "   min: '#{min_date}'"
    screenshot_and_raise "cannot change time to #{target_dt} because the picker has a minimum date of '#{min_date}'"
  end
end
set_briar_date_picker_variables(target_dt, options={}) click to toggle source
# File lib/briar/picker/date_picker_manipulation.rb, line 224
def set_briar_date_picker_variables(target_dt, options={})
  default_options = {:picker_id => nil,
                     :convert_time_to_utc => false,
                     :assert_mode => false}
  options = default_options.merge(options)

  options[:assert_picker] = false
  ruby_picker_time = ruby_time_from_picker options

  options[:time_on_picker] = ruby_picker_time


  picker_mode = picker_mode(options[:picker_id])

  if picker_mode == UIDatePickerModeDateAndTime or
        picker_mode == UIDatePickerModeTime
    @date_picker_time_12h = picker_time_str :h12, options
    @date_picker_time_24h = picker_time_str :h24, options
    @date_picker_time_hash = picker_time_strs_hash options
    @date_picker_time_arr = picker_time_strs_arr options
    unless time_strings_are_equivalent @date_picker_time_12h, @date_picker_time_24h
      screenshot_and_raise "ERROR: changing the picker resulted in two different times: '#{@date_picker_time_hash}'"
    end
  end

  @date_picker_brief_date_12h = picker_brief_date_str :brief_12h, options
  @date_picker_brief_date_24h = picker_brief_date_str :brief_24h, options
  @date_picker_brief_date_hash = picker_brief_date_strs_hash options
  @date_picker_brief_date_arr = picker_brief_date_strs_arr options

  unless brief_date_strings_are_equivalent @date_picker_brief_date_12h, @date_picker_brief_date_24h
    screenshot_and_raise "ERROR: changing the picker resulted in two different dates: '#{@date_picker_brief_date_hash}'"
  end

  @date_picker_date_time = target_dt
end
target_date_for_change_date_on_picker_with_date(target_date, picker_id=nil) click to toggle source
# File lib/briar/picker/date_picker_manipulation.rb, line 114
def target_date_for_change_date_on_picker_with_date(target_date, picker_id=nil)
  current_time = ruby_time_from_picker picker_id
  DateTime.new(target_date.year, target_date.mon, target_date.day,
               current_time.hour, current_time.min, 0, current_time.offset)
end
target_date_for_change_date_on_picker_with_date_str(date_str, picker_id=nil) click to toggle source
# File lib/briar/picker/date_picker_manipulation.rb, line 106
def target_date_for_change_date_on_picker_with_date_str(date_str, picker_id=nil)
  if date_str.nil? || date_str.length == 0
    screenshot_and_raise "date str '#{date_str}' must be non-nil and non-empty"
  end
  date = Date.parse(date_str)
  target_date_for_change_date_on_picker_with_date date, picker_id
end
target_date_for_change_time_on_picker_with_time(target_time, convert, picker_id=nil) click to toggle source
# File lib/briar/picker/date_picker_manipulation.rb, line 92
def target_date_for_change_time_on_picker_with_time(target_time, convert, picker_id=nil)
  current_time = ruby_time_from_picker({:picker_id => picker_id})
  if RUBY_VERSION.start_with?('1.8')
    tz_offset = (convert) ? 0 : Rational(((target_time.utc_offset/3600.0)/24.0).to_i)
  else
    tz_offset = (convert) ? 0 : Rational((target_time.utc_offset/3600.0)/24.0)
  end

  DateTime.new(current_time.year, current_time.mon, current_time.day,
               target_time.hour, target_time.min,
               0, tz_offset)
end
target_date_for_change_time_on_picker_with_time_str(time_str, convert, picker_id=nil) click to toggle source
# File lib/briar/picker/date_picker_manipulation.rb, line 84
def target_date_for_change_time_on_picker_with_time_str(time_str, convert, picker_id=nil)
  if time_str.nil? || time_str.length == 0
    screenshot_and_raise "time str '#{time_str}' must be non-nil and non-empty"
  end
  time = Time.parse(time_str)
  target_date_for_change_time_on_picker_with_time time, convert, picker_id
end
time_strings_are_equivalent(a, b) click to toggle source

utility

# File lib/briar/picker/date_picker_manipulation.rb, line 263
def time_strings_are_equivalent (a, b)
  a_iso_str = Time.parse(a).strftime(BRIAR_PICKER_ISO8601_TIME_FMT)
  b_iso_str = Time.parse(b).strftime(BRIAR_PICKER_ISO8601_TIME_FMT)
  a_iso_str.eql? b_iso_str
end