diff src/core/date.cpp @ 51:75c804f713b2

window: add about window, *: use tr() when applicable (useful for i18n)
author Paper <mrpapersonic@gmail.com>
date Mon, 25 Sep 2023 20:29:26 -0400
parents d8eb763e6661
children 3d2decf093bb
line wrap: on
line diff
--- a/src/core/date.cpp	Mon Sep 25 13:50:56 2023 -0400
+++ b/src/core/date.cpp	Mon Sep 25 20:29:26 2023 -0400
@@ -1,6 +1,7 @@
 #include "core/date.h"
 #include "core/json.h"
 #include <QDate>
+#include <QDebug>
 #include <cstdint>
 #include <tuple>
 
@@ -30,16 +31,22 @@
 Date::Date() {
 }
 
-Date::Date(int32_t y) {
+Date::Date(unsigned int y) {
 	SetYear(y);
 }
 
-Date::Date(int32_t y, int8_t m, int8_t d) {
+Date::Date(unsigned int y, unsigned int m, unsigned int d) {
 	SetYear(y);
 	SetMonth(m);
 	SetDay(d);
 }
 
+Date::Date(const QDate& date) {
+	SetYear(date.year());
+	SetMonth(date.month());
+	SetDay(date.day());
+}
+
 void Date::VoidYear() {
 	year.reset();
 }
@@ -52,34 +59,34 @@
 	day.reset();
 }
 
-void Date::SetYear(int32_t y) {
-	year.reset(new int32_t(MAX(0, y)));
+void Date::SetYear(unsigned int y) {
+	year.reset(new unsigned int(MAX(0U, y)));
 }
 
-void Date::SetMonth(int8_t m) {
-	month.reset(new int8_t(CLAMP(m, 1, 12)));
+void Date::SetMonth(unsigned int m) {
+	month.reset(new unsigned int(CLAMP(m, 1U, 12U)));
 }
 
-void Date::SetDay(int8_t d) {
-	day.reset(new int8_t(CLAMP(d, 1, 31)));
+void Date::SetDay(unsigned int d) {
+	day.reset(new unsigned int(CLAMP(d, 1U, 31U)));
 }
 
-int32_t Date::GetYear() const {
-	int32_t* ptr = year.get();
+unsigned int Date::GetYear() const {
+	unsigned int* ptr = year.get();
 	if (ptr != nullptr)
 		return *year;
 	return -1;
 }
 
-int8_t Date::GetMonth() const {
-	int8_t* ptr = month.get();
+unsigned int Date::GetMonth() const {
+	unsigned int* ptr = month.get();
 	if (ptr != nullptr)
 		return *month;
 	return -1;
 }
 
-int8_t Date::GetDay() const {
-	int8_t* ptr = day.get();
+unsigned int Date::GetDay() const {
+	unsigned int* ptr = day.get();
 	if (ptr != nullptr)
 		return *day;
 	return -1;
@@ -90,8 +97,8 @@
 }
 
 bool Date::operator<(const Date& other) const {
-	int y = GetYear(), m = GetMonth(), d = GetDay();
-	int o_y = other.GetYear(), o_m = other.GetMonth(), o_d = other.GetDay();
+	unsigned int y = GetYear(), m = GetMonth(), d = GetDay();
+	unsigned int o_y = other.GetYear(), o_m = other.GetMonth(), o_d = other.GetDay();
 	return std::tie(y, m, d) < std::tie(o_y, o_m, o_d);
 }