-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from tri-star/hotfix-from-to-bug
Fix --from, --to option parse bug.
- Loading branch information
Showing
6 changed files
with
57 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include "../../util/date_util.h" | ||
|
||
#include <string> | ||
|
||
#include <gtest/gtest.h> | ||
|
||
|
||
namespace tigrep { | ||
|
||
namespace util { | ||
|
||
TEST(DateUtilTest, basic) { | ||
std::string time = "2014-08-08 10:00:00"; | ||
std::string format = "%Y-%m-%d %H:%M:%S"; | ||
time_t expected = 1407459600; //date -d "2014-08-08 10:00:00" +%s | ||
time_t actual = DateUtil::stringToTime(time, format); | ||
|
||
ASSERT_EQ(expected, actual); | ||
} | ||
|
||
} //namespace | ||
} //namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#ifndef TIGREP_UTIL_DATE_UTIL_H_ | ||
#define TIGREP_UTIL_DATE_UTIL_H_ | ||
|
||
#include <string> | ||
#include <ctime> | ||
|
||
namespace tigrep { | ||
|
||
namespace util { | ||
|
||
class DateUtil { | ||
|
||
public: | ||
|
||
static time_t stringToTime(const std::string& time, const std::string& format) { | ||
struct tm tm; | ||
char* result = strptime(time.c_str(), format.c_str(), &tm); | ||
if(result == time.c_str() || result == 0) { | ||
return 0; | ||
} | ||
return mktime(&tm); | ||
} | ||
|
||
}; | ||
|
||
} //namespace | ||
} //namespace | ||
|
||
|
||
#endif |