MCPcopy Create free account
hub / github.com/abbeycode/UnrarKit / GetLocal

Method GetLocal

Libraries/unrar/timefn.cpp:3–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1#include "rar.hpp"
2
3void RarTime::GetLocal(RarLocalTime *lt)
4{
5#ifdef _WIN_ALL
6 FILETIME ft;
7 GetWinFT(&ft);
8 FILETIME lft;
9
10 if (WinNT() < WNT_VISTA)
11 {
12 // SystemTimeToTzSpecificLocalTime based code produces 1 hour error on XP.
13 FileTimeToLocalFileTime(&ft,&lft);
14 }
15 else
16 {
17 // We use these functions instead of FileTimeToLocalFileTime according to
18 // MSDN recommendation: "To account for daylight saving time
19 // when converting a file time to a local time ..."
20 SYSTEMTIME st1,st2;
21 FileTimeToSystemTime(&ft,&st1);
22 SystemTimeToTzSpecificLocalTime(NULL,&st1,&st2);
23 SystemTimeToFileTime(&st2,&lft);
24
25 // Correct precision loss (low 4 decimal digits) in FileTimeToSystemTime.
26 FILETIME rft;
27 SystemTimeToFileTime(&st1,&rft);
28 uint64 Corrected=INT32TO64(ft.dwHighDateTime,ft.dwLowDateTime)-
29 INT32TO64(rft.dwHighDateTime,rft.dwLowDateTime)+
30 INT32TO64(lft.dwHighDateTime,lft.dwLowDateTime);
31 lft.dwLowDateTime=(DWORD)Corrected;
32 lft.dwHighDateTime=(DWORD)(Corrected>>32);
33 }
34
35 SYSTEMTIME st;
36 FileTimeToSystemTime(&lft,&st);
37 lt->Year=st.wYear;
38 lt->Month=st.wMonth;
39 lt->Day=st.wDay;
40 lt->Hour=st.wHour;
41 lt->Minute=st.wMinute;
42 lt->Second=st.wSecond;
43 lt->wDay=st.wDayOfWeek;
44 lt->yDay=lt->Day-1;
45
46 static int mdays[12]={31,28,31,30,31,30,31,31,30,31,30,31};
47 for (uint I=1;I<lt->Month && I<=ASIZE(mdays);I++)
48 lt->yDay+=mdays[I-1];
49
50 if (lt->Month>2 && IsLeapYear(lt->Year))
51 lt->yDay++;
52#else
53 time_t ut=GetUnix();
54 struct tm *t;
55 t=localtime(&ut);
56
57 lt->Year=t->tm_year+1900;
58 lt->Month=t->tm_mon+1;
59 lt->Day=t->tm_mday;
60 lt->Hour=t->tm_hour;

Callers 2

ReadHeader15Method · 0.80
GenArcNameFunction · 0.80

Calls 2

WinNTFunction · 0.85
IsLeapYearFunction · 0.85

Tested by

no test coverage detected