|
| 1 | +//+------------------------------------------------------------------+ |
| 2 | +//| constants.mqh | |
| 3 | +//| Time Shield - MQL5 Constants | |
| 4 | +//| Copyright 2025, NewYaroslav | |
| 5 | +//| https://github.com/NewYaroslav/time-shield-cpp | |
| 6 | +//+------------------------------------------------------------------+ |
| 7 | +#ifndef __TIME_SHIELD_CONSTANTS_MQH__ |
| 8 | +#define __TIME_SHIELD_CONSTANTS_MQH__ |
| 9 | + |
| 10 | +/// \file constants.mqh |
| 11 | +/// \ingroup mql5 |
| 12 | +/// \brief Header file with time-related constants. |
| 13 | +/// |
| 14 | +/// This file contains various constants used for time calculations and conversions. |
| 15 | + |
| 16 | +#property copyright "Copyright 2025, NewYaroslav" |
| 17 | +#property link "https://github.com/NewYaroslav/time-shield-cpp" |
| 18 | +#property strict |
| 19 | + |
| 20 | +namespace time_shield { |
| 21 | + |
| 22 | + /// \defgroup time_constants Time Constants |
| 23 | + /// \brief A collection of constants for time calculations and conversions. |
| 24 | + /// |
| 25 | + /// This group includes constants for time units (nanoseconds, microseconds, milliseconds, seconds, minutes, hours, days), |
| 26 | + /// and other values related to the representation of time, such as UNIX and OLE epochs. |
| 27 | + /// |
| 28 | + /// ### Key Features: |
| 29 | + /// - Provides constants for common time conversions. |
| 30 | + /// - Includes limits and special values like MAX_YEAR and ERROR_YEAR. |
| 31 | + /// |
| 32 | + /// ### Example Usage: |
| 33 | + /// \code |
| 34 | + /// long milliseconds_in_a_day = time_shield::MS_PER_DAY; |
| 35 | + /// \endcode |
| 36 | + /// |
| 37 | + /// \{ |
| 38 | + |
| 39 | + // Nanoseconds and microseconds |
| 40 | + const long NS_PER_US = 1000; ///< Nanoseconds per microsecond |
| 41 | + const long NS_PER_MS = 1000000; ///< Nanoseconds per millisecond |
| 42 | + const long NS_PER_SEC = 1000000000; ///< Nanoseconds per second |
| 43 | + |
| 44 | + // Microseconds and milliseconds |
| 45 | + const long US_PER_SEC = 1000000; ///< Microseconds per second |
| 46 | + const long MS_PER_SEC = 1000; ///< Milliseconds per second |
| 47 | + const long MS_PER_1_SEC = 1000; ///< Milliseconds per 1 second |
| 48 | + const long MS_PER_5_SEC = 5000; ///< Milliseconds per 5 second |
| 49 | + const long MS_PER_10_SEC = 10000; ///< Milliseconds per 10 seconds |
| 50 | + const long MS_PER_15_SEC = 15000; ///< Milliseconds per 15 second |
| 51 | + const long MS_PER_30_SEC = 30000; ///< Milliseconds per 30 second |
| 52 | + const long MS_PER_MIN = 60000; ///< Milliseconds per minute |
| 53 | + const long MS_PER_1_MIN = 60000; ///< Milliseconds per 1 minute |
| 54 | + const long MS_PER_5_MIN = 300000; ///< Milliseconds per 5 minute |
| 55 | + const long MS_PER_10_MIN = 600000; ///< Milliseconds per 10 minute |
| 56 | + const long MS_PER_15_MIN = 900000; ///< Milliseconds per 15 minute |
| 57 | + const long MS_PER_30_MIN = 1800000; ///< Milliseconds per 30 minute |
| 58 | + const long MS_PER_HALF_HOUR = 1800000; ///< Milliseconds per half hour |
| 59 | + const long MS_PER_HOUR = 3600000; ///< Milliseconds per hour |
| 60 | + const long MS_PER_1_HOUR = 3600000; ///< Milliseconds per 1 hour |
| 61 | + const long MS_PER_2_HOUR = 7200000; ///< Milliseconds per 2 hour |
| 62 | + const long MS_PER_4_HOUR = 14400000; ///< Milliseconds per 4 hour |
| 63 | + const long MS_PER_5_HOUR = 18000000; ///< Milliseconds per 5 hour |
| 64 | + const long MS_PER_8_HOUR = 28800000; ///< Milliseconds per 8 hour |
| 65 | + const long MS_PER_12_HOUR = 43200000; ///< Milliseconds per 12 hour |
| 66 | + const long MS_PER_DAY = 86400000; ///< Milliseconds per day |
| 67 | + |
| 68 | + // Seconds |
| 69 | + const long SEC_PER_MIN = 60; ///< Seconds per minute |
| 70 | + const long SEC_PER_1_MIN = 60; ///< Seconds per 1 minute |
| 71 | + const long SEC_PER_3_MIN = 180; ///< Seconds per 3 minute |
| 72 | + const long SEC_PER_5_MIN = 300; ///< Seconds per 5 minute |
| 73 | + const long SEC_PER_10_MIN = 600; ///< Seconds per 10 minute |
| 74 | + const long SEC_PER_15_MIN = 900; ///< Seconds per 15 minute |
| 75 | + const long SEC_PER_HALF_HOUR = 1800; ///< Seconds per half hour |
| 76 | + const long SEC_PER_HOUR = 3600; ///< Seconds per hour |
| 77 | + const long SEC_PER_1_HOUR = 3600; ///< Seconds per 1 hour |
| 78 | + const long SEC_PER_2_HOUR = 7200; ///< Seconds per 2 hour |
| 79 | + const long SEC_PER_4_HOUR = 14400; ///< Seconds per 4 hour |
| 80 | + const long SEC_PER_5_HOUR = 18000; ///< Seconds per 5 hour |
| 81 | + const long SEC_PER_8_HOUR = 28800; ///< Seconds per 8 hour |
| 82 | + const long SEC_PER_12_HOUR = 43200; ///< Seconds per 12 hour |
| 83 | + const long SEC_PER_DAY = 86400; ///< Seconds per day |
| 84 | + const long SEC_PER_YEAR = 31536000; ///< Seconds per year (365 days) |
| 85 | + const long AVG_SEC_PER_YEAR = 31557600; ///< Average seconds per year (365.25 days) |
| 86 | + const long SEC_PER_LEAP_YEAR = 31622400; ///< Seconds per leap year (366 days) |
| 87 | + const long SEC_PER_4_YEARS = 126230400; ///< Seconds per 4 years |
| 88 | + const long SEC_PER_FIRST_100_YEARS = 3155760000; ///< Seconds per first 100 years |
| 89 | + const long SEC_PER_100_YEARS = 3155673600; ///< Seconds per 100 years |
| 90 | + const long SEC_PER_400_YEARS = 12622780800; ///< Seconds per 400 years |
| 91 | + const long MAX_SEC_PER_DAY = 86399; ///< Maximum seconds per day |
| 92 | + |
| 93 | + // Minutes |
| 94 | + const long MIN_PER_HOUR = 60; ///< Minutes per hour |
| 95 | + const long MIN_PER_DAY = 1440; ///< Minutes per day |
| 96 | + const long MIN_PER_1_DAY = 1440; ///< Minutes per 1 day |
| 97 | + const long MIN_PER_2_DAY = 2*1440; ///< Minutes per 2 day |
| 98 | + const long MIN_PER_5_DAY = 5*1440; ///< Minutes per 5 day |
| 99 | + const long MIN_PER_7_DAY = 7*1440; ///< Minutes per 7 day |
| 100 | + const long MIN_PER_WEEK = 10080; ///< Minutes per week |
| 101 | + const long MIN_PER_10_DAY = 10*1440; ///< Minutes per 10 day |
| 102 | + const long MIN_PER_15_DAY = 15*1440; ///< Minutes per 15 day |
| 103 | + const long MIN_PER_30_DAY = 15*1440; ///< Minutes per 30 day |
| 104 | + const long MIN_PER_MONTH = 40320; ///< Minutes per month (28 days) |
| 105 | + const long MAX_MOON_MIN = 42523; ///< Maximum lunar minutes |
| 106 | + |
| 107 | + // Hours and days |
| 108 | + const long HOURS_PER_DAY = 24; ///< Hours per day |
| 109 | + const long DAYS_PER_WEEK = 7; ///< Days per week |
| 110 | + const long DAYS_PER_LEAP_YEAR = 366; ///< Days per leap year |
| 111 | + const long DAYS_PER_YEAR = 365; ///< Days per year |
| 112 | + const long DAYS_PER_4_YEARS = 1461; ///< Days per 4 years |
| 113 | + |
| 114 | + // Months and years |
| 115 | + const long MONTHS_PER_YEAR = 12; ///< Months per year |
| 116 | + const long MAX_DAYS_PER_MONTH = 31; ///< Maximum days per month |
| 117 | + const long LEAP_YEAR_PER_100_YEAR = 24; ///< Leap years per 100 years |
| 118 | + const long LEAP_YEAR_PER_400_YEAR = 97; ///< Leap years per 400 years |
| 119 | + |
| 120 | + // Epoch and maximum values |
| 121 | + const long UNIX_EPOCH = 1970; ///< Start year of UNIX time |
| 122 | + const long OLE_EPOCH = 25569; ///< OLE automation date since UNIX epoch |
| 123 | + const long MAX_YEAR = 292277022000; ///< Maximum representable year |
| 124 | + const long MIN_YEAR = -2967369602200; ///< Minimum representable year |
| 125 | + const long ERROR_YEAR = 9223372036854770000; ///< Error year value |
| 126 | + const long MAX_TIMESTAMP = 9223371890843040000; ///< Maximum timestamp value |
| 127 | + const long ERROR_TIMESTAMP = 9223372036854770000; ///< Error timestamp value |
| 128 | + const double MAX_OADATE = 1.7976931348623158e+308; ///< Maximum OLE automation date |
| 129 | + const double AVG_DAYS_PER_YEAR = 365.25; ///< Average days per year |
| 130 | + |
| 131 | + /// \} |
| 132 | + |
| 133 | +}; // namespace time_shield |
| 134 | + |
| 135 | +#endif // __TIME_SHIELD_CONSTANTS_MQH__ |
0 commit comments