Getting Clock Control's Format

Applies to TestComplete 15.68, last modified on October 16, 2024
Using the Native Fields

To get the current time format of the device, use the native mFormat field of the Android DigitalClock and Android TextClock objects. This field returns the sequence of characters depending on the time format of the application.

You can also access the mFormat12 and mFormat24 fields of the Android TextClock object, as well as m12 and m24 fields of the DigitalClock object. The values these fields return determine the time format used to show time in 12- and 24-hour modes. The following example determines the current time format and posts it to the log.

JavaScript, JScript

function Test()
{
  var p, Clock, Format, Format12, Format24;

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

  // Obtain the clock object
  p = Mobile.Device().Process("com.example.myapp");
  Clock = p.RootLayout("").Layout("layoutTop").Layout("layout1").TextClock("textClock1");
  
  // Obtain the format values
  Format = Clock.mFormat.value;
  Format12 = Clock.mFormat12.value;
  Format24 = Clock.mFormat24.value;
  
  // Compare the format values and post the current one to the log
  if (Format12 == Format)
    Log.Message(Format12);
  else
    Log.Message(Format24);
}

Python

def Test():

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

  # Obtain the clock object 
  p = Mobile.Device().Process("com.example.myapp")
  Clock = p.RootLayout("").Layout("layoutTop").Layout("layout1").TextClock("textClock1")
  
  # Obtain the format values
  Format = Clock.mFormat.value
  Format12 = Clock.mFormat12.value
  Format24 = Clock.mFormat24.value
  
  # Compare the format values and post the current one to the log
  if (Format12 == Format):
    Log.Message(Format12) 
  else:
    Log.Message(Format24)

VBScript

Sub Test()
  Dim p, Clock, Format, Format12, Format24

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

  ' Obtain the clock object
  Set p = Mobile.Device.Process("com.example.myapp")
  Set Clock = p.RootLayout("").Layout("layoutTop").Layout("layout1").TextClock("textClock1")
  
  ' Obtain the format values
  Format = Clock.mFormat.value
  Format12 = Clock.mFormat12.value
  Format24 = Clock.mFormat24.value
  
  ' Compare the format values and post the current one to the log
  If Format12 = Format Then
    Log.Message(Format12)
  else
    Log.Message(Format24)
  End If
End Sub

DelphiScript

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

  // Obtain the clock object
  p := Mobile.Device.Process('com.example.myapp');
  Clock := p.RootLayout('').Layout('layoutTop').Layout('layout1').TextClock('textClock1');
  
  // Obtain the format values
  Format := Clock.mFormat.value;
  Format12 := Clock.mFormat12.value;
  Format24 := Clock.mFormat24.value;
  
  // Compare the format values and post the current one to the log
  if Format12 = Format then
    Log.Message(Format12)
  else
    Log.Message(Format24);
end;

C++Script, C#Script

function Test()
{
  var p, Clock, Format, Format12, Format24;

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

  // Obtain the clock object
  p = Mobile["Device"]["Process"]("com.example.myapp");
  Clock = p["RootLayout"]("")["Layout"]("layoutTop")["Layout"]("layout1")["TextClock"]("textClock1");
  
  // Obtain the format values
  Format = Clock["mFormat"]["value"];
  Format12 = Clock["mFormat12"]["value"];
  Format24 = Clock["mFormat24"]["value"];
  
  // Compare the format values and post the current one to the log
  if (Format12 == Format)
    Log["Message"](Format12);
  else
    Log["Message"](Format24);
}

Simulating Actions From Keyword Tests

This topic explains how to check the time format of the clock control in scripts. You can use the described fields in keyword tests too. To do this, use the On-Screen Action or the Call Object Method operations.

See Also

Working With Android Clock Controls
Touching Clock Controls
wTime Property (Android Controls)

Highlight search results