Initial commit
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
*.o.*
|
||||
*.d.*
|
||||
*.a.*
|
||||
.*.swp
|
||||
.AppleDouble
|
||||
lib
|
||||
@@ -0,0 +1,3 @@
|
||||
[submodule "Makefiles"]
|
||||
path = Makefiles
|
||||
url = https://gogs.dierkse.nl/JDierkse/Makefiles
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../Makefile
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../../date/src/tz.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(¤t_time);
|
||||
struct std::tm *timeinfo = std::localtime(¤t_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
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../Makefile
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../../date
|
||||
@@ -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
|
||||
@@ -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
@@ -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
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../../date/include/date/chrono_io.h
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../../date/include/date/date.h
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../../date/include/date/ios.h
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../../date/include/date/islamic.h
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../../date/include/date/iso_week.h
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../../date/include/date/julian.h
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../../date/include/date/ptz.h
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../../date/include/date/solar_hijri.h
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../../date/include/date/tz.h
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../../date/include/date/tz_private.h
|
||||
Reference in New Issue
Block a user