Commit 89482ee8 authored by LEFEBVREJP email's avatar LEFEBVREJP email
Browse files

Merge branch 'utc_to_time' into 'master'

Utc to time

See merge request !20
parents 0cdcca43 04155db1
Pipeline #11146 passed with stage
in 3 minutes and 25 seconds
.windows_before_script: &windows_before_script
before_script:
- set PATH=%PATH%;c:\vendors\mingw-w64\x86_64-4.8.5-posix-seh-rt_v4-rev0\mingw64\bin;c:\vendors\git\2.11\cmd;c:\vendors\cmake\3.6.3\bin;c:\vendors\mingw-w64\qt\5.7.0\bin
- set PATH=%PATH%;c:\vendors\mingw-w64\x86_64-4.8.5-posix-seh-rt_v4-rev0\mingw64\bin;c:\vendors\mingw-w64\qt\5.9.1\bin
mac_gcc_testing:
tags:
......@@ -79,8 +79,6 @@ windows_mingw_testing:
script:
- where git
- git --version
- where qmake
- qmake -version
- where cmake
- cmake --version
- git clone https://github.com/lefebvre/TriBITS.git TriBITS
......@@ -88,7 +86,7 @@ windows_mingw_testing:
- git clone https://github.com/lefebvre/googletest googletest
- mkdir build
- cd build
- cmake -DDEBUG_OUTPUT=1 -DTPL_LAPACK_LIBRARIES=c:/vendors/mingw-w64/lapack/3.6.1/lib/liblapack.a\\\;c:/vendors/mingw-w64/lapack/3.6.1/lib/libblas.a\\\;-lgfortran -DBUILDNAME=Windows-MinGW-GCC-4.8.5-Debug-%CI_BUILD_REF_NAME% -DCMAKE_BUILD_TYPE=DEBUG -Dradix_ENABLE_COVERAGE_TESTING=ON -Dradix_ENABLE_TESTS=ON -Dradix_ENABLE_radixams=ON -Dradix_ENABLE_radixio=ON -Dradix_ENABLE_radixmath=ON -Dradix_ENABLE_radixpara=ON -Dradix_ENABLE_radixgeometry=ON -Dradix_ENABLE_radixglls=ON -Dradix_ENABLE_radixcommand=ON -Dradix_ENABLE_googletest=ON -Dradix_ENABLE_radixdl=ON -Dradix_ENABLE_radixcore=ON -G "MinGW Makefiles" ..
- cmake -DDEBUG_OUTPUT=1 -DTPL_LAPACK_LIBRARIES=c:/vendors/mingw-w64/lapack/3.5.0/lib/liblapack.a\\\;c:/vendors/mingw-w64/lapack/3.5.0/lib/libblas.a\\\;-lgfortran -DBUILDNAME=Windows-MinGW-GCC-4.8.5-Debug-%CI_BUILD_REF_NAME% -DCMAKE_BUILD_TYPE=DEBUG -Dradix_ENABLE_COVERAGE_TESTING=ON -Dradix_ENABLE_TESTS=ON -Dradix_ENABLE_radixams=ON -Dradix_ENABLE_radixio=ON -Dradix_ENABLE_radixmath=ON -Dradix_ENABLE_radixpara=ON -Dradix_ENABLE_radixgeometry=ON -Dradix_ENABLE_radixglls=ON -Dradix_ENABLE_radixcommand=ON -Dradix_ENABLE_googletest=ON -Dradix_ENABLE_radixdl=ON -Dradix_ENABLE_radixcore=ON -G "MinGW Makefiles" ..
- ctest -D ExperimentalStart -D ExperimentalBuild -D ExperimentalTest -D ExperimentalSubmit
windows_intel_shared_testing:
......
......@@ -121,4 +121,24 @@ std::string remove_extra_whitespace(const std::string &inputStr)
str.erase(new_end, str.end());
return trim_string(str);
}
struct tm utc_to_time(const std::string &time, int &zone, int &daylight)
{
int year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0;
int count = sscanf(time.c_str(), "%d-%d-%dT%d:%d:%d-%d:%d", &year, &month,
&day, &hour, &minute, &second, &zone, &daylight);
radix_line("utc_to_time elements: " << count);
struct tm res;
res.tm_year = year;
res.tm_mon = month;
res.tm_mday = day;
res.tm_hour = hour;
res.tm_min = minute;
res.tm_sec = second;
radix_line("Parsed time:" << year << "-" << month << "-" << day << "T" << hour
<< ":" << minute << ":" << second << "-" << zone
<< ":" << daylight);
return res;
}
} // namespace radix
......@@ -8,15 +8,25 @@
*/
#include <cstdio>
#include <ctime>
#include <fstream>
#include <string>
#include <type_traits>
#include <vector>
#include "radixdl/visibility.hh"
namespace radix
{
/**
* @brief utc_to_time UTC time to
* @param time UTC formatted date and time
* @param zone time zone
* @param daylight daylight savings
* @return struct tm
*/
struct tm RADIX_PUBLIC utc_to_time(const std::string &time, int &zone,
int &daylight);
/**
* Convert a string to lowercase
* @param the string to be converted
......
#include <iomanip>
#include <limits>
#include <sstream>
#include <type_traits>
#include "radixbug/bug.hh"
namespace radix
{
......
#include "gtest/gtest.h"
#include <ctime>
#include <fstream>
#include <iostream>
#include <string>
......@@ -11,6 +12,35 @@ using namespace radix;
typedef std::vector<std::string> Vec_Str;
TEST(StringFunctions, utc_to_time)
{
{
std::string utcDateTime = "1951-11-19T17:00:00-08:00";
int zone = 0, daylight = 0;
struct tm time = utc_to_time(utcDateTime, zone, daylight);
EXPECT_EQ(time.tm_year, 1951);
EXPECT_EQ(time.tm_mon, 11);
EXPECT_EQ(time.tm_mday, 19);
EXPECT_EQ(time.tm_hour, 17);
EXPECT_EQ(time.tm_min, 0);
EXPECT_EQ(time.tm_sec, 0);
EXPECT_EQ(zone, 8);
EXPECT_EQ(daylight, 0);
}
{
std::string utcDateTime = "1951-11-19T17:00:00Z";
int zone = 0, daylight = 0;
struct tm time = utc_to_time(utcDateTime, zone, daylight);
EXPECT_EQ(time.tm_year, 1951);
EXPECT_EQ(time.tm_mon, 11);
EXPECT_EQ(time.tm_mday, 19);
EXPECT_EQ(time.tm_hour, 17);
EXPECT_EQ(time.tm_min, 0);
EXPECT_EQ(time.tm_sec, 0);
EXPECT_EQ(zone, 0);
EXPECT_EQ(daylight, 0);
}
}
TEST(FindAndReplace, Basic)
{
EXPECT_EQ("x001", find_and_replace("x$f", "$f", "001"));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment