Skip to content

Commit f40cded

Browse files
authored
add date format for Android (#94)
* add date format for Android * append a docstring * update changelog * update get device time * tweak
1 parent afc3878 commit f40cded

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file.
33

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

78
### Bug fixes
89

lib/appium_lib_core/device.rb

+10-4
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,15 @@ module Device
8080
# @!method device_time
8181
# Get the time on the device
8282
#
83-
# @return [String]
83+
# @param [String] format The set of format specifiers. Read https://momentjs.com/docs/ to get the full list of supported
84+
# datetime format specifiers. The default format is `YYYY-MM-DDTHH:mm:ssZ`,
85+
# which complies to ISO-8601
86+
# @return [String] Formatted datetime string or the raw command output if formatting fails
8487
#
8588
# @example
8689
#
87-
# @driver.device_time
90+
# @driver.device_time #=> "2018-06-12T11:13:31+02:00"
91+
# @driver.device_time "YYYY-MM-DD" #=> "2018-06-12"
8892
#
8993

9094
####
@@ -523,8 +527,10 @@ def shake
523527
end
524528

525529
add_endpoint_method(:device_time) do
526-
def device_time
527-
execute :device_time
530+
def device_time(format = nil)
531+
arg = {}
532+
arg[:format] = format unless format.nil?
533+
execute :device_time, {}, arg
528534
end
529535
end
530536

test/functional/android/android/device_test.rb

+5
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ def test_device_time
7676
assert Date.parse(@@driver.device_time).is_a?(Date)
7777
end
7878

79+
def test_device_time_format
80+
require 'date'
81+
assert Date.parse(@@driver.device_time('YYYY-MM-DD')).is_a?(Date)
82+
end
83+
7984
def test_context_related
8085
@@core.wait { scroll_to('Views') }.click
8186
@@core.wait { scroll_to('WebView') }.click

0 commit comments

Comments
 (0)