xtd 0.2.0
Loading...
Searching...
No Matches
date_time.h
Go to the documentation of this file.
1
4#pragma once
5#include "chrono.h"
6#include "date_time_kind.h"
7#include "day_of_week.h"
8#include "icomparable.h"
9#include "iequatable.h"
10#include "month_of_year.h"
11#include "object.h"
12#include "ticks.h"
13#include "time_span.h"
14#include "ustring.h"
15#include <ctime>
16
18namespace xtd {
20 class time_zone_info;
22
24
79 class core_export_ date_time : public xtd::icomparable<date_time>, public xtd::iequatable<date_time>, public xtd::object {
80 public:
82
91 static const date_time max_value;
101 static const date_time min_value;
103
105
109 date_time() = default;
150 date_time(uint32 year, uint32 month, uint32 day);
161 date_time(uint32 year, uint32 month, uint32 day, uint32 hour, uint32 minute, uint32 second);
181 date_time(uint32 year, uint32 month, uint32 day, uint32 hour, uint32 minute, uint32 second, date_time_kind kind);
192 date_time(uint32 year, uint32 month, uint32 day, uint32 hour, uint32 minute, uint32 second, uint32 millisecond);
204 date_time(uint32 year, uint32 month, uint32 day, uint32 hour, uint32 minute, uint32 second, uint32 millisecond, date_time_kind kind);
206
208 date_time(const date_time&) = default;
209 date_time(date_time&&) = default;
210 date_time& operator =(const date_time&) = default;
212
213
215
224 date_time date() const noexcept;
225
254 uint32 day() const noexcept;
255
263 xtd::day_of_week day_of_week() const noexcept;
264
271 uint32 day_of_year() const noexcept;
272
306 uint32 hour() const noexcept;
307
315 date_time_kind kind() const noexcept;
316
356 uint32 millisecond() const noexcept;
357
385 uint32 minute() const noexcept;
386
414 uint32 month() const noexcept;
415
443 uint32 second() const noexcept;
444
450 int64 ticks() const noexcept;
451
457 xtd::ticks ticks_duration() const noexcept;
458
466 xtd::time_span time_of_day() const noexcept;
467
496 uint32 year() const noexcept;
498
500
512 date_time add(const xtd::time_span& value) const;
513
524 date_time add_days(double value) const;
525
536 date_time add_hours(double value) const;
537
548 date_time add_milliseconds(double value) const;
549
559 date_time add_minutes(double value) const;
560
570 date_time add_months(int32 months) const;
571
581 date_time add_seconds(double value) const;
582
588 date_time add_ticks(int64 value) const;
589
601 date_time add_years(int32 value) const;
602
603 int32 compare_to(const date_time& value) const noexcept override;
604
605 bool equals(const date_time&) const noexcept override;
606
609 std::vector<ustring> get_date_time_formats() const noexcept;
610
615 bool is_daylight_saving_time() const noexcept;
616
628 xtd::time_span subtract(const date_time& value) const;
648 date_time subtract(const xtd::time_span& value) const;
649
653 int64 to_binary() const;
654
660 int64 to_file_time() const;
661
667 int64 to_file_time_utc() const;
668
683 date_time to_local_time() const;
684
688 const xtd::ustring to_long_date_string() const;
689
693 const xtd::ustring to_long_time_string() const;
694
698 const xtd::ustring to_short_date_string() const;
699
703 const xtd::ustring to_short_time_string() const;
704
708 xtd::ustring to_string() const noexcept override;
765 xtd::ustring to_string(const ustring& format) const;
766
771 std::time_t to_time_t() const;
772
777 std::tm to_tm() const;
778
791 date_time to_universal_time() const;
793
795
804 static date_time now() noexcept;
805
813 static date_time today() noexcept;
814
823 static date_time utc_now() noexcept;
824
838 static int32 days_in_month(uint32 year, month_of_year month);
839
853 static int32 days_in_month(uint32 year, uint32 month);
854
861 static date_time from_binary(int64 date_data);
862
885 static date_time from_file_time(int64 file_time);
893 static date_time from_file_time_utc(int64 file_time);
894
899 static date_time from_duration(const time_span& value);
905 static date_time from_duration(const time_span& value, date_time_kind kind);
906
913 static date_time from_time_t(std::time_t value);
921 static date_time from_time_t(std::time_t value, date_time_kind kind);
922
929 static date_time from_tm(const std::tm& value);
937 static date_time from_tm(const std::tm& value, date_time_kind kind);
938
943 static bool is_leap_year(uint32 year);
944
952 static date_time parse(const xtd::ustring& s);
953
961 static date_time specify_kind(const date_time& value, date_time_kind kind);
962
1030 static xtd::ustring sprintf(const ustring& format, const date_time& value);
1031
1037 static bool try_parse(const ustring& s, date_time& result) noexcept;
1039
1041 operator xtd::time_span() const;
1042 date_time operator +=(const date_time& value) = delete;
1043 date_time operator +=(const time_span& value);
1044 time_span operator -=(const date_time& value);
1045 time_span operator -=(const time_span& value);
1046 date_time operator +();
1047 date_time operator -();
1048 date_time operator +(const date_time& value) const = delete;
1049 date_time operator +(const time_span& value) const;
1050 time_span operator -(const date_time& value) const;
1051 date_time operator -(const time_span& value) const;
1052 date_time& operator ++();
1053 date_time operator ++(int32);
1054 date_time& operator --();
1055 date_time operator --(int32);
1057
1058 private:
1059 friend class time_zone_info;
1060 xtd::ticks utc_offset() const;
1061 std::tuple<uint32, uint32, uint32, uint32, uint32, uint32, uint32, int32> get_date_time() const;
1062 void set_date_time(uint32 year, uint32 month, uint32 day, uint32 hour, uint32 minute, uint32 second, uint32 millisecond, date_time_kind kind);
1063
1064 xtd::ticks value_ {0};
1065 date_time_kind kind_ {date_time_kind::unspecified};
1066 };
1068
1079 template<>
1080 inline std::string to_string(const date_time& value, const std::string& fmt, const std::locale& loc) {
1081 return value.to_string(fmt);
1082 }
1083}
Contains dyas, weeks, months and years durationtypes.
Represents an instant in time, typically expressed as a date and time of day.
Definition date_time.h:79
date_time(uint32 year, uint32 month, uint32 day, uint32 hour, uint32 minute, uint32 second, uint32 millisecond, date_time_kind kind)
Initializes a new instance of the xtd::date_time structure to the specified year, month,...
static const date_time min_value
Represents the smallest possible value of xtd::date_time. This field is read-only.
Definition date_time.h:101
date_time(int64 ticks)
Initializes a new instance of the xtd::date_time structure to a specified number of ticks.
date_time date() const noexcept
Gets the date component of this instance.
date_time(xtd::ticks ticks, xtd::date_time_kind kind)
Initializes a new instance of the xtd::date_time structure to a specified number of ticks and to Coor...
date_time(uint32 year, uint32 month, uint32 day)
Initializes a new instance of the xtd::date_time structure to the specified year, month,...
xtd::ustring to_string() const noexcept override
Converts the value of the current xtd::date_time object to its equivalent string representation using...
date_time(int64 ticks, xtd::date_time_kind kind)
Initializes a new instance of the xtd::date_time structure to a specified number of ticks and to Coor...
date_time(uint32 year, uint32 month, uint32 day, uint32 hour, uint32 minute, uint32 second, date_time_kind kind)
Initializes a new instance of the xtd::date_time structure to the specified year, month,...
date_time(xtd::ticks ticks)
Initializes a new instance of the xtd::date_time structure to a specified number of ticks.
date_time()=default
Initializes a new instance of the xtd::date_time structure.
date_time(uint32 year, uint32 month, uint32 day, uint32 hour, uint32 minute, uint32 second, uint32 millisecond)
Initializes a new instance of the xtd::date_time structure to the specified year, month,...
date_time(uint32 year, uint32 month, uint32 day, uint32 hour, uint32 minute, uint32 second)
Initializes a new instance of the xttd::date_time structure to the specified year,...
static const date_time max_value
Represents the largest possible value of xtd::date_time. This field is read-only.
Definition date_time.h:91
Defines a generalized comparison method that a value type or class implements to create a type-specif...
Definition icomparable.h:17
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition iequatable.h:18
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.h:32
Represents any time zone in the world.
Definition time_zone_info.h:38
Represents text as a sequence of UTF-8 code units.
Definition ustring.h:47
Contains xtd::date_time_kind enum class.
Contains xtd::day_of_week enum class.
#define core_export_
Define shared library export.
Definition core_export.h:13
int_least64_t int64
Represents a 64-bit signed integer.
Definition types.h:142
int_least32_t int32
Represents a 32-bit signed integer.
Definition types.h:131
uint_least32_t uint32
Represents a 32-bit unsigned integer.
Definition types.h:241
std::chrono::duration< int64, tick > ticks
Represents a tick duration.
Definition ticks.h:21
date_time_kind
Specifies whether a DateTime object represents a local time, a Coordinated Universal Time (UTC),...
Definition date_time_kind.h:19
month_of_year
Specifies the month of the year.
Definition month_of_year.h:21
std::string to_string(const date_time &value, const std::string &fmt, const std::locale &loc)
Convert a specified value into a string with specified format and locale.
Definition date_time.h:1080
day_of_week
Specifies the day of the week.
Definition day_of_week.h:23
Contains xtd::icomparable interface.
Contains xtd::iequatable interface.
Contains xtd::month_of_year enum class.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10
Contains xtd::object class.
Represents a time interval.
Definition time_span.h:26
Contains xtd::ticks typedef.
Contains xtd::time_span typedef.
Contains xtd::ustring class.