- #include <WinUser32.mqh>
- #import "Kernel32.dll"
- int GetTimeZoneInformation(int &TIME_ZONE_INFORMATION[]);
- void GetSystemTime(int &SYSTEMTIME[]);
- #import
- //------ Get GMT Offset by GetTimeZoneInformation() - modified from CrapperQuotes source ------//
- int GMT_Off_GetTimeZoneInformation()//20
- {
- int a[43],offlocmin,n;
- n=TimeCurrent()-TimeLocal(); // server time - local time, in seconds
- switch(GetTimeZoneInformation(a))
- {
- case 0: // no daylight saving in local time zone, or unkown
- offlocmin=a[0];
- break;
- case 1: // local system is operating in standard time (no daylight saving time)
- offlocmin=a[0];
- break;
- case 2: // local system is operating in daylight saving time
- offlocmin=a[0]+a[42];
- break;
- }
- return(MathRound(n/3600.0-offlocmin/60.0));
- }
- //------ Get GMT Offset by GetSystemTime() - unknown source ------//
- int GMT_Off_GetSystemTime()//10
- {
- double GMT_Diff;
- int SYSTEMTIME[4];
- int nYear,nMonth,nDay,nHour,nMin,nSec,nMilliSec;
- string sMonth,sDay,sHour,sMin,sSec;
- string sUTC_Time;
- GetSystemTime(SYSTEMTIME);//API
- nYear = SYSTEMTIME[0]&0x0000FFFF;
- nMonth = SYSTEMTIME[0]>>16;
- nDay = SYSTEMTIME[1]>>16;
- nHour = SYSTEMTIME[2]&0x0000FFFF;
- nMin = SYSTEMTIME[2]>>16;
- nSec = SYSTEMTIME[3]&0x0000FFFF;
- nMilliSec = SYSTEMTIME[3]>>16;
- sMonth = 100 + nMonth;
- sMonth = StringSubstr(sMonth, 1);
- sDay = 100 + nDay;
- sDay = StringSubstr(sDay, 1);
- sHour = 100 + nHour;
- sHour = StringSubstr(sHour, 1);
- sMin = 100 + nMin;
- sMin = StringSubstr(sMin, 1);
- sSec = 100 + nSec;
- sSec = StringSubstr(sSec, 1);
- sUTC_Time=StringConcatenate(nYear,".",sMonth,".",sDay," ",sHour,":",sMin,":",sSec);
- GMT_Diff=TimeCurrent()-StrToTime(sUTC_Time);
- return(MathRound(GMT_Diff / 3600.0));
- }
-
- // Get GMT Offset in several possible ways
- int GetGMT_Offset()
- {
- bool IsPlausible1=false,IsPlausible2=false,IsIdentical=false;
- int GMT_Offset1,GMT_Offset2;
- GMT_Offset1 = GMT_Off_GetSystemTime(); //10
- GMT_Offset2 = GMT_Off_GetTimeZoneInformation(); //20
- if(-12<=GMT_Offset1 && GMT_Offset1<=12)
- IsPlausible1=true;
- if(-12<=GMT_Offset2 && GMT_Offset2<=12)
- IsPlausible2=true;
- if(GMT_Offset1==GMT_Offset2)
- IsIdentical=true;
- if(IsIdentical && IsPlausible1)
- {
- ERR_GMT_Offset=0;
- return(GMT_Offset1);
- }
- ERR_GMT_Offset++; // if not identical or not plausible, then increase error counter and return most suitable value
- if(IsPlausible1 && !IsPlausible2)
- return(GMT_Offset1);
- else if(!IsPlausible1 && IsPlausible2)
- return(GMT_Offset2);
- else // leave unchanged
- return(GMT_Offset);
- }
复制代码
|