Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29341 Discussions

Alternative to UNPACKTIMEQQ, neglecting summer/winter time change?

Gerdes_Gerhard_J
Beginner
563 Views
Is there an alternative to the time packing and unpacking routines PACKTIMEQQ and UNPACKTIMEQQ, which neglect the summer/winter time change?

Gerd
0 Kudos
4 Replies
Paul_Curtis
Valued Contributor I
563 Views

I cannot figure out whether this request is for time manipulation routines which include, or which explicitly fail to include, daylight savings corrections, or if this question is about packing/unpacking or about interval calculation (?).

I do time interval calculations using julian dates, which ignore daylight savings time; routines for this purpose have been posted here several times.
0 Kudos
Gerdes_Gerhard_J
Beginner
563 Views
Quoting - Paul Curtis

I cannot figure out whether this request is for time manipulation routines which include, or which explicitly fail to include, daylight savings corrections, or if this question is about packing/unpacking or about interval calculation (?).

I do time interval calculations using julian dates, which ignore daylight savings time; routines for this purpose have been posted here several times.

Thanks for your reply. but sorry, if I ask for something which seems already to be well known to this community.

My question was on a routine, unpacking the Unix time format, but not considering daylight savings, i.e. a continuous time stamp without any gaps or duobled hours.

Could you tell me, where I can the mentioned routines or under which keyword?
0 Kudos
Paul_Curtis
Valued Contributor I
563 Views
... unpacking the Unix time format, but not considering daylight savings, i.e. a continuous time stamp without any gaps or duobled hours...

The time format is only a format; it is the timevalue data which needs to be correct. Timestamp data provided by the opsys (ie, Windows) reports the local system clock, which typically tracks DST, or DST correction can be disabled at the system level (checkbox on date-and-time/time-zone dialog). GMT can be obtained from the web directly.
0 Kudos
IanH
Honored Contributor III
563 Views
It depends a bit on what you are trying to do.

Assuming by "unix time" you are referring to the time fields in the buffer argument of GETFILEINFOQQ, then you could roll-your-own by calling a non-standard variant of gmtime from the C library. That's all that UNPACKTIMEQQ appears to do (except it calls a non-standard variant of localtime). It is not portable but the following demonstrates an approach that works at least for win32 with VS2005 libraries (you will need to create a file 'TextFile1.txt' for this program to work with).

Another option is to directly use the Windows API - depending on what you want to do this may be even easier - the underlying representation of time within Windows for most things is already based on UTC.

[plain]MODULE FortranGMTime
  USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_INT
  IMPLICIT NONE  
  TYPE, BIND(C) :: tm_type 
    INTEGER(C_INT) :: tm_sec
    INTEGER(C_INT) :: tm_min
    INTEGER(C_INT) :: tm_hour
    INTEGER(C_INT) :: tm_mday
    INTEGER(C_INT) :: tm_mon
    INTEGER(C_INT) :: tm_year     ! Less 1900
    INTEGER(C_INT) :: tm_wday
    INTEGER(C_INT) :: tm_yday
    INTEGER(C_INT) :: tm_isdst
  END TYPE tm_type  
CONTAINS
  SUBROUTINE do_gmtime32(timer, tm)  
    USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_PTR, C_F_POINTER  
    INTEGER(4), INTENT(IN) :: timer
    TYPE(tm_type), INTENT(OUT) :: tm        
    TYPE(C_PTR) :: tm_cptr
    TYPE(tm_type), POINTER :: tm_fptr    
    INTERFACE
      ! _gmtime32 is a MS variant of gmtime where timer is 32 bit
      FUNCTION gmtime32(timer) RESULT(tm_ptr) BIND(C, NAME='_gmtime32')
        USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_PTR
        INTEGER(4), INTENT(IN) :: timer
        TYPE(C_PTR) :: tm_ptr
      END FUNCTION gmtime32    
    END INTERFACE    
    !****
    tm_cptr = gmtime32(timer)
    CALL C_F_POINTER(tm_cptr, tm_fptr)
    tm = tm_fptr    
  END SUBROUTINE do_gmtime32
END MODULE 

PROGRAM FileTime
  USE IFPORT
  USE FortranGMTime  
  IMPLICIT NONE
  INTEGER(4) :: res
  TYPE(FILE$INFO) :: fi
  INTEGER(INT_PTR_KIND()) :: handle  
  INTEGER(2) :: year, month, day, hour, minute, second  
  TYPE(tm_type) :: tm    
  !****
  handle = FILE$FIRST  
  res = GETFILEINFOQQ('TextFile1.txt', fi, handle)  
  CALL UNPACKTIMEQQ(fi%LASTWRITE, year, month, day, hour, minute, second)  
  ! Local time
  WRITE (*, "('Local:',6(I4,:,','))") year, month, day, hour, minute, second   
  ! UTC
  CALL do_gmtime32(fi%LASTWRITE, tm)
  WRITE (*, "('UTC:  ',6(I4,:,','))") tm%tm_year + 1900, tm%tm_mon,  &
      tm%tm_mday, tm%tm_hour, tm%tm_min, tm%tm_sec     
END PROGRAM FileTime
[/plain]

0 Kudos
Reply