-
Notifications
You must be signed in to change notification settings - Fork 0
/
mycalendar.cpp
35 lines (32 loc) · 1.05 KB
/
mycalendar.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "mycalendar.h"
MyCalendar::MyCalendar()
{
}
time_t MyCalendar::dateToTimeT(int month, int day, int year) {
std::tm tmp = tm();
tmp.tm_mday = day;
tmp.tm_mon = month - 1;
tmp.tm_year = year;
tmp.tm_hour = 0;
tmp.tm_min = 0;
tmp.tm_sec = 0;
return mktime(&tmp);
}
QString MyCalendar::leftToNY()
{
time_t now = time(0);
tm *ltm = localtime(&now);
time_t newYear = dateToTimeT(01, 01, ltm->tm_year + 1);
double sec = difftime(newYear, now);
uint leftDays = static_cast<uint>(sec / secondsInDay);
uint diffSecs = sec - (leftDays * secondsInDay);
uint leftHours = diffSecs / secondsInHour;
uint remainingSeconds = diffSecs - (leftHours * secondsInHour);
uint leftMinutes = remainingSeconds / secondsInMinute;
uint leftSeconds = remainingSeconds - (leftMinutes * secondsInMinute);
isTimeToBell = leftMinutes == 0 && leftSeconds == 0;
return timeStr.arg(leftDays)
.arg(leftHours)
.arg(leftMinutes, 2, 10, QChar('0'))
.arg(leftSeconds, 2, 10, QChar('0'));
}