| 107 | } |
| 108 | |
| 109 | fn write_date(&self, context: &mut Context, out: &mut DynQuery, value: &Date) { |
| 110 | let (l, r) = match context.fragment { |
| 111 | Fragment::None | Fragment::ParameterBinding | Fragment::Timestamp => ("", ""), |
| 112 | Fragment::Json | Fragment::JsonKey => ("\"", "\""), |
| 113 | _ => ("'", "'::DATE"), |
| 114 | }; |
| 115 | let (year, suffix) = if value.year() <= 0 { |
| 116 | // Year 0 in Postgres is 1 BC |
| 117 | let suffix = if context.fragment == Fragment::Timestamp { |
| 118 | "" |
| 119 | } else { |
| 120 | " BC" |
| 121 | }; |
| 122 | (value.year().abs() + 1, suffix) |
| 123 | } else { |
| 124 | (value.year(), "") |
| 125 | }; |
| 126 | let month = value.month() as u8; |
| 127 | let day = value.day(); |
| 128 | let _ = write!(out, "{l}{year:04}-{month:02}-{day:02}{suffix}{r}"); |
| 129 | } |
| 130 | |
| 131 | fn write_time(&self, context: &mut Context, out: &mut DynQuery, value: &Time) { |
| 132 | let (l, r) = match context.fragment { |