-
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.
- Loading branch information
Showing
24 changed files
with
1,957 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.ll text | ||
*.yy text |
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,55 @@ | ||
#pragma once | ||
|
||
#include <optional> | ||
#include <string> | ||
|
||
#include <takatori/util/either.h> | ||
|
||
#include "conversion_info.h" | ||
|
||
namespace takatori::datetime { | ||
|
||
/** | ||
* @brief represents the result of conversion, or error message. | ||
* @tparam T the type of conversion result | ||
*/ | ||
template<class T> | ||
using conversion_result = util::either<std::string, T>; | ||
|
||
/** | ||
* @brief parses the given contents as a date. | ||
* @details The date format must be `YYYY-MM-DD`. | ||
* @param contents the source contents | ||
* @return the parsed date information | ||
* @return an error message if the conversion was failed | ||
*/ | ||
[[nodiscard]] conversion_result<date_info> parse_date(std::string const& contents); | ||
|
||
/** | ||
* @brief parses the given contents as a time of day. | ||
* @details The date format must be `hh:mm:ss.SSSSSSSSS`. | ||
* @param contents the source contents | ||
* @return the parsed time of day information | ||
* @return an error message if the conversion was failed | ||
*/ | ||
[[nodiscard]] conversion_result<time_info> parse_time(std::string const& contents); | ||
|
||
/** | ||
* @brief parses the given contents as a datetime, with or without zone offset. | ||
* @details The date format must be `YY-MM-DD hh:mm:ss.SSSSSSSSS+HH:MM`. | ||
* @param contents the source contents | ||
* @return the parsed datetime information with or without zone offset | ||
* @return an error message if the conversion was failed | ||
*/ | ||
[[nodiscard]] conversion_result<datetime_info> parse_datetime(std::string const& contents); | ||
|
||
/** | ||
* @brief parses the given contents as a zone offset. | ||
* @details The date format must be `+HH:MM` or just `Z`. | ||
* @param contents the source contents | ||
* @return the parsed zone offset | ||
* @return an error message if the conversion was failed | ||
*/ | ||
[[nodiscard]] conversion_result<zone_offset_info> parse_zone_offset(std::string const& contents); | ||
|
||
} // namespace takatori::datetime |
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,76 @@ | ||
#pragma once | ||
|
||
#include <chrono> | ||
#include <optional> | ||
|
||
#include <cstdint> | ||
|
||
namespace takatori::datetime { | ||
|
||
/** | ||
* @brief represents date information. | ||
*/ | ||
struct date_info { | ||
|
||
/// @brief the year field of date. | ||
std::uint32_t year {}; | ||
|
||
/// @brief the month field of date. | ||
std::uint32_t month {}; | ||
|
||
/// @brief the day of month field of date. | ||
std::uint32_t day {}; | ||
}; | ||
|
||
/** | ||
* @brief represents time of day information. | ||
*/ | ||
struct time_info { | ||
|
||
/// @brief the sub-second field type. | ||
using subsecond_type = std::chrono::duration<std::uint32_t, std::nano>; | ||
|
||
/// @brief the hour field of time of day. | ||
std::uint32_t hour {}; | ||
|
||
/// @brief the minute field of time of day. | ||
std::uint32_t minute {}; | ||
|
||
/// @brief the second field of time of day. | ||
std::uint32_t second {}; | ||
|
||
/// @brief the sub-second field of time of day. | ||
subsecond_type subsecond {}; | ||
}; | ||
|
||
/** | ||
* @brief represents timezone offset information. | ||
*/ | ||
struct zone_offset_info { | ||
|
||
/// @brief the sign of timezone offset. | ||
bool plus { true }; | ||
|
||
/// @brief the hour field of timezone offset. | ||
std::uint32_t hour {}; | ||
|
||
/// @brief the minute field of timezone offset. | ||
std::uint32_t minute {}; | ||
}; | ||
|
||
/** | ||
* @brief represents datetime information. | ||
*/ | ||
struct datetime_info { | ||
|
||
/// @brief the date information. | ||
date_info date; | ||
|
||
/// @brief the time of day information. | ||
time_info time; | ||
|
||
/// @brief the optional timezone offset information. | ||
std::optional<zone_offset_info> offset; | ||
}; | ||
|
||
} // namespace takatori::datetime |
Oops, something went wrong.