|
9 | 9 | #include "util.h" // for LogPrintf |
10 | 10 |
|
11 | 11 | #include <boost/date_time/posix_time/posix_time.hpp> |
| 12 | +#include <ctime> |
12 | 13 | #include <limits> |
13 | 14 | #include <map> |
14 | 15 |
|
@@ -174,24 +175,42 @@ bool GetBDAPFees(const opcodetype& opCodeAction, const opcodetype& opCodeObject, |
174 | 175 |
|
175 | 176 | int64_t AddMonthsToCurrentEpoch(const short nMonths) |
176 | 177 | { |
| 178 | + struct std::tm epoch_date; |
| 179 | + epoch_date.tm_hour = 0; epoch_date.tm_min = 0; epoch_date.tm_sec = 0; |
| 180 | + epoch_date.tm_year = 70; epoch_date.tm_mon = 0; epoch_date.tm_mday = 1; |
| 181 | + |
177 | 182 | boost::gregorian::date dt = boost::gregorian::day_clock::universal_day(); |
178 | 183 | short nYear = dt.year() + ((dt.month() + nMonths)/12); |
179 | 184 | short nMonth = (dt.month() + nMonths) % 12; |
180 | 185 | short nDay = dt.day(); |
181 | | - boost::posix_time::time_duration dur = boost::posix_time::ptime(boost::gregorian::date(nYear, nMonth, nDay)) - boost::posix_time::ptime(boost::gregorian::date(1970, 1, 1)); |
182 | 186 | //LogPrintf("%s -- nYear %d, nMonth %d, nDay %d\n", __func__, nYear, nMonth, nDay); |
183 | | - return dur.total_seconds() + SECONDS_PER_DAY; |
| 187 | + struct std::tm month_date; |
| 188 | + month_date.tm_hour = 0; month_date.tm_min = 0; month_date.tm_sec = 0; |
| 189 | + month_date.tm_year = nYear - 1900; month_date.tm_mon = nMonth -1; month_date.tm_mday = nDay; |
| 190 | + |
| 191 | + int64_t seconds = (int64_t)std::difftime(std::mktime(&month_date), std::mktime(&epoch_date)); |
| 192 | + |
| 193 | + return seconds + SECONDS_PER_DAY; |
184 | 194 | } |
185 | 195 |
|
186 | 196 | int64_t AddMonthsToBlockTime(const uint32_t& nBlockTime, const short nMonths) |
187 | 197 | { |
| 198 | + struct std::tm epoch_date; |
| 199 | + epoch_date.tm_hour = 0; epoch_date.tm_min = 0; epoch_date.tm_sec = 0; |
| 200 | + epoch_date.tm_year = 70; epoch_date.tm_mon = 0; epoch_date.tm_mday = 1; |
| 201 | + |
188 | 202 | boost::gregorian::date dt = boost::posix_time::from_time_t(nBlockTime).date(); |
189 | 203 | short nYear = dt.year() + ((dt.month() + nMonths)/12); |
190 | 204 | short nMonth = (dt.month() + nMonths) % 12; |
191 | 205 | short nDay = dt.day(); |
192 | | - boost::posix_time::time_duration dur = boost::posix_time::ptime(boost::gregorian::date(nYear, nMonth, nDay)) - boost::posix_time::ptime(boost::gregorian::date(1970, 1, 1)); |
193 | 206 | //LogPrintf("%s -- nYear %d, nMonth %d, nDay %d\n", __func__, nYear, nMonth, nDay); |
194 | | - return dur.total_seconds() + SECONDS_PER_DAY; |
| 207 | + struct std::tm month_date; |
| 208 | + month_date.tm_hour = 0; month_date.tm_min = 0; month_date.tm_sec = 0; |
| 209 | + month_date.tm_year = nYear - 1900; month_date.tm_mon = nMonth -1; month_date.tm_mday = nDay; |
| 210 | + |
| 211 | + int64_t seconds = (int64_t)std::difftime(std::mktime(&month_date), std::mktime(&epoch_date)); |
| 212 | + |
| 213 | + return seconds + SECONDS_PER_DAY; |
195 | 214 | } |
196 | 215 |
|
197 | 216 | uint16_t MonthsFromBlockToExpire(const uint32_t& nBlockTime, const uint64_t& nExpireTime) |
|
0 commit comments