Exemple #1
0
static void RtlSystemTimeToLocalTime( const LARGE_INTEGER *SystemTime,
                                      LARGE_INTEGER *LocalTime ) {
  int bias, daylight;
  time_t gmt = time(NULL);
  bias = TIME_GetBias(gmt, &daylight);
  LocalTime->QuadPart = SystemTime->QuadPart + bias * (LONGLONG)10000000;
}
BOOL WINAPI FileTimeToDosDateTime( const FILETIME *ft, WORD *fatdate, WORD *fattime ) {
  LARGE_INTEGER       li;
  ULONG               t;
  time_t              unixtime;
  struct tm*          tm;
  WORD fat_d,fat_t;

  TRACEN((printf("FileTimeToDosDateTime\n")))
  li.QuadPart = ft->dwHighDateTime;
  li.QuadPart = (li.QuadPart << 32) | ft->dwLowDateTime;
  RtlTimeToSecondsSince1970( &li, &t );
  unixtime = t - TIME_GetBias();
  tm = gmtime( &unixtime );

  fat_t = (tm->tm_hour << 11) + (tm->tm_min << 5) + (tm->tm_sec / 2);
  fat_d = ((tm->tm_year - 80) << 9) + ((tm->tm_mon + 1) << 5) + tm->tm_mday;
  if (fattime)
    *fattime = fat_t;
  if (fatdate)
    *fatdate = fat_d;

  TRACEN((printf("FileTimeToDosDateTime : %lx %lx => %d %d\n",
	(long)ft->dwHighDateTime,(long)ft->dwLowDateTime,(unsigned)fat_d,(unsigned)fat_t)))

  return TRUE;
}
Exemple #3
0
static inline NTSTATUS WINAPI RtlLocalTimeToSystemTime( const LARGE_INTEGER *LocalTime,
    LARGE_INTEGER *SystemTime) {

  TRACEN((printf("RtlLocalTimeToSystemTime\n")))
  LONG bias = TIME_GetBias();
  SystemTime->QuadPart = LocalTime->QuadPart + bias * (LONGLONG)TICKSPERSEC;
  return STATUS_SUCCESS;
}
Exemple #4
0
/******************************************************************************
 *       RtlSystemTimeToLocalTime [NTDLL.@]
 *
 * Convert a system time into a local time.
 *
 * PARAMS
 *   SystemTime [I] System time to convert.
 *   LocalTime  [O] Destination for the converted time.
 *
 * RETURNS
 *   Success: STATUS_SUCCESS.
 *   Failure: An NTSTATUS error code indicating the problem.
 */
NTSTATUS WINAPI RtlSystemTimeToLocalTime( const LARGE_INTEGER *SystemTime,
                                          PLARGE_INTEGER LocalTime )
{
    LONG bias;

    TRACE("(%p, %p)\n", SystemTime, LocalTime);

    bias = TIME_GetBias();
    LocalTime->QuadPart = SystemTime->QuadPart - bias * (LONGLONG)TICKSPERSEC;
    return STATUS_SUCCESS;
}
Exemple #5
0
static void WINAPI RtlLocalTimeToSystemTime( const LARGE_INTEGER *LocalTime,
    LARGE_INTEGER *SystemTime) {
  time_t gmt;
  int bias, daylight;

  TRACEN((printf("RtlLocalTimeToSystemTime\n")))
  gmt = time(NULL);
  bias = TIME_GetBias(gmt, &daylight);

  SystemTime->QuadPart = LocalTime->QuadPart - bias * (LONGLONG)10000000;
}
Exemple #6
0
/***********************************************************************
 *              SetSystemTime            (KERNEL32.@)
 *
 *  Sets the system time (utc).
 *
 * RETURNS
 *
 *  True if the time was set, false if the time was invalid or the
 *  necessary permissions were not held.
 */
BOOL WINAPI SetSystemTime(
    const SYSTEMTIME *systime) /* [in] The desired system time. */
{
    struct timeval tv;
    struct timezone tz;
    struct tm t;
    time_t sec, oldsec;
    int dst, bias;
    int err;

    /* call gettimeofday to get the current timezone */
    gettimeofday(&tv, &tz);
    oldsec=tv.tv_sec;
    /* get delta local time from utc */
    bias=TIME_GetBias(oldsec,&dst);

    /* get the number of seconds */
    t.tm_sec = systime->wSecond;
    t.tm_min = systime->wMinute;
    t.tm_hour = systime->wHour;
    t.tm_mday = systime->wDay;
    t.tm_mon = systime->wMonth - 1;
    t.tm_year = systime->wYear - 1900;
    t.tm_isdst = dst;
    sec = mktime (&t);
    /* correct for timezone and daylight */
    sec += bias;

    /* set the new time */
    tv.tv_sec = sec;
    tv.tv_usec = systime->wMilliseconds * 1000;

    /* error and sanity check*/
    if( sec == (time_t)-1 || abs((int)(sec-oldsec)) > SETTIME_MAX_ADJUST ){
        err = 1;
        SetLastError(ERROR_INVALID_PARAMETER);
    } else {
#ifdef HAVE_SETTIMEOFDAY
        err=settimeofday(&tv, NULL); /* 0 is OK, -1 is error */
        if(err == 0)
            return TRUE;
        SetLastError(ERROR_PRIVILEGE_NOT_HELD);
#else
	err = 1;
	SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
#endif
    }
    ERR("Cannot set time to %d/%d/%d %d:%d:%d Time adjustment %ld %s\n",
            systime->wYear, systime->wMonth, systime->wDay, systime->wHour,
            systime->wMinute, systime->wSecond,
            sec-oldsec, err == -1 ? "No Permission" :
                sec==(time_t)-1 ? "" : "is too large." );
    return FALSE;
}
Exemple #7
0
/***********************************************************************
 *              GetTimeZoneInformation  (KERNEL32.@)
 *
 *  Fills in the a time zone information structure with values based on
 *  the current local time.
 *
 * RETURNS
 *
 *  The daylight savings time standard or TIME_ZONE_ID_INVALID if the call failed.
 */
DWORD WINAPI GetTimeZoneInformation(
    LPTIME_ZONE_INFORMATION tzinfo) /* [out] The time zone structure to be filled in. */
{
    time_t gmt;
    int bias, daylight;
    const WCHAR *psTZ;


    memset(tzinfo, 0, sizeof(TIME_ZONE_INFORMATION));

    gmt = time(NULL);
    bias=TIME_GetBias(gmt,&daylight);

    tzinfo->Bias = -bias / 60;
    tzinfo->StandardBias = 0;
    tzinfo->DaylightBias = -60;
    psTZ = TIME_GetTZAsStr (gmt, (-bias/60), daylight);
    if (psTZ) strcpyW( tzinfo->StandardName, psTZ );
    return TIME_ZONE_ID_STANDARD;
}
BOOL WINAPI DosDateTimeToFileTime( WORD fatdate, WORD fattime, FILETIME * ft) {
  struct tm newtm;

  TRACEN((printf("DosDateTimeToFileTime\n")))
  // memset(&newtm,0,sizeof(newtm));
  newtm.tm_sec  = (fattime & 0x1f) * 2;
  newtm.tm_min  = (fattime >> 5) & 0x3f;
  newtm.tm_hour = (fattime >> 11);
  newtm.tm_mday = (fatdate & 0x1f);
  newtm.tm_mon  = ((fatdate >> 5) & 0x0f) - 1;
  newtm.tm_year = (fatdate >> 9) + 80;
  newtm.tm_isdst = -1;

  time_t time1 = mktime(&newtm);
  LONG   bias  = TIME_GetBias();
  RtlSecondsSince1970ToFileTime( time1 - bias, ft );

  TRACEN((printf("DosDateTimeToFileTime(%ld,%ld) t1=%ld bias=%ld => %lx %lx\n",
	(long)fatdate,(long)fattime,(long)time1,(long)bias,
	(long)ft->dwHighDateTime,(long)ft->dwLowDateTime)))

  return TRUE;
}
Exemple #9
0
static inline void RtlSystemTimeToLocalTime( const LARGE_INTEGER *SystemTime,
                                      LARGE_INTEGER *LocalTime ) {
  LONG bias = TIME_GetBias();
  LocalTime->QuadPart = SystemTime->QuadPart - bias * (LONGLONG)TICKSPERSEC;
}