From 2b9fc6f201bf38689ad18d4a3253c66ba0d9b5fb Mon Sep 17 00:00:00 2001 From: Aster Seker Date: Thu, 2 Jul 2026 22:08:16 +0300 Subject: [PATCH 1/3] fix(mql): restore MetaEditor compilation Adjust MQL5 DateTime construction and ISO date validation for MetaEditor, and expose MQL4 TimeShield constant access through static methods. --- MQL4/Include/TimeShield.mqh | 30 ++++++++++++++++++++++++ MQL5/Include/time_shield/DateTime.mqh | 22 +++++++++++------ MQL5/Include/time_shield/time_parser.mqh | 2 +- 3 files changed, 46 insertions(+), 8 deletions(-) diff --git a/MQL4/Include/TimeShield.mqh b/MQL4/Include/TimeShield.mqh index d4e789b1..01d80d6b 100644 --- a/MQL4/Include/TimeShield.mqh +++ b/MQL4/Include/TimeShield.mqh @@ -25,6 +25,36 @@ public: SEC_PER_DAY = 86400 ///< Seconds per day. }; + /// \brief Get milliseconds per second. + /// \return Milliseconds per second. + static int ms_per_sec() { + return MS_PER_SEC; + } + + /// \brief Get microseconds per second. + /// \return Microseconds per second. + static int us_per_sec() { + return US_PER_SEC; + } + + /// \brief Get seconds per minute. + /// \return Seconds per minute. + static int sec_per_min() { + return SEC_PER_MIN; + } + + /// \brief Get seconds per hour. + /// \return Seconds per hour. + static int sec_per_hour() { + return SEC_PER_HOUR; + } + + /// \brief Get seconds per day. + /// \return Seconds per day. + static int sec_per_day() { + return SEC_PER_DAY; + } + /// \brief Get raw terminal tick counter in milliseconds. /// \return Wrapped 32-bit terminal tick counter. static uint tick_count_ms() { diff --git a/MQL5/Include/time_shield/DateTime.mqh b/MQL5/Include/time_shield/DateTime.mqh index 7db488c3..d082b281 100644 --- a/MQL5/Include/time_shield/DateTime.mqh +++ b/MQL5/Include/time_shield/DateTime.mqh @@ -34,14 +34,16 @@ namespace time_shield { /// \param offset Fixed UTC offset in seconds. /// \return Constructed DateTime. static DateTime from_unix_ms(const long utc_ms, const int offset = 0) { - return DateTime(utc_ms, offset); + DateTime result(utc_ms, offset); + return result; } /// \brief Construct instance for current UTC time. /// \param offset Fixed UTC offset in seconds. /// \return DateTime set to now. static DateTime now_utc(const int offset = 0) { - return DateTime(ts_ms(), offset); + DateTime result(ts_ms(), offset); + return result; } /// \brief Try to build from calendar components interpreted in provided offset. @@ -73,7 +75,8 @@ namespace time_shield { return false; const long local_ms = to_timestamp_ms(year, month, day, hour, min, sec, ms); - out = DateTime(local_ms - offset_to_ms(offset), offset); + DateTime result(local_ms - offset_to_ms(offset), offset); + out = result; return true; } @@ -94,7 +97,8 @@ namespace time_shield { return false; const long local_ms = dt_to_timestamp_ms(local_dt); - out = DateTime(local_ms - offset_to_ms(offset), offset); + DateTime result(local_ms - offset_to_ms(offset), offset); + out = result; return true; } @@ -108,8 +112,9 @@ namespace time_shield { if (!parse_iso8601(str, dt, tz)) return false; - out = DateTime(dt_to_timestamp_ms(dt) - offset_to_ms(time_zone_struct_to_offset(tz)), - time_zone_struct_to_offset(tz)); + const int offset = time_zone_struct_to_offset(tz); + DateTime result(dt_to_timestamp_ms(dt) - offset_to_ms(offset), offset); + out = result; return true; } @@ -123,7 +128,10 @@ namespace time_shield { int utc_offset() const { return m_offset; } /// \brief Return copy with new offset preserving instant. - DateTime with_offset(const int new_offset) const { return DateTime(m_utc_ms, new_offset); } + DateTime with_offset(const int new_offset) const { + DateTime result(m_utc_ms, new_offset); + return result; + } /// \brief Return copy with zero offset. DateTime to_utc() const { return with_offset(0); } diff --git a/MQL5/Include/time_shield/time_parser.mqh b/MQL5/Include/time_shield/time_parser.mqh index 424684af..ebbc6786 100644 --- a/MQL5/Include/time_shield/time_parser.mqh +++ b/MQL5/Include/time_shield/time_parser.mqh @@ -317,7 +317,7 @@ namespace time_shield { dt.mon =(int)StringToInteger(parts[1]); dt.day =(int)StringToInteger(parts[2]); - if(!is_valid_date(dt)) + if(!is_valid_date(dt.year, dt.mon, dt.day)) return false; if (StringLen(time_part)>0) { From f75c61a1d55577e486c83c4d1a58fa96a6a68935 Mon Sep 17 00:00:00 2001 From: Aster Seker Date: Thu, 2 Jul 2026 23:18:06 +0300 Subject: [PATCH 2/3] fix(mql4): expose prefixed constants Replace MQL4 TimeShield constant accessor methods with typed global TSHIELD-prefixed constants and document the public MQL4 constant style. --- MQL4/Include/TimeShield.mqh | 58 +++++++++---------------------------- README.md | 5 ++-- 2 files changed, 16 insertions(+), 47 deletions(-) diff --git a/MQL4/Include/TimeShield.mqh b/MQL4/Include/TimeShield.mqh index 01d80d6b..e74901af 100644 --- a/MQL4/Include/TimeShield.mqh +++ b/MQL4/Include/TimeShield.mqh @@ -13,48 +13,16 @@ #property link "https://github.com/NewYaroslav/time-shield-cpp" #property strict +const int TSHIELD_MS_PER_SEC = 1000; ///< Milliseconds per second. +const int TSHIELD_US_PER_SEC = 1000000; ///< Microseconds per second. +const int TSHIELD_SEC_PER_MIN = 60; ///< Seconds per minute. +const int TSHIELD_SEC_PER_HOUR = 3600; ///< Seconds per hour. +const int TSHIELD_SEC_PER_DAY = 86400; ///< Seconds per day. + /// \class TimeShield /// \brief Provides static time helpers for MQL4. class TimeShield { public: - enum Constants { - MS_PER_SEC = 1000, ///< Milliseconds per second. - US_PER_SEC = 1000000, ///< Microseconds per second. - SEC_PER_MIN = 60, ///< Seconds per minute. - SEC_PER_HOUR = 3600, ///< Seconds per hour. - SEC_PER_DAY = 86400 ///< Seconds per day. - }; - - /// \brief Get milliseconds per second. - /// \return Milliseconds per second. - static int ms_per_sec() { - return MS_PER_SEC; - } - - /// \brief Get microseconds per second. - /// \return Microseconds per second. - static int us_per_sec() { - return US_PER_SEC; - } - - /// \brief Get seconds per minute. - /// \return Seconds per minute. - static int sec_per_min() { - return SEC_PER_MIN; - } - - /// \brief Get seconds per hour. - /// \return Seconds per hour. - static int sec_per_hour() { - return SEC_PER_HOUR; - } - - /// \brief Get seconds per day. - /// \return Seconds per day. - static int sec_per_day() { - return SEC_PER_DAY; - } - /// \brief Get raw terminal tick counter in milliseconds. /// \return Wrapped 32-bit terminal tick counter. static uint tick_count_ms() { @@ -107,7 +75,7 @@ public: while((next_ts = ts()) == start_ts) { } - offset = next_ts * MS_PER_SEC - (long)monotonic_ms(); + offset = next_ts * TSHIELD_MS_PER_SEC - (long)monotonic_ms(); initialized = true; } @@ -130,14 +98,14 @@ public: /// \param timestamp Timestamp in seconds. /// \return Second of day. static int sec_of_day(const long timestamp) { - return (int)(timestamp % SEC_PER_DAY); + return (int)(timestamp % TSHIELD_SEC_PER_DAY); } /// \brief Get second of day from milliseconds timestamp. /// \param timestamp_ms Timestamp in milliseconds. /// \return Second of day. static int sec_of_day_ms(const long timestamp_ms) { - return sec_of_day(timestamp_ms / MS_PER_SEC); + return sec_of_day(timestamp_ms / TSHIELD_MS_PER_SEC); } /// \brief Get second of day from hours, minutes and seconds. @@ -146,7 +114,7 @@ public: /// \param second Second value. /// \return Second of day. static int sec_of_day(const int hour, const int minute, const int second) { - return hour * SEC_PER_HOUR + minute * SEC_PER_MIN + second; + return hour * TSHIELD_SEC_PER_HOUR + minute * TSHIELD_SEC_PER_MIN + second; } /// \brief Check time-of-day components. @@ -162,7 +130,7 @@ public: /// \brief Convert string with time of day to second of day. /// \param value Time string in HH, HH:MM, or HH:MM:SS format. - /// \return Second of day or SEC_PER_DAY on parse failure. + /// \return Second of day or TSHIELD_SEC_PER_DAY on parse failure. static int sec_of_day(const string value) { string parts[]; const ushort separator = StringGetCharacter(":", 0); @@ -170,7 +138,7 @@ public: if(count < 1 || count > 3) { ArrayFree(parts); - return SEC_PER_DAY; + return TSHIELD_SEC_PER_DAY; } int hour = 0; @@ -188,7 +156,7 @@ public: ArrayFree(parts); if(!is_valid_time(hour, minute, second)) { - return SEC_PER_DAY; + return TSHIELD_SEC_PER_DAY; } return sec_of_day(hour, minute, second); diff --git a/README.md b/README.md index 30cb3d2b..376270ef 100644 --- a/README.md +++ b/README.md @@ -94,8 +94,8 @@ library and report platform capabilities: C++ and MQL5 public headers place their declarations inside the `time_shield` namespace. Use `time_shield::` or `using namespace time_shield;` to access that -API. MQL4 uses the `TimeShield` class with static methods and constants because -the MQL4 language does not provide namespaces. +API. MQL4 uses the `TimeShield` class for static methods and `TSHIELD_` +constants because the MQL4 language does not provide namespaces. > Some functions depend on platform APIs and may be limited (for example, > obtaining realtime via `QueryPerformanceCounter` on Windows). @@ -189,6 +189,7 @@ Use `install_mql5.bat` to install the MQL5 files. For MQL4, copy long now_ms = TimeShield::now(); int second_day = TimeShield::sec_of_day(TimeCurrent()); +int one_day = TSHIELD_SEC_PER_DAY; ``` ### Integration Notes From e9d99727d705b263636b305d9bddfb4da0c6af0e Mon Sep 17 00:00:00 2001 From: Aster Seker Date: Thu, 2 Jul 2026 23:30:05 +0300 Subject: [PATCH 3/3] fix(mql5): keep single TimeShield header --- MQL5/Include/TimeShield.mqh | 63 ++++++++++++++++++++++++++--------- MQL5/Include/time_shield.mqh | 64 ------------------------------------ 2 files changed, 48 insertions(+), 79 deletions(-) delete mode 100644 MQL5/Include/time_shield.mqh diff --git a/MQL5/Include/TimeShield.mqh b/MQL5/Include/TimeShield.mqh index ee30e0c1..5edd6acb 100644 --- a/MQL5/Include/TimeShield.mqh +++ b/MQL5/Include/TimeShield.mqh @@ -1,18 +1,14 @@ //+------------------------------------------------------------------+ //| TimeShield.mqh | -//| MQL5 Facade for TimeShield C++ Library | //| Copyright 2025, NewYaroslav | //| https://github.com/NewYaroslav/time-shield-cpp | //+------------------------------------------------------------------+ -#ifndef __TIME_SHIELD_FACADE_MQH__ -#define __TIME_SHIELD_FACADE_MQH__ +#ifndef TIME_SHIELD_MQL5_MQH_INCLUDED +#define TIME_SHIELD_MQL5_MQH_INCLUDED /// \file TimeShield.mqh -/// \brief MQL5-style facade header for the Time Shield library. -/// -/// This is a thin wrapper over the internal `time_shield.mqh` header, designed -/// to provide a user-friendly PascalCase interface for MQL5 users. -/// Prefer `#include ` when using the library in MQL5. +/// \ingroup mql5 +/// \brief Main MQL5 header file for the Time Shield library. #property copyright "Copyright 2025, NewYaroslav" #property link "https://github.com/NewYaroslav/time-shield-cpp" @@ -20,19 +16,56 @@ /// \defgroup mql5 MQL5 TimeShield API /// \brief Components of the Time Shield library adapted for MetaTrader 5. -/// @{ /// -/// This group includes all functions, structures, and utilities that are part of the MQL5-compatible version -/// of the Time Shield library. +/// This group includes all functions, structures, and utilities that are part +/// of the MQL5-compatible version of the Time Shield library. /// /// Example usage: /// \code /// #include /// time_shield::DateStruct d = time_shield::create_date_struct(2025, 6, 21); /// \endcode -/// -/// @} -#include +// Constants used in time calculations +#include + +// Enumerations used in time representations +#include + +// Structures representing time components +#include + +// Structures representing date components +#include + +// Structure representing a time zone +#include + +// Structure representing date and time combinations +#include + +// Value-type wrapper for date-time with offset +#include + +// Functions for validation of time-related values +#include + +// Utility functions for time manipulation +#include + +// Functions for converting between different time representations +#include + +// Functions for converting between time zones +#include + +// Functions for formatting time in various standard formats +#include + +// Functions for parsing time in various standard formats +#include + +// Functions for initializing the library +#include -#endif // __TIME_SHIELD_FACADE_MQH__ \ No newline at end of file +#endif // TIME_SHIELD_MQL5_MQH_INCLUDED diff --git a/MQL5/Include/time_shield.mqh b/MQL5/Include/time_shield.mqh deleted file mode 100644 index b6536b0c..00000000 --- a/MQL5/Include/time_shield.mqh +++ /dev/null @@ -1,64 +0,0 @@ -//+------------------------------------------------------------------+ -//| TimeShield.mqh | -//| Copyright 2025, NewYaroslav | -//| https://github.com/NewYaroslav/time-shield-cpp | -//+------------------------------------------------------------------+ -#ifndef __TIME_SHIELD_MQH__ -#define __TIME_SHIELD_MQH__ - -/// \file time_shield.mqh -/// \ingroup mql5 -/// \brief Main header file for the Time Shield library. -/// -/// This header file includes all the components of the Time Shield library, -/// making it easy to include the entire library in your projects with a single -/// include directive. - -#property copyright "Copyright 2025, NewYaroslav" -#property link "https://github.com/NewYaroslav/time-shield-cpp" -#property strict - - -// Constants used in time calculations -#include - -// Enumerations used in time representations -#include - -// Structures representing time components -#include - -// Structures representing date components -#include - -// Structure representing a time zone -#include - -// Structure representing date and time combinations -#include - -// Value-type wrapper for date-time with offset -#include - -// Functions for validation of time-related values -#include - -// Utility functions for time manipulation -#include - -// Functions for converting between different time representations -#include - -// Functions for converting between time zones -#include - -// Functions for formatting time in various standard formats -#include - -// Functions for parsing time in various standard formats -#include - -// Functions for initializing the library -#include - -#endif // __TIME_SHIELD_MQH__