Debian Codegraph @

src/types/chrono/datetime.rs

raw symbols SCIP
1 use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::decoderust-analyzer cargo sqlx-core 0.8.3 decode/::Decoderust-analyzer cargo sqlx-core 0.8.3 decode/Decode#;
2 use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::encoderust-analyzer cargo sqlx-core 0.8.3 encode/::{Encoderust-analyzer cargo sqlx-core 0.8.3 encode/Encode#, IsNullrust-analyzer cargo sqlx-core 0.8.3 encode/IsNull#};
3 use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::errorrust-analyzer cargo sqlx-postgres 0.8.3 error/::BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#;
4 use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::typesrust-analyzer cargo sqlx-postgres 0.8.3 types/::Typerust-analyzer cargo sqlx-core 0.8.3 types/Type#;
5 use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::{PgArgumentBufferrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBuffer#, PgHasArrayTyperust-analyzer cargo sqlx-postgres 0.8.3 types/array/PgHasArrayType#, PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo#, PgValueFormatrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueFormat#, PgValueRefrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueRef#, Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#};
6 use chronorust-analyzer cargo chrono 0.4.45 crate/::{
7 DateTimerust-analyzer cargo chrono 0.4.45 datetime/DateTime#, Durationrust-analyzer cargo chrono 0.4.45 Duration#, FixedOffsetrust-analyzer cargo chrono 0.4.45 offset/fixed/FixedOffset#, Localrust-analyzer cargo chrono 0.4.45 offset/local/Local#, NaiveDaterust-analyzer cargo chrono 0.4.45 naive/date/NaiveDate#, NaiveDateTimerust-analyzer cargo chrono 0.4.45 naive/datetime/NaiveDateTime#, Offsetrust-analyzer cargo chrono 0.4.45 offset/Offset#, TimeZonerust-analyzer cargo chrono 0.4.45 offset/TimeZone#, Utcrust-analyzer cargo chrono 0.4.45 offset/utc/Utc#,
8 };
9 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/;
10
11 impl Typerust-analyzer cargo sqlx-core 0.8.3 types/Type#<Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#> for NaiveDateTimerust-analyzer cargo chrono 0.4.45 naive/datetime/NaiveDateTime# {
12 fn type_inforust-analyzer cargo sqlx-postgres 0.8.3 types/chrono/datetime/impl#[NaiveDateTime][`Type<Postgres>`]type_info().() -> PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo# {
13 PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo#::TIMESTAMPrust-analyzer cargo sqlx-postgres 0.8.3 type_info/impl#[PgTypeInfo]TIMESTAMP.
14 }
15 }
16
17 impl<Tz: TimeZonerust-analyzer cargo chrono 0.4.45 offset/TimeZone#> Typerust-analyzer cargo sqlx-core 0.8.3 types/Type#<Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#> for DateTimerust-analyzer cargo chrono 0.4.45 datetime/DateTime#<Tz> {
18 fn type_inforust-analyzer cargo sqlx-postgres 0.8.3 types/chrono/datetime/impl#[`DateTime<Tz>`][`Type<Postgres>`]type_info().() -> PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo# {
19 PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo#::TIMESTAMPTZrust-analyzer cargo sqlx-postgres 0.8.3 type_info/impl#[PgTypeInfo]TIMESTAMPTZ.
20 }
21 }
22
23 impl PgHasArrayTyperust-analyzer cargo sqlx-postgres 0.8.3 types/array/PgHasArrayType# for NaiveDateTimerust-analyzer cargo chrono 0.4.45 naive/datetime/NaiveDateTime# {
24 fn array_type_inforust-analyzer cargo sqlx-postgres 0.8.3 types/chrono/datetime/impl#[NaiveDateTime][PgHasArrayType]array_type_info().() -> PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo# {
25 PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo#::TIMESTAMP_ARRAYrust-analyzer cargo sqlx-postgres 0.8.3 type_info/impl#[PgTypeInfo]TIMESTAMP_ARRAY.
26 }
27 }
28
29 impl<Tz: TimeZonerust-analyzer cargo chrono 0.4.45 offset/TimeZone#> PgHasArrayTyperust-analyzer cargo sqlx-postgres 0.8.3 types/array/PgHasArrayType# for DateTimerust-analyzer cargo chrono 0.4.45 datetime/DateTime#<Tz> {
30 fn array_type_inforust-analyzer cargo sqlx-postgres 0.8.3 types/chrono/datetime/impl#[`DateTime<Tz>`][PgHasArrayType]array_type_info().() -> PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo# {
31 PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo#::TIMESTAMPTZ_ARRAYrust-analyzer cargo sqlx-postgres 0.8.3 type_info/impl#[PgTypeInfo]TIMESTAMPTZ_ARRAY.
32 }
33 }
34
35 impl Encoderust-analyzer cargo sqlx-core 0.8.3 encode/Encode#<'_, Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#> for NaiveDateTimerust-analyzer cargo chrono 0.4.45 naive/datetime/NaiveDateTime# {
36 fn encode_by_refrust-analyzer cargo sqlx-postgres 0.8.3 types/chrono/datetime/impl#[NaiveDateTime][`Encode<'_, Postgres>`]encode_by_ref().(&self, buf: &mut PgArgumentBufferrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBuffer#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<IsNullrust-analyzer cargo sqlx-core 0.8.3 encode/IsNull#, BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#> {
37 // TIMESTAMP is encoded as the microseconds since the epoch
38 let micros = (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self rust-analyzer cargo chrono 0.4.45 naive/datetime/impl#[NaiveDateTime][`Sub<Self>`]sub().-rust-analyzer cargo chrono 0.4.45 naive/datetime/impl#[NaiveDateTime][`Sub<Self>`]sub(). rust-analyzer cargo chrono 0.4.45 naive/datetime/impl#[NaiveDateTime][`Sub<Self>`]sub().postgres_epoch_datetimerust-analyzer cargo sqlx-postgres 0.8.3 types/chrono/datetime/postgres_epoch_datetime().())
39 .num_microsecondsrust-analyzer cargo chrono 0.4.45 time_delta/impl#[TimeDelta]num_microseconds().()
40 .ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("NaiveDateTime out of range for Postgres: {self:?}"))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
41
42 Encoderust-analyzer cargo sqlx-core 0.8.3 encode/Encode#::<Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#>::encoderust-analyzer cargo sqlx-core 0.8.3 encode/Encode#encode().(micros, buf)
43 }
44
45 fn size_hintrust-analyzer cargo sqlx-postgres 0.8.3 types/chrono/datetime/impl#[NaiveDateTime][`Encode<'_, Postgres>`]size_hint().(&self) -> usize {
46 memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<i64>()
47 }
48 }
49
50 impl<'r> Decoderust-analyzer cargo sqlx-core 0.8.3 decode/Decode#<'r, Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#> for NaiveDateTimerust-analyzer cargo chrono 0.4.45 naive/datetime/NaiveDateTime# {
51 fn decoderust-analyzer cargo sqlx-postgres 0.8.3 types/chrono/datetime/impl#[NaiveDateTime][`Decode<'r, Postgres>`]decode().(value: PgValueRefrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueRef#<'r>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo sqlx-postgres 0.8.3 types/chrono/datetime/impl#[NaiveDateTime][`Decode<'r, Postgres>`], BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#> {
52 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(match value.formatrust-analyzer cargo sqlx-postgres 0.8.3 value/impl#[`PgValueRef<'r>`]format().() {
53 PgValueFormatrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueFormat#::Binaryrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueFormat#Binary# => {
54 // TIMESTAMP is encoded as the microseconds since the epoch
55 let us = Decoderust-analyzer cargo sqlx-core 0.8.3 decode/Decode#::<Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#>::decoderust-analyzer cargo sqlx-postgres 0.8.3 types/int/impl#[i64][`Decode<'_, Postgres>`]decode().(value)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
56 postgres_epoch_datetimerust-analyzer cargo sqlx-postgres 0.8.3 types/chrono/datetime/postgres_epoch_datetime().() rust-analyzer cargo chrono 0.4.45 naive/datetime/impl#[NaiveDateTime][`Add<TimeDelta>`]add().+rust-analyzer cargo chrono 0.4.45 naive/datetime/impl#[NaiveDateTime][`Add<TimeDelta>`]add(). rust-analyzer cargo chrono 0.4.45 naive/datetime/impl#[NaiveDateTime][`Add<TimeDelta>`]add().Durationrust-analyzer cargo chrono 0.4.45 Duration#::microsecondsrust-analyzer cargo chrono 0.4.45 time_delta/impl#[TimeDelta]microseconds().(us)
57 }
58
59 PgValueFormatrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueFormat#::Textrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueFormat#Text# => {
60 let s = value.as_strrust-analyzer cargo sqlx-postgres 0.8.3 value/impl#[`PgValueRef<'r>`]as_str().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
61 NaiveDateTimerust-analyzer cargo chrono 0.4.45 naive/datetime/NaiveDateTime#::parse_from_strrust-analyzer cargo chrono 0.4.45 naive/datetime/impl#[NaiveDateTime]parse_from_str().(
62 s,
63 if s.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().('+') {
64 // Contains a time-zone specifier
65 // This is given for timestamptz for some reason
66 // Postgres already guarantees this to always be UTC
67 "%Y-%m-%d %H:%M:%S%.f%#z"
68 } else {
69 "%Y-%m-%d %H:%M:%S%.f"
70 },
71 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().
72 }
73 })
74 }
75 }
76
77 impl<Tz: TimeZonerust-analyzer cargo chrono 0.4.45 offset/TimeZone#> Encoderust-analyzer cargo sqlx-core 0.8.3 encode/Encode#<'_, Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#> for DateTimerust-analyzer cargo chrono 0.4.45 datetime/DateTime#<Tz> {
78 fn encode_by_refrust-analyzer cargo sqlx-postgres 0.8.3 types/chrono/datetime/impl#[`DateTime<Tz>`][`Encode<'_, Postgres>`]encode_by_ref().(&self, buf: &mut PgArgumentBufferrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBuffer#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<IsNullrust-analyzer cargo sqlx-core 0.8.3 encode/IsNull#, BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#> {
79 Encoderust-analyzer cargo sqlx-core 0.8.3 encode/Encode#::<Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#>::encoderust-analyzer cargo sqlx-core 0.8.3 encode/Encode#encode().(self.naive_utcrust-analyzer cargo chrono 0.4.45 datetime/impl#[`DateTime<Tz>`]naive_utc().(), buf)
80 }
81
82 fn size_hintrust-analyzer cargo sqlx-postgres 0.8.3 types/chrono/datetime/impl#[`DateTime<Tz>`][`Encode<'_, Postgres>`]size_hint().(&self) -> usize {
83 memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<i64>()
84 }
85 }
86
87 impl<'r> Decoderust-analyzer cargo sqlx-core 0.8.3 decode/Decode#<'r, Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#> for DateTimerust-analyzer cargo chrono 0.4.45 datetime/DateTime#<Localrust-analyzer cargo chrono 0.4.45 offset/local/Local#> {
88 fn decoderust-analyzer cargo sqlx-postgres 0.8.3 types/chrono/datetime/impl#[`DateTime<Local>`][`Decode<'r, Postgres>`]decode().(value: PgValueRefrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueRef#<'r>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo sqlx-postgres 0.8.3 types/chrono/datetime/impl#[`DateTime<Local>`][`Decode<'r, Postgres>`], BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#> {
89 let fixed = <DateTimerust-analyzer cargo chrono 0.4.45 datetime/DateTime#<FixedOffsetrust-analyzer cargo chrono 0.4.45 offset/fixed/FixedOffset#> as Decoderust-analyzer cargo sqlx-core 0.8.3 decode/Decode#<Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#>>::decoderust-analyzer cargo sqlx-postgres 0.8.3 types/chrono/datetime/impl#[`DateTime<FixedOffset>`][`Decode<'r, Postgres>`]decode().(value)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
90 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Localrust-analyzer cargo chrono 0.4.45 offset/local/Local#.from_utc_datetimerust-analyzer cargo chrono 0.4.45 offset/TimeZone#from_utc_datetime().(&fixed.naive_utcrust-analyzer cargo chrono 0.4.45 datetime/impl#[`DateTime<Tz>`]naive_utc().()))
91 }
92 }
93
94 impl<'r> Decoderust-analyzer cargo sqlx-core 0.8.3 decode/Decode#<'r, Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#> for DateTimerust-analyzer cargo chrono 0.4.45 datetime/DateTime#<Utcrust-analyzer cargo chrono 0.4.45 offset/utc/Utc#> {
95 fn decoderust-analyzer cargo sqlx-postgres 0.8.3 types/chrono/datetime/impl#[`DateTime<Utc>`][`Decode<'r, Postgres>`]decode().(value: PgValueRefrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueRef#<'r>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo sqlx-postgres 0.8.3 types/chrono/datetime/impl#[`DateTime<Utc>`][`Decode<'r, Postgres>`], BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#> {
96 let fixed = <DateTimerust-analyzer cargo chrono 0.4.45 datetime/DateTime#<FixedOffsetrust-analyzer cargo chrono 0.4.45 offset/fixed/FixedOffset#> as Decoderust-analyzer cargo sqlx-core 0.8.3 decode/Decode#<Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#>>::decoderust-analyzer cargo sqlx-postgres 0.8.3 types/chrono/datetime/impl#[`DateTime<FixedOffset>`][`Decode<'r, Postgres>`]decode().(value)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
97 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Utcrust-analyzer cargo chrono 0.4.45 offset/utc/Utc#.from_utc_datetimerust-analyzer cargo chrono 0.4.45 offset/TimeZone#from_utc_datetime().(&fixed.naive_utcrust-analyzer cargo chrono 0.4.45 datetime/impl#[`DateTime<Tz>`]naive_utc().()))
98 }
99 }
100
101 impl<'r> Decoderust-analyzer cargo sqlx-core 0.8.3 decode/Decode#<'r, Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#> for DateTimerust-analyzer cargo chrono 0.4.45 datetime/DateTime#<FixedOffsetrust-analyzer cargo chrono 0.4.45 offset/fixed/FixedOffset#> {
102 fn decoderust-analyzer cargo sqlx-postgres 0.8.3 types/chrono/datetime/impl#[`DateTime<FixedOffset>`][`Decode<'r, Postgres>`]decode().(value: PgValueRefrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueRef#<'r>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo sqlx-postgres 0.8.3 types/chrono/datetime/impl#[`DateTime<FixedOffset>`][`Decode<'r, Postgres>`], BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#> {
103 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(match value.formatrust-analyzer cargo sqlx-postgres 0.8.3 value/impl#[`PgValueRef<'r>`]format().() {
104 PgValueFormatrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueFormat#::Binaryrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueFormat#Binary# => {
105 let naive = <NaiveDateTimerust-analyzer cargo chrono 0.4.45 naive/datetime/NaiveDateTime# as Decoderust-analyzer cargo sqlx-core 0.8.3 decode/Decode#<Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#>>::decoderust-analyzer cargo sqlx-postgres 0.8.3 types/chrono/datetime/impl#[NaiveDateTime][`Decode<'r, Postgres>`]decode().(value)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
106 Utcrust-analyzer cargo chrono 0.4.45 offset/utc/Utc#.fixrust-analyzer cargo chrono 0.4.45 offset/utc/impl#[Utc][Offset]fix().().from_utc_datetimerust-analyzer cargo chrono 0.4.45 offset/TimeZone#from_utc_datetime().(&naive)
107 }
108
109 PgValueFormatrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueFormat#::Textrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueFormat#Text# => {
110 let s = value.as_strrust-analyzer cargo sqlx-postgres 0.8.3 value/impl#[`PgValueRef<'r>`]as_str().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
111 DateTimerust-analyzer cargo chrono 0.4.45 datetime/DateTime#::parse_from_strrust-analyzer cargo chrono 0.4.45 datetime/impl#[`DateTime<FixedOffset>`]parse_from_str().(
112 s,
113 if s.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().('+') || s.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().('-') {
114 // Contains a time-zone specifier
115 // This is given for timestamptz for some reason
116 // Postgres already guarantees this to always be UTC
117 "%Y-%m-%d %H:%M:%S%.f%#z"
118 } else {
119 "%Y-%m-%d %H:%M:%S%.f"
120 },
121 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().
122 }
123 })
124 }
125 }
126
127 #[inline]
128 fn postgres_epoch_datetimerust-analyzer cargo sqlx-postgres 0.8.3 types/chrono/datetime/postgres_epoch_datetime().() -> NaiveDateTimerust-analyzer cargo chrono 0.4.45 naive/datetime/NaiveDateTime# {
129 NaiveDaterust-analyzer cargo chrono 0.4.45 naive/date/NaiveDate#::from_ymd_optrust-analyzer cargo chrono 0.4.45 naive/date/impl#[NaiveDate]from_ymd_opt().(2000, 1, 1)
130 .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("expected 2000-01-01 to be a valid NaiveDate")
131 .and_hms_optrust-analyzer cargo chrono 0.4.45 naive/date/impl#[NaiveDate]and_hms_opt().(0, 0, 0)
132 .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("expected 2000-01-01T00:00:00 to be a valid NaiveDateTime")
133 }