TimeGMT and TimeGMTOffset and Daylight Savings??? - page 2

 
GreenMoney:


I've previously posted code and information about calculating the start and end dates for American DST and European DST.

Here are two functions that use those calculations:

American DST

European DST

Using the dates returned by the above functions, one could determine whether a specific date/time is within American or European DST.

Working perfectly! Thank you.


my modification for London Time: 

int TimeShift=0;



    datetime time_GMT=TimeGMT();

    MqlDateTime timestruct_GMT;

    TimeToStruct(time_GMT, timestruct_GMT);

    int year= timestruct_GMT.year;

    int month =timestruct_GMT.mon;

    int day= timestruct_GMT.day;

    int hour= timestruct_GMT.hour;

    if (year < 1996) 

      { Print ("EuropeanDST(): Invalid year."); }



   int DST_start_dom = 0, DST_end_dom = 0;

   DST_start_dom = 31 - MathMod((4 + MathFloor(5*year/4)), 7);

   DST_end_dom = 31 - MathMod((1 + MathFloor(5*year/4)), 7);  

   if((month>=3 && day>=DST_start_dom && hour>=1)&&(month<=10 && day<=DST_end_dom && hour<1))

   {TimeShift=3600;}

   else TimeShift=0;

   

   

 
BOCTOK KOCMOC:

Working perfectly! Thank you.


my modification for London Time: 

   .
The condition will not always true.

int TimeShift;
void forTime(){
    datetime time_GMT=TimeGMT();

    int DST_start_dom = 0, DST_end_dom = 0;
    int year=TimeYear(time_GMT);
   DST_start_dom = 31 - MathMod((4 + MathFloor(5*year/4)), 7);
   DST_end_dom = 31 - MathMod((1 + MathFloor(5*year/4)), 7);
   datetime DST_Start = StrToTime(StringConcatenate(year, ".03.01")) + ((DST_start_dom - 1) * 86400) + 3600;     // last Sunday in March 
   datetime DST_End = StrToTime(StringConcatenate(year, ".10.01")) + ((DST_end_dom - 1) * 86400) + 7200;         // last Sunday in October 

   if(DST_Start<time_GMT && time_GMT <DST_End)

   {TimeShift=3600;}

   else TimeShift=0;
   
}
datetime Time(){
        return TimeGMT()+TimeShift;
}   
int OnInit()
{
        forTime();
}

   

here's the modified code.
Reason: