ensure that stored time is less than 24 hrs and adjust date accordingly
| 272 | |
| 273 | // ensure that stored time is less than 24 hrs and adjust date accordingly |
| 274 | void DateTime::normalize() { |
| 275 | // total number of whole days in the time |
| 276 | int wholeDays = m_time.days(); |
| 277 | |
| 278 | // if time is longer than a day (either positive or negative) normalize it to remainder less than 24 hrs |
| 279 | if (wholeDays != 0) { |
| 280 | Time adjustTime(wholeDays, 0, 0, 0); |
| 281 | m_date += adjustTime; |
| 282 | m_time -= adjustTime; |
| 283 | } |
| 284 | |
| 285 | // total number of fractional days in the time |
| 286 | double fracDays = m_time.totalDays(); |
| 287 | |
| 288 | // if time is negative add a day to make it positive |
| 289 | if (fracDays < 0) { |
| 290 | Time adjustTime(1, 0, 0, 0); |
| 291 | m_date -= adjustTime; |
| 292 | m_time += adjustTime; |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | int DateTime::utcOffsetHours() const { |
| 297 | return (int)m_utcOffset; |
no test coverage detected