[gnote] Fix date formatting when second is single digit
- From: Aurimas Černius <aurimasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote] Fix date formatting when second is single digit
- Date: Sat, 18 Dec 2021 19:41:35 +0000 (UTC)
commit 8ac82d0d6bbfd77f8675c1c85de9076274a69c81
Author: Aurimas Černius <aurisc4 gmail com>
Date: Sat Dec 18 21:40:20 2021 +0200
Fix date formatting when second is single digit
Fixes https://gitlab.gnome.org/GNOME/gnote/-/issues/115
src/sharp/datetime.cpp | 4 ++--
src/test/unit/datetimeutests.cpp | 7 ++++++-
2 files changed, 8 insertions(+), 3 deletions(-)
---
diff --git a/src/sharp/datetime.cpp b/src/sharp/datetime.cpp
index 43d22dfc..94707dc7 100644
--- a/src/sharp/datetime.cpp
+++ b/src/sharp/datetime.cpp
@@ -1,7 +1,7 @@
/*
* gnote
*
- * Copyright (C) 2012,2017,2020 Aurimas Cernius
+ * Copyright (C) 2012,2017,2020-2021 Aurimas Cernius
* Copyright (C) 2009 Hubert Figuiere
*
* Permission is hereby granted, free of charge, to any person obtaining a
@@ -58,7 +58,7 @@ Glib::ustring date_time_to_iso8601(const Glib::DateTime & dt)
Glib::DateTime date = dt.to_utc();
char buffer[36] = {0};
- std::sprintf(buffer, "%d-%02d-%02dT%02d:%02d:%02.6lfZ", date.get_year(), date.get_month(),
date.get_day_of_month(), date.get_hour(), date.get_minute(), date.get_seconds());
+ std::sprintf(buffer, "%d-%02d-%02dT%02d:%02d:%09.6lfZ", date.get_year(), date.get_month(),
date.get_day_of_month(), date.get_hour(), date.get_minute(), date.get_seconds());
retval = buffer;
return retval;
}
diff --git a/src/test/unit/datetimeutests.cpp b/src/test/unit/datetimeutests.cpp
index eb7530ae..0c1436b3 100644
--- a/src/test/unit/datetimeutests.cpp
+++ b/src/test/unit/datetimeutests.cpp
@@ -1,7 +1,7 @@
/*
* gnote
*
- * Copyright (C) 2017,2020 Aurimas Cernius
+ * Copyright (C) 2017,2020,2021 Aurimas Cernius
* Copyright (C) 2009 Hubert Figuiere
*
* This program is free software: you can redistribute it and/or modify
@@ -48,6 +48,11 @@ SUITE(DateTime)
CHECK(bool(d));
date_string = sharp::date_time_to_iso8601(d);
CHECK_EQUAL("2009-03-24T07:34:35.540000Z", date_string);
+
+ d = Glib::DateTime::create_local(2021, 1, 2, 3, 4, 5);
+ CHECK(bool(d));
+ date_string = sharp::date_time_to_iso8601(d);
+ CHECK_EQUAL("2021-01-02T03:04:05.000000Z", date_string);
}
TEST(date_time_from_iso8601)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]