Libraries: High-Performance Time Functions (TimeUtils) - page 2

 
amrali #:
Watch out:
1970*5844 (11,512,680) - 11,512,692 = minus 
There is right-shift for the minus.

True. But I left it like that, because in this case it doesn't affect the result.


But here it does, so the array is of a different type.

Форум по трейдингу, автоматическим торговым системам и тестированию торговых стратегий

Особенности языка mql5, тонкости и приёмы работы

amrali, 2024.11.29 14:06

    static const int Months[] = { 0, 11512692, 11512196, 11511744, 11511248, 11510766, 11510272, 11509790, 11509296, 11508797, 11508318, 11507822, 11507342 };
 
fxsaber #:

True. But I left it like that, because in this case it doesn't affect the result.


But here it does, so the array is of a different type.

I am not feeling comfortable with mixing variables types here. Surely it'll cause problems as I dont understand how this expression gets evaluated.
 
Thank you for sharing this amazing work.
 
very good and educative base on time accuracy and performances
 

Update 9 December 2024 - version 1.20

Added TimeFormat() function to format the time according to the passed string of tokens.

//+------------------------------------------------------------------+
//| Get the formatted time according to the passed string of tokens. |
//| List of all available formats:                                   |
//| Format  Output            Description                            |
//| ------  ----------------  -------------------------------------  |
//| YY      18                Two-digit year                         |
//| YYYY    2018              Four-digit year                        |
//| M       1-12              The month, beginning at 1              |
//| MM      01-12             The month, 2-digits                    |
//| MMM     Jan-Dec           The abbreviated month name, 3-letters  |
//| MMMM    January-December  The full month name                    |
//| D       1-31              The day of the month                   |
//| DD      01-31             The day of the month, 2-digits         |
//| DDD     Sun-Sat           The short name of the day of the week  |
//| DDDD    Sunday-Saturday   The name of the day of the week        |
//| h       0-23              The hour                               |
//| hh      00-23             The hour, 2-digits                     |
//| H       1-12              The hour, 12-hour clock                |
//| HH      01-12             The hour, 12-hour clock, 2-digits      |
//| m       0-59              The minute                             |
//| mm      00-59             The minute, 2-digits                   |
//| s       0-59              The second                             |
//| ss      00-59             The second, 2-digits                   |
//| A       AM PM                                                    |
//| a       am pm                                                    |
//+------------------------------------------------------------------+
//| Sample formats:                                                  |
//| "YYYY.MM.DD hh:mm"           // "2024.12.08 22:05"  (default)    |
//| "DDD, YYYY.MM.DD hh:mm:ss"   // "Sun, 2024.12.08 22:05:21"       |
//| "D MMMM YYYY, HH:mm a"       // "8 December 2024, 10:05 pm"      |
//| "DD/MM/YYYY"                 // "08/12/2024"                     |
//+------------------------------------------------------------------+
string TimeFormat(const datetime t, const string format = "YYYY.MM.DD hh:mm");

 

Update 10 December 2024 - version 1.30

Optimized TimeFormat(), StartOfYear() and EndOfYear() functions. Updated descriptions of some functions.

 

Update 15 December 2024 - version 1.35

Optimized the GetNthWeekdayInYearMonth() function.

 

Update 18 December 2024 - version 1.40

Added IsCurrentXXX(), IsToday(), IsTomorrow() and IsYesterday() functions.

//+==================================================================+
//| IsCurrent() Units                                                |
//+==================================================================+
bool IsCurrentMinute(datetime t)
bool IsCurrentHour(datetime t)
bool IsCurrentWeek(datetime t, bool StartsOnMonday = false)
bool IsCurrentMonth(datetime t)
bool IsCurrentYear(datetime t)
bool IsToday(datetime t)
bool IsTomorrow(datetime t)
bool IsYesterday(datetime t)

 

Update 21 December 2024 - version 1.55

Simplified calculations in AddMonths(): replaced the complex logic of adjusting months and years with a simpler total months calculation.

 
كم ساعة في العمل