Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
some date/time/timestamp functions revisited
#4
Well done but for Windows only. I made an attempt to fix the "TIM.UTC~&&()" function so it worked for Linux but was unsuccessful. Must instead use "gmtime()" or "mktime()" from C library and "struct tm" which is ordered a bit differently and doesn't offer milliseconds. The "mktime()" takes only one parameter of "struct tm" but goes on local time not UTC. The "gmtime()" however is more complicated to use, the first parameter is a structure with "calendar" time and the second parameter is the return value of type "struct tm". Is the "TIM.UTC~&&()" used to get today's date and current time? That's how I attempted to fix it.

This is the one function in mdijkens' code that I tried to fix:

Code: (Select All)
Function TIM.utc~&& ()
$IF WIN THEN
  Type UTCtype
    year As Integer
    month As Integer
    weekday As Integer
    day As Integer
    hour As Integer
    minute As Integer
    second As Integer
    millis As Integer
  End Type
  Declare Dynamic Library "Kernel32"
    Sub GetUTC Alias GetSystemTime (lpSystemTime As UTCtype)
  End Declare
  Dim utc As UTCtype: GetUTC utc
  TIM.utc~&& = TIM.stamp~&&(utc.year, utc.month, utc.day, utc.hour, utc.minute, utc.second)
$ELSE
  Type UTCtype
    second as Integer
    minute as Integer
    hour as Integer
    day as Integer
    month as Integer
    year as Integer
    weekday as Integer
    yearday as Integer
    isdst as Integer
    tmgmtoff as Long
    tmzone as _Offset
  End Type
  Declare CustomType Library
    Sub GetUTC Alias mktime (lpSystemTime As UTCtype)
  End Declare
  Dim utc As UTCtype: GetUTC utc
  TIM.utc~&& = TIM.stamp~&&(utc.year, utc.month, utc.day, utc.hour, utc.minute, utc.second)
$END IF
End Function

and this is the "struct tm" definition and the two C functions:

Code: (Select All)
/* from "(include_path)/bits/types/struct_tm.h" */
struct tm
{
  int tm_sec;            /* Seconds.    [0-60] (1 leap second) */
  int tm_min;            /* Minutes.    [0-59] */
  int tm_hour;            /* Hours.    [0-23] */
  int tm_mday;            /* Day.        [1-31] */
  int tm_mon;            /* Month.    [0-11] */
  int tm_year;            /* Year    - 1900.  */
  int tm_wday;            /* Day of week.    [0-6] */
  int tm_yday;            /* Days in year.[0-365]    */
  int tm_isdst;            /* DST.        [-1/0/1]*/

# ifdef    __USE_MISC
  long int tm_gmtoff;        /* Seconds east of UTC.  */
  const char *tm_zone;        /* Timezone abbreviation.  */
# else
  long int __tm_gmtoff;        /* Seconds east of UTC.  */
  const char *__tm_zone;    /* Timezone abbreviation.  */
# endif
};

/* from "(include_path)/time.h" */
extern struct tm *gmtime (const time_t *__timer) __THROW;
# ifdef __REDIRECT_NTH
extern struct tm*__REDIRECT_NTH (gmtime, (const time_t *__timer), __gmtime64);
# endif
extern time_t mktime (struct tm *__tp) __THROW;
Reply


Messages In This Thread
RE: some date/time/timestamp functions revisited - by mnrvovrfc - 03-02-2023, 11:32 AM



Users browsing this thread: 3 Guest(s)