Files
2025-10-25 03:02:53 +03:00

18 KiB
Raw Permalink Blame History

[time.zone.zonedtime]

30 Time library [time]

30.11 Time zones [time.zone]

30.11.7 Class template zoned_time [time.zone.zonedtime]

30.11.7.1 Overview [time.zone.zonedtime.overview]

namespace std::chrono {template<class Duration, class TimeZonePtr = const time_zone*>class zoned_time {public:using duration = common_type_t<Duration, seconds>; private: TimeZonePtr zone_; // exposition only sys_time tp_; // exposition onlyusing traits = zoned_traits; // exposition onlypublic: zoned_time(); zoned_time(const zoned_time&) = default; zoned_time& operator=(const zoned_time&) = default;

zoned_time(const sys_time& st); explicit zoned_time(TimeZonePtr z); explicit zoned_time(string_view name); template zoned_time(const zoned_time<Duration2, TimeZonePtr>& y);

zoned_time(TimeZonePtr z, const sys_time& st); zoned_time(string_view name, const sys_time& st);

zoned_time(TimeZonePtr z, const local_time& tp); zoned_time(string_view name, const local_time& tp); zoned_time(TimeZonePtr z, const local_time& tp, choose c); zoned_time(string_view name, const local_time& tp, choose c); template<class Duration2, class TimeZonePtr2> zoned_time(TimeZonePtr z, const zoned_time<Duration2, TimeZonePtr2>& y); template<class Duration2, class TimeZonePtr2> zoned_time(TimeZonePtr z, const zoned_time<Duration2, TimeZonePtr2>& y, choose); template<class Duration2, class TimeZonePtr2> zoned_time(string_view name, const zoned_time<Duration2, TimeZonePtr2>& y); template<class Duration2, class TimeZonePtr2> zoned_time(string_view name, const zoned_time<Duration2, TimeZonePtr2>& y, choose c);

zoned_time& operator=(const sys_time& st); zoned_time& operator=(const local_time& lt); operator sys_time() const; explicit operator local_time() const;

TimeZonePtr get_time_zone() const; local_time get_local_time() const; sys_time get_sys_time() const; sys_info get_info() const; };

zoned_time() -> zoned_time; template zoned_time(sys_time)-> zoned_time<common_type_t<Duration, seconds>>; templateusing time-zone-representation = // exposition only conditional_t<is_convertible_v<TimeZonePtrOrName, string_view>, const time_zone*, remove_cvref_t>; template zoned_time(TimeZonePtrOrName&&)-> zoned_time<seconds, time-zone-representation>; template<class TimeZonePtrOrName, class Duration> zoned_time(TimeZonePtrOrName&&, sys_time)-> zoned_time<common_type_t<Duration, seconds>, time-zone-representation>; template<class TimeZonePtrOrName, class Duration> zoned_time(TimeZonePtrOrName&&, local_time, choose = choose::earliest)-> zoned_time<common_type_t<Duration, seconds>, time-zone-representation>; template<class Duration, class TimeZonePtrOrName, class TimeZonePtr2> zoned_time(TimeZonePtrOrName&&, zoned_time<Duration, TimeZonePtr2>, choose = choose::earliest)-> zoned_time<common_type_t<Duration, seconds>, time-zone-representation>;}

1

#

zoned_time represents a logical pairing of a time_zone and a time_point with precision Duration.

zoned_time maintains the invariant that it always refers to a valid time zone and represents a point in time that exists and is not ambiguous in that time zone.

2

#

If Duration is not a specialization of chrono::duration, the program is ill-formed.

3

#

Every constructor of zoned_time that accepts a string_view as its first parameter does not participate in class template argument deduction ([over.match.class.deduct]).

30.11.7.2 Constructors [time.zone.zonedtime.ctor]

🔗

zoned_time();

1

#

Constraints: traits::default_zone() is a well-formed expression.

2

#

Effects: Initializes zone_ with traits::default_zone() and default constructs tp_.

🔗

zoned_time(const sys_time<Duration>& st);

3

#

Constraints: traits::default_zone() is a well-formed expression.

4

#

Effects: Initializes zone_ with traits::default_zone() and tp_ with st.

🔗

explicit zoned_time(TimeZonePtr z);

5

#

Preconditions: z refers to a time zone.

6

#

Effects: Initializes zone_ with std::move(z) and default constructs tp_.

🔗

explicit zoned_time(string_view name);

7

#

Constraints: traits::locate_zone(string_view{}) is a well-formed expression andzoned_time is constructible from the return type of traits::locate_zone(string_view{}).

8

#

Effects: Initializes zone_ with traits::locate_zone(name) and default constructs tp_.

🔗

template<class Duration2> zoned_time(const zoned_time<Duration2, TimeZonePtr>& y);

9

#

Constraints: is_convertible_v<sys_time, sys_time> is true.

10

#

Effects: Initializes zone_ with y.zone_ and tp_ with y.tp_.

🔗

zoned_time(TimeZonePtr z, const sys_time<Duration>& st);

11

#

Preconditions: z refers to a time zone.

12

#

Effects: Initializes zone_ with std::move(z) and tp_ with st.

🔗

zoned_time(string_view name, const sys_time<Duration>& st);

13

#

Constraints: zoned_time is constructible from the return type of traits::locate_zone(name) and st.

14

#

Effects: Equivalent to construction with {traits::locate_zone(name), st}.

🔗

zoned_time(TimeZonePtr z, const local_time<Duration>& tp);

15

#

Constraints: is_convertible_v<decltype(declval<TimeZonePtr&>()->to_sys(local_time{})), sys_time> is true.

16

#

Preconditions: z refers to a time zone.

17

#

Effects: Initializes zone_ with std::move(z) and tp_ with zone_->to_sys(tp).

🔗

zoned_time(string_view name, const local_time<Duration>& tp);

18

#

Constraints: zoned_time is constructible from the return type of traits::locate_zone(name) and tp.

19

#

Effects: Equivalent to construction with {traits::locate_zone(name), tp}.

🔗

zoned_time(TimeZonePtr z, const local_time<Duration>& tp, choose c);

20

#

Constraints: is_convertible_v<decltype(declval<TimeZonePtr&>()->to_sys(local_time{}, choose::earliest)), sys_time> is true.

21

#

Preconditions: z refers to a time zone.

22

#

Effects: Initializes zone_ with std::move(z) and tp_ with zone_->to_sys(tp, c).

🔗

zoned_time(string_view name, const local_time<Duration>& tp, choose c);

23

#

Constraints: zoned_time is constructible from the return type of traits::locate_zone(name), local_time, and choose.

24

#

Effects: Equivalent to construction with {traits::locate_zone(name), tp, c}.

🔗

template<class Duration2, class TimeZonePtr2> zoned_time(TimeZonePtr z, const zoned_time<Duration2, TimeZonePtr2>& y);

25

#

Constraints: is_convertible_v<sys_time, sys_time> is true.

26

#

Preconditions: z refers to a valid time zone.

27

#

Effects: Initializes zone_ with std::move(z) and tp_ with y.tp_.

🔗

template<class Duration2, class TimeZonePtr2> zoned_time(TimeZonePtr z, const zoned_time<Duration2, TimeZonePtr2>& y, choose);

28

#

Constraints: is_convertible_v<sys_time, sys_time> is true.

29

#

Preconditions: z refers to a valid time zone.

30

#

Effects: Equivalent to construction with {z, y}.

31

#

[Note 1:

The choose parameter has no effect.

— end note]

🔗

template<class Duration2, class TimeZonePtr2> zoned_time(string_view name, const zoned_time<Duration2, TimeZonePtr2>& y);

32

#

Constraints: zoned_time is constructible from the return type of traits::locate_zone(name) and the type zoned_time<Duration2, TimeZonePtr2>.

33

#

Effects: Equivalent to construction with {traits::locate_zone(name), y}.

🔗

template<class Duration2, class TimeZonePtr2> zoned_time(string_view name, const zoned_time<Duration2, TimeZonePtr2>& y, choose c);

34

#

Constraints: zoned_time is constructible from the return type of traits::locate_zone(name), the type zoned_time<Duration2, TimeZonePtr2>, and the type choose.

35

#

Effects: Equivalent to construction with {traits::locate_zone(name), y, c}.

36

#

[Note 2:

The choose parameter has no effect.

— end note]

30.11.7.3 Member functions [time.zone.zonedtime.members]

🔗

zoned_time& operator=(const sys_time<Duration>& st);

1

#

Effects: After assignment, get_sys_time() == st.

This assignment has no effect on the return value of get_time_zone().

2

#

Returns: *this.

🔗

zoned_time& operator=(const local_time<Duration>& lt);

3

#

Effects: After assignment, get_local_time() == lt.

This assignment has no effect on the return value of get_time_zone().

4

#

Returns: *this.

🔗

operator sys_time<duration>() const;

5

#

Returns: get_sys_time().

🔗

explicit operator local_time<duration>() const;

6

#

Returns: get_local_time().

🔗

TimeZonePtr get_time_zone() const;

7

#

Returns: zone_.

🔗

local_time<duration> get_local_time() const;

8

#

Returns: zone_->to_local(tp_).

🔗

sys_time<duration> get_sys_time() const;

9

#

Returns: tp_.

🔗

sys_info get_info() const;

10

#

Returns: zone_->get_info(tp_).

30.11.7.4 Non-member functions [time.zone.zonedtime.nonmembers]

🔗

template<class Duration1, class Duration2, class TimeZonePtr> bool operator==(const zoned_time<Duration1, TimeZonePtr>& x, const zoned_time<Duration2, TimeZonePtr>& y);

1

#

Returns: x.zone_ == y.zone_ && x.tp_ == y.tp_.

🔗

template<class charT, class traits, class Duration, class TimeZonePtr> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const zoned_time<Duration, TimeZonePtr>& t);

2

#

Effects: Equivalent to:return os << format(os.getloc(), STATICALLY-WIDEN("{:L%F %T %Z}"), t);