Commit 2368798e authored by jan.koester's avatar jan.koester
Browse files

use chrono

parent b6ae8746
Loading
Loading
Loading
Loading
+16 −20
Changes for plugins/content/content.cpp: 16 added lines, 20 removed lines.
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *******************************************************************************/

#include <chrono>
#include <iostream>
#include <algorithm>
#include <compare>
@@ -294,31 +295,26 @@ namespace blogi {

                int author=atoi(ares[0][0]);

                time_t t = time(NULL);
                struct tm time_info = { 0 }; // Renamed 'time' to 'time_info' to avoid conflict with the function name
                char ttmp[26];
#ifdef Windows
                if (localtime_s(&time_info, &t) == 0) {
                    if (asctime_s(ttmp, sizeof(ttmp), &time_info) != 0) {
                        excep[libhttppp::HTTPException::Error] << "Cannot get Time!";
                        throw excep;
                    }
                }
                else {
                    excep[libhttppp::HTTPException::Error] << "Cannot get Time!";
                    throw excep;
                std::chrono::system_clock::time_point t = std::chrono::system_clock::now();


                try {
                    std::time_t time_t_value = std::chrono::system_clock::to_time_t(t);
                    std::string time_str;

                    try {
                        time_str = std::format("{:%a %b %d %H:%M:%S %Y}", t);
                    } catch (...) {
                        throw excep[libhttppp::HTTPException::Error] << "Cannot get Time (std::format/put_time failed)!";
                    }
#else
                if (localtime_r(&t, &time_info) != 0) {
                    if (asctime_r(&time_info, ttmp) != 0) {
                        excep[libhttppp::HTTPException::Error] << "Cannot get Time!";
                        throw excep;

                    if (time_str.empty()) {
                        throw excep[libhttppp::HTTPException::Error] << "Cannot get Time (Time structure failure)!";
                    }
                } else {
                    excep[libhttppp::HTTPException::Error] << "Cannot get Time!";
                } catch (const libhttppp::HTTPException& excep) {
                    throw excep;
                }
#endif
                sql << "INSERT INTO content (title,descrition,text,author,created) VALUES ('" <<
                dbpp::SQL::escaped(sbuf,title.data()) << "','" <<
                dbpp::SQL::escaped(sbuf,description.data()) <<"','" <<