Initial commit

This commit is contained in:
2020-05-04 21:22:57 +02:00
commit f61d7fd7af
22 changed files with 134 additions and 0 deletions
+6
View File
@@ -0,0 +1,6 @@
*.o.*
*.d.*
*.a.*
.*.swp
.AppleDouble
lib
+3
View File
@@ -0,0 +1,3 @@
[submodule "Makefiles"]
path = Makefiles
url = https://gogs.dierkse.nl/JDierkse/Makefiles
+1
View File
@@ -0,0 +1 @@
../Makefile
+1
View File
@@ -0,0 +1 @@
../../date/src/tz.cpp
+52
View File
@@ -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
View File
@@ -0,0 +1 @@
../Makefile
+1
View File
@@ -0,0 +1 @@
../../date
Symlink
+1
View File
@@ -0,0 +1 @@
Makefiles/Makefile
+11
View File
@@ -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
View File
@@ -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
Submodule
+1
Submodule Makefiles added at cd9ef1a1b0
+34
View File
@@ -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
View File
@@ -0,0 +1 @@
../../date/include/date/chrono_io.h
+1
View File
@@ -0,0 +1 @@
../../date/include/date/date.h
+1
View File
@@ -0,0 +1 @@
../../date/include/date/ios.h
+1
View File
@@ -0,0 +1 @@
../../date/include/date/islamic.h
+1
View File
@@ -0,0 +1 @@
../../date/include/date/iso_week.h
+1
View File
@@ -0,0 +1 @@
../../date/include/date/julian.h
+1
View File
@@ -0,0 +1 @@
../../date/include/date/ptz.h
+1
View File
@@ -0,0 +1 @@
../../date/include/date/solar_hijri.h
+1
View File
@@ -0,0 +1 @@
../../date/include/date/tz.h
+1
View File
@@ -0,0 +1 @@
../../date/include/date/tz_private.h