diff --git a/CHANGELOG.md b/CHANGELOG.md index d20d7dae..0d0454fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/appium_lib_core/device.rb b/lib/appium_lib_core/device.rb index 7bf3a370..50ad5da2 100644 --- a/lib/appium_lib_core/device.rb +++ b/lib/appium_lib_core/device.rb @@ -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" # #### @@ -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 diff --git a/test/functional/android/android/device_test.rb b/test/functional/android/android/device_test.rb index 331c65d2..9b8cf388 100644 --- a/test/functional/android/android/device_test.rb +++ b/test/functional/android/android/device_test.rb @@ -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