StrToTime() bug?

 

Hello,

now I may just be missing something here.

      string Begin="03:00";
      string End="23:00";
      Print("Current Time = ",TimeCurrent());
      Print("Begin Time = ",StrToTime(Begin));
      Print("Finish Time = ",StrToTime(End)); 

resulted in


0 03:59:07.242 Scratchings NZDUSD,H1: Current Time = 2018.05.08 23:59:06

0 03:59:07.242 Scratchings NZDUSD,H1: Begin Time = 2018.05.09 03:00:00

0 03:59:07.242 Scratchings NZDUSD,H1: Finish Time = 2018.05.09 23:00:00

As you can see, the date for the current time is 8th, but Begin and Finish are both 9th.

This was just before midnight broker time and just before 4 AM my computer time.

I ran the code again when broker midnight passed


0 04:00:30.517 Scratchings NZDUSD,H1: Current Time = 2018.05.09 00:00:19

0 04:00:30.517 Scratchings NZDUSD,H1: Begin Time = 2018.05.09 03:00:00

0 04:00:30.517 Scratchings NZDUSD,H1: Finish Time = 2018.05.09 23:00:00

and then all dates were the 9th.

Documentation states

 var2=StrToTime("17:35");      // returns the current date with the given time 

So is the current date taken from Local time not broker time?

That doesn't make sense.

 
For the current day
datetime Current= TimeCurrent(),
         Begin  = StringToTime( TimeToString(Current, TIME_DATE) + " 03:00" ),
         End    = StringToTime( TimeToString(Current, TIME_DATE) + " 23:00" );
Print("Current Time = ", Current);
Print("Begin Time = ",   Begin);
Print("Finish Time = ",  End);
 
Konstantin Nikitin:
For the current day

You seem to have missed the point.

I was talking about a possible problem with StrToTime()

 

TimeCurrent is always broker-server time. Your begin and end times had rolled-over to the next day since those times had already passed. Working with time using strings is asking for weird bugs like this. Instead, you should practice working with time using literal integers and the Mql-time-structs and convert back and forth with the structs instead of time-strings. It may be more verbose, but you always know exactly what you're getting.

So for example if I know I need to set some times for the following trading day the method is as follows. 

#property strict

void OnStart()
{
   MqlDateTime begin,end;
   TimeToStruct(TimeCurrent()+PeriodSeconds(PERIOD_D1),begin);
   begin.sec=0;
   begin.min=0;
   end=begin;
   begin.hour=3;
   end.hour=23;
   printf(
      "%s -> %s",
      TimeToString(StructToTime(begin)),
      TimeToString(StructToTime(end))
   );
}
 

Seems like you have all missed the point.

The function should return the time with the current broker's date not my local time date.

I am not asking for alternatives I am suggesting that there might be a bug.

I have reported it to the service desk, so will see what they have to say.

 
Keith Watford:

Seems like you have all missed the point.

The function should return the time with the current broker's date not my local time date.

I am not asking for alternatives I am suggesting that there might be a bug.

I have reported it to the service desk, so will see what they have to say.

You are running it at your computer so it uses local time and not broker time, seems logical to me. I doubt it's a bug, the problem is rather it's not documented.
 
Keith Watford :

Seems like you have all missed the point.

The function should return the time with the current broker's date not my local time date.

I am not asking for alternatives I am suggesting that there might be a bug.

I have reported it to the service desk , so will see what they have to say.

And this is not the server date???

datetime Current= TimeCurrent(),
         Begin  = StringToTime( TimeToString(Current, TIME_DATE) + " 03:00" ),
         End    = StringToTime( TimeToString(Current, TIME_DATE) + " 23:00" );

You can use this way

MqlDateTime structTime;
TimeToStruct(TimeCurrent(), structTime);
structTime.min  = 0;
structTime.sec  = 0;
structTime.hour = 3;
datetime begin  = StructToTime( structTime );
structTime.hour = 23;
datetime end    = StructToTime( structTime );
P.S. You need to get the server date. Then use. As you wish.
 
Alain Verleyen:
You are running it at your computer so it uses local time and not broker time, seems logical to me. I doubt it's a bug, the problem is rather it's not documented.

Yes Alain, apparently, according to service desk it is local time. As you say the documentation does not mention this at all.

From codes done by other coders that I have modified, I know that a lot assume that this is broker time, not local time. Luckily I have rarely used this function myself.

 
Keith Watford:

Yes Alain, apparently, according to service desk it is local time. As you say the documentation does not mention this at all.

From codes done by other coders that I have modified, I know that a lot assume that this is broker time, not local time. Luckily I have rarely used this function myself.

Yes it's useful to know it. Thanks.
Reason: