KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: An alternative method to calling Current time(*)
PRODUCT: 4D Server | VERSION: 13.2 | PLATFORM: Mac & Win
Published On: November 28, 2012

There are a lot of deployed 4D Servers -- v11, v12, & v13 -- that have an issue twice a year, their time becomes one hour off when there is a change onto and off of daylight savings time. The current fix is to quite and restart 4D Server. This is not always a convenient fix.

The method below is a workaround to this problem without having to restart the server. It is a workaround for the 4D function Current time(*). The trick is to set the method property "Execute on Server."

When the method executes it get the system time from the OS instead of 4D Server by using the command LAUNCH EXTERNAL PROCESS.

If (True)
   If (False)
      Begin SQL
         /*
          Name: Current_time
          Path: Current_time

          Purpose: Workaround for twice a year time change bug
          Replaces the 4D function "Current time(*)"

          $0 - Time - current time from the systom of the server machine
         */
      End SQL
   End if
   C_TEXT($MethodName_T)
   $MethodName_T:=Current method name
    //===================== Declare Variables ==================================
    //method_parameters_declarations
   C_TIME($0)
    //---------------------------------------------------------------------
    //method_wide_constants_declarations
    //---------------------------------------------------------------------
    //local_variable_declarations
   C_LONGINT($Ndx;$SOA;$RIS;$OS_L)
   C_TEXT($Time_T;$AMPM_T;$Secs_T)
   C_TIME($Time_H;$Time2_H)
End if
//====================== Initialize and Setup ================================

PLATFORM PROPERTIES($OS_L)
$Time_T:=""

//======================== Method Actions ==================================

If ($OS_L=Mac OS)
   LAUNCH EXTERNAL PROCESS("date +%r";$Time_T;$Time_T)
   $Time_H:=Current time

    // Strip trailing characters, UNIX new line "\n"
    //
   $Time_T:=Substring($Time_T;1;11)

Else
    // Returns only HH:MM
    //
   SET ENVIRONMENT VARIABLE("_4D_OPTION_HIDE_CONSOLE";"True") // Hide the cosole
   LAUNCH EXTERNAL PROCESS("cmd.exe /C TIME/T";$Time_T;$Time_T)

    // Get the seconds from the Current time function
    //
   $Time_H:=Current time
   $Secs_T:=Time string($Time_H)
   $Secs_T:=Substring($Secs_T;Length($Secs_T)-2)

    // Parse down the time string
    //
   $Time_T:=Substring($Time_T;1;Length($Time_T)-2)
   $AMPM_T:=Substring($Time_T;Length($Time_T)-2)
   $Time_T:=Substring($Time_T;1;Length($Time_T)-3)

    // Build the final time string
    //
   $Time_T:=$Time_T+$Secs_T+$AMPM_T

End if

$Time_H:=Time($Time_T)

//======================== Clean up and Exit =================================

$0:=$Time_H