JDierkse 5 жил өмнө
commit
f61d7fd7af

+ 6 - 0
.gitignore

@@ -0,0 +1,6 @@
+*.o.*
+*.d.*
+*.a.*
+.*.swp
+.AppleDouble
+lib

+ 3 - 0
.gitmodules

@@ -0,0 +1,3 @@
+[submodule "Makefiles"]
+	path = Makefiles
+	url = https://gogs.dierkse.nl/JDierkse/Makefiles

+ 1 - 0
Date/Makefile

@@ -0,0 +1 @@
+../Makefile

+ 1 - 0
Date/tz.cpp

@@ -0,0 +1 @@
+../../date/src/tz.cpp

+ 52 - 0
DateTime/DateTime.cpp

@@ -0,0 +1,52 @@
+#include "DateTime.h"
+
+
+namespace DateTime {
+
+std::chrono::system_clock::time_point DateTime_UTC_to_time_point(const DateTime& dateTime)
+{
+	auto yearMonthDay = date::year(dateTime.year)/dateTime.month/dateTime.day;
+	if (!yearMonthDay.ok())
+		throw std::runtime_error("Invalid date");
+
+	return date::sys_days(yearMonthDay) + std::chrono::hours(dateTime.hour) + std::chrono::minutes(dateTime.min) + std::chrono::seconds(dateTime.sec);
+}
+
+std::chrono::system_clock::time_point DateTime_to_time_point(const DateTime& dateTime, const date::time_zone* timeZone)
+{
+	auto yearMonthDay = date::year(dateTime.year)/dateTime.month/dateTime.day;
+	if (!yearMonthDay.ok())
+		throw std::runtime_error("Invalid date");
+
+	return date::make_zoned(timeZone, date::local_days{yearMonthDay} + std::chrono::hours(dateTime.hour) + std::chrono::minutes(dateTime.min) + std::chrono::seconds(dateTime.sec)).get_sys_time();
+}
+
+int GetTimestamp()
+{
+	return std::time(nullptr);
+}
+
+int GetUTCOffset()
+{
+	std::time_t current_time;
+	std::time(&current_time);
+	struct std::tm *timeinfo = std::localtime(&current_time);
+	return timeinfo->tm_gmtoff;
+}
+
+std::string GetTimeString()
+{
+	return GetTimeString(std::chrono::system_clock::now());
+}
+
+std::string GetTimeString(const std::chrono::system_clock::time_point& timePoint)
+{
+	auto time_t = std::chrono::system_clock::to_time_t(timePoint);
+	auto tm = *std::localtime(&time_t);
+
+	char buffer[80];
+	strftime(buffer, 80, "%Y-%m-%d %H:%M:%S", &tm);
+	return std::string(buffer);
+}
+
+} // namespace DateTime

+ 1 - 0
DateTime/Makefile

@@ -0,0 +1 @@
+../Makefile

+ 1 - 0
Libraries/date

@@ -0,0 +1 @@
+../../date

+ 1 - 0
Makefile

@@ -0,0 +1 @@
+Makefiles/Makefile

+ 11 - 0
Makefile.conf

@@ -0,0 +1,11 @@
+#
+# Makefile.conf
+#
+
+CFLAGS += -I$(ROOTPATH)/Libraries/date/include
+
+LFLAGS += -lDateTime
+LFLAGS += -L$(ROOTPATH)/lib/$(ARCH)
+CFLAGS += -I$(ROOTPATH) -I$(ROOTPATH)/include
+
+DEBUGDIR := .debug

+ 12 - 0
Makefile.target

@@ -0,0 +1,12 @@
+#
+# Makefile.target
+#
+
+DateTime.a.$(ARCH) : $(OBJECTS)
+	$(call build_target_library_arch,$@,$^)
+DateTime.a:
+	$(call build_target,$@)
+
+.DEFAULT_GOAL := DateTime.a
+
+TARGETS += DateTime.a

+ 1 - 0
Makefiles

@@ -0,0 +1 @@
+Subproject commit cd9ef1a1b0f7b88f36b0c51b4209d1859aca83aa

+ 34 - 0
include/DateTime.h

@@ -0,0 +1,34 @@
+#ifndef DATETIME_H
+#define DATETIME_H
+
+#include "date.h"
+#include "tz.h"
+#include <chrono>
+#include <string>
+
+
+namespace DateTime {
+
+struct DateTime
+{
+	DateTime(int year, unsigned month, unsigned day) : year(year), month(month), day(day) {}
+	int year;
+	unsigned month;
+	unsigned day;
+	int hour = 0;
+	int min  = 0;
+	int sec  = 0;
+};
+
+std::chrono::system_clock::time_point DateTime_UTC_to_time_point(const DateTime& dt);
+std::chrono::system_clock::time_point DateTime_to_time_point(const DateTime& dt, const date::time_zone* tzone);
+
+int GetTimestamp();
+int GetUTCOffset();
+
+std::string GetTimeString();
+std::string GetTimeString(const std::chrono::system_clock::time_point& timePoint);
+
+} // namespace DateTime
+
+#endif // DATETIME_H

+ 1 - 0
include/chrono_io.h

@@ -0,0 +1 @@
+../../date/include/date/chrono_io.h

+ 1 - 0
include/date.h

@@ -0,0 +1 @@
+../../date/include/date/date.h

+ 1 - 0
include/ios.h

@@ -0,0 +1 @@
+../../date/include/date/ios.h

+ 1 - 0
include/islamic.h

@@ -0,0 +1 @@
+../../date/include/date/islamic.h

+ 1 - 0
include/iso_week.h

@@ -0,0 +1 @@
+../../date/include/date/iso_week.h

+ 1 - 0
include/julian.h

@@ -0,0 +1 @@
+../../date/include/date/julian.h

+ 1 - 0
include/ptz.h

@@ -0,0 +1 @@
+../../date/include/date/ptz.h

+ 1 - 0
include/solar_hijri.h

@@ -0,0 +1 @@
+../../date/include/date/solar_hijri.h

+ 1 - 0
include/tz.h

@@ -0,0 +1 @@
+../../date/include/date/tz.h

+ 1 - 0
include/tz_private.h

@@ -0,0 +1 @@
+../../date/include/date/tz_private.h