Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file.

## [Unreleased]
### Enhancements
- Add a `format` argument for `device_time` [#94](https://github.com/appium/ruby_lib_core/pull/94)

### Bug fixes

Expand Down
14 changes: 10 additions & 4 deletions lib/appium_lib_core/device.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,15 @@ module Device
# @!method device_time
# Get the time on the device
#
# @return [String]
# @param [String] format The set of format specifiers. Read https://momentjs.com/docs/ to get the full list of supported
# datetime format specifiers. The default format is `YYYY-MM-DDTHH:mm:ssZ`,
# which complies to ISO-8601
# @return [String] Formatted datetime string or the raw command output if formatting fails
#
# @example
#
# @driver.device_time
# @driver.device_time #=> "2018-06-12T11:13:31+02:00"
# @driver.device_time "YYYY-MM-DD" #=> "2018-06-12"
#

####
Expand Down Expand Up @@ -523,8 +527,10 @@ def shake
end

add_endpoint_method(:device_time) do
def device_time
execute :device_time
def device_time(format = nil)
arg = {}
arg[:format] = format unless format.nil?
execute :device_time, {}, arg
end
end

Expand Down
5 changes: 5 additions & 0 deletions test/functional/android/android/device_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ def test_device_time
assert Date.parse(@@driver.device_time).is_a?(Date)
end

def test_device_time_format
require 'date'
assert Date.parse(@@driver.device_time('YYYY-MM-DD')).is_a?(Date)
end

def test_context_related
@@core.wait { scroll_to('Views') }.click
@@core.wait { scroll_to('WebView') }.click
Expand Down