mirror of
https://github.com/szymon-jozef/static-site-generator.git
synced 2026-10-27 19:20:41 +01:00
fixed date error
This commit is contained in:
@@ -51,11 +51,10 @@ std::optional<Metadata> get_metadata(const std::string &FILE_PATH) {
|
|||||||
if (toml_time.is_date()) {
|
if (toml_time.is_date()) {
|
||||||
toml::date d = toml_time.as_date()->get();
|
toml::date d = toml_time.as_date()->get();
|
||||||
|
|
||||||
// To convert to a Unix timestamp (time_t):
|
t.tm_year = d.year - 1900;
|
||||||
t.tm_year = d.year - 1900; // tm_year is years since 1900
|
t.tm_mon = d.month - 1;
|
||||||
t.tm_mon = d.month - 1; // tm_mon is 0-11
|
|
||||||
t.tm_mday = d.day;
|
t.tm_mday = d.day;
|
||||||
t.tm_isdst = -1;
|
t.tm_isdst = 0;
|
||||||
|
|
||||||
timestamp = mktime(&t);
|
timestamp = mktime(&t);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ TEST_CASE("get_metadata function data correctness test") {
|
|||||||
datetime.tm_year = 2026 - 1900;
|
datetime.tm_year = 2026 - 1900;
|
||||||
datetime.tm_mon = 1 - 1;
|
datetime.tm_mon = 1 - 1;
|
||||||
datetime.tm_mday = 1;
|
datetime.tm_mday = 1;
|
||||||
|
datetime.tm_isdst = 0;
|
||||||
|
|
||||||
time_t expected_date = mktime(&datetime);
|
time_t expected_date = mktime(&datetime);
|
||||||
std::string expected_title = "Example of a blog post";
|
std::string expected_title = "Example of a blog post";
|
||||||
std::vector<std::string> expected_tags = {"blog", "test", "lalilulelo"};
|
std::vector<std::string> expected_tags = {"blog", "test", "lalilulelo"};
|
||||||
|
|||||||
Reference in New Issue
Block a user