Skip to content

Commit a517b84

Browse files
committed
Add xtd::date_time constructors with std::chrono::time_point
1 parent e318b16 commit a517b84

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/xtd.core/include/xtd/date_time.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,23 @@ namespace xtd {
208208
/// @exception xtd::argument_out_of_range_exception year is less than 1 or greater than 9999.<br>-or-<br>month is less than 1 or greater than 12.<br>-or-<br>day is less than 1 or greater than the number of days in month.<br>-or-<br>hour is less than 0 or greater than 23.<br>-or-<br>minute is less than 0 or greater than 59<br>-or-<br>second is less than 0 or greater than 59<br>-or-<br>millisecond is less than 0 or greater than 999.
209209
/// @remarks This constructor interpretsyear, month, and day as a year, month, and day in the Gregorian calendar.
210210
date_time(uint32 year, uint32 month, uint32 day, uint32 hour, uint32 minute, uint32 second, uint32 millisecond, date_time_kind kind);
211+
212+
/// @brief Initializes a new instance of the xtd::date_time structure to a specified time point.
213+
/// @param time_point A [std::chrono::time_point](https://en.cppreference.com/w/cpp/chrono/time_point) value.
214+
/// @remarks This constructor is used to convert [std::chrono::system_clock::time_point](https://en.cppreference.com/w/cpp/chrono/system_clock) to xtd::date_time.
215+
template<class clock_t, class duration_t = clock_t::duration>
216+
date_time(const std::chrono::time_point<clock_t, duration_t>& time_point) {
217+
*this = from_time_t(clock_t::to_time_t(time_point), date_time_kind::local);
218+
}
219+
220+
/// @brief Initializes a new instance of the xtd::date_time structure to a specified time point, and Coordinated Universal Time (UTC) or local time.
221+
/// @param time_point A [std::chrono::time_point](https://en.cppreference.com/w/cpp/chrono/time_point) value.
222+
/// @param kind One of the enumeration values that indicates whether year, month, day, hour, minute and second specify a local time, Coordinated Universal Time (UTC), or neither.
223+
/// @remarks This constructor is used to convert [std::chrono::system_clock::time_point](https://en.cppreference.com/w/cpp/chrono/system_clock) to xtd::date_time.
224+
template<class clock_t, class duration_t = clock_t::duration>
225+
date_time(const std::chrono::time_point<clock_t, duration_t>& time_point, date_time_kind kind) {
226+
*this = from_time_t(clock_t::to_time_t(time_point), kind);
227+
}
211228
/// @}
212229

213230
/// @cond

0 commit comments

Comments
 (0)