Determining Time Picker's Format

Applies to TestComplete 15.69, last modified on November 13, 2024
Getting mIs24HourView Native Field

To determine the format of a time picker control, use the mIs24HourView native field. You can work with this field in the same way as with the properties provided by TestComplete. If the time picker format is 24-hour it returns True; otherwise - False. The following example determines the format of the time picker and posts it to the log:

JavaScript, JScript

function Test()
{
  // Select the Android device
  Mobile.SetCurrent("MyDevice");

  // Obtain the CalendarView object
  var p = Mobile.Device().Process("com.example.myapp");
  var TimePicker = p.RootLayout("", 2).Layout("content").TimePicker("timePicker");
  
  // Check if the format is 24-hour
  if (TimePicker.mIs24HourView)
    // Post the result to the log
    Log.Message("The time format is 24-hour");
  else
    Log.Message("The time format is 12-hour");
}

Python

def Test():
  # Select the Android device
  Mobile.SetCurrent("MyDevice")

  # Obtain the CalendarView object
  p = Mobile.Device().Process("com.example.myapp")
  TimePicker = p.RootLayout("", 2).Layout("content").TimePicker("timePicker")
  
  # Check if the format is 24-hour
  if TimePicker.mIs24HourView:
    # Post the result to the log
    Log.Message("The time format is 24-hour")
  else:
    Log.Message("The time format is 12-hour")

VBScript

Sub Test()
  ' Select the Android device
  Call Mobile.SetCurrent("MyDevice")

  ' Obtain the CalendarView object
  Set p = Mobile.Device.Process("com.example.myapp")
  Set TimePicker = p.RootLayout("", 2).Layout("content").TimePicker("timePicker")
  
  ' Check if the format is 24-hour
  If TimePicker.mIs24HourView Then
    ' Post the result to the log
    Log.Message("The time format is 24-hour")
  Else
    Log.Message("The time format is 12-hour")
  End If
End Sub

DelphiScript

procedure Test();
var
  p, TimePicker : OleVariant;
begin
  // Select the Android device
  Mobile.SetCurrent('MyDevice');

  // Obtain the TimePicker object
  p := Mobile.Device.Process('com.example.myapp');
  TimePicker := p.RootLayout('', 2).Layout('content').TimePicker('timePicker');
  
  // Check if the format is 24-hour
  if TimePicker.mIs24HourView then
    // Post the result to the log
    Log.Message('The time format is 24-hour')
  else
    Log.Message('The time format is 12-hour')
end;

C++Script, C#Script

function Test()
{
  // Select the Android device
  Mobile["SetCurrent"]("MyDevice");

  // Obtain the TimePicker object
  var p = Mobile["Device"]["Process"]("com.example.myapp");
  var TimePicker = p["RootLayout"]("", 2)["Layout"]("content")["TimePicker"]("timePicker");
  
  // Check if the format is 24-hour
  if (TimePicker["mIs24HourView"])
    // Post the result to the log
    Log["Message"]("The time format is 24-hour");
  else
    Log["Message"]("The time format is 12-hour");
}

Working With Number Pickers

A time picker control has NumberPicker child objects. You can check the time format of your device by determining the maximum hour value. If the format is 12-hour, the wMax property will return 12, otherwise - 23, because the 24-hour format includes 0. You can also do this by checking if the "amPm" number picker is visible. If it is, the time format is 12-hour.

However, in most cases, it is easier to use methods and properties of time picker controls, as in this case, the details of control implementation are hidden from tests. For more information on working with number picker controls, see the topics of the Working With Number Picker Controls section.

Simulating Actions From Keyword Tests

See Also

Working With Android Time Picker Controls
Android TimePicker Support
Determining and Changing Time Using Time Picker Control

Highlight search results