@@ -29,35 +29,76 @@ const MONTHS_PER_YEAR: i32 = 12;
2929
3030const TIMESTAMP_FORMAT : & str = "%Y-%m-%d %H:%M:%S%.6f" ;
3131
32+ /// Represents extended JSON value types that are not supported in standard JSON.
33+ ///
34+ /// Standard JSON only supports strings, numbers, booleans, null, arrays, and objects.
35+ /// This enum provides additional data types commonly needed in database systems and
36+ /// other applications that require more specialized data representations.
3237#[ derive( Debug , Clone ) ]
3338pub enum ExtensionValue < ' a > {
39+ /// Binary data (byte array), allowing efficient storage of binary content
40+ /// that would otherwise require base64 encoding in standard JSON
3441 Binary ( & ' a [ u8 ] ) ,
42+ /// Calendar date without time component (year, month, day)
3543 Date ( Date ) ,
44+ /// Timestamp with microsecond precision but without timezone information
3645 Timestamp ( Timestamp ) ,
46+ /// Timestamp with microsecond precision and timezone offset information
3747 TimestampTz ( TimestampTz ) ,
48+ /// Time interval representation for duration calculations
3849 Interval ( Interval ) ,
3950}
4051
52+ /// Represents a calendar date (year, month, day) without time component.
53+ ///
54+ /// The value is stored as days since the Unix epoch (January 1, 1970).
55+ /// This allows for efficient date arithmetic and comparison operations.
56+ /// Standard JSON has no native date type and typically uses ISO 8601 strings.
4157#[ derive( Debug , Clone , PartialEq , Eq , Ord , PartialOrd ) ]
4258pub struct Date {
59+ /// Days since Unix epoch (January 1, 1970)
60+ /// Positive values represent dates after the epoch, negative values represent dates before
4361 pub value : i32 ,
4462}
4563
64+ /// Represents a timestamp (date and time) without timezone information.
65+ ///
66+ /// The value is stored as microseconds since the Unix epoch (January 1, 1970 00:00:00 UTC).
67+ /// This provides microsecond precision for timestamp operations.
68+ /// Standard JSON has no native timestamp type and typically uses ISO 8601 strings.
4669#[ derive( Debug , Clone , PartialEq , Eq , Ord , PartialOrd ) ]
4770pub struct Timestamp {
71+ /// Microseconds since Unix epoch (January 1, 1970 00:00:00 UTC)
4872 pub value : i64 ,
4973}
5074
75+ /// Represents a timestamp with timezone information.
76+ ///
77+ /// Combines a timestamp value with a timezone offset, allowing for
78+ /// timezone-aware datetime operations. The timestamp is stored in UTC,
79+ /// and the offset indicates the local timezone.
80+ /// Standard JSON has no native timezone-aware timestamp type.
5181#[ derive( Debug , Clone , PartialEq , Eq , Ord , PartialOrd ) ]
5282pub struct TimestampTz {
83+ /// Timezone offset in hours from UTC
5384 pub offset : i8 ,
85+ /// Microseconds since Unix epoch (January 1, 1970 00:00:00 UTC)
5486 pub value : i64 ,
5587}
5688
89+ /// Represents a time interval or duration.
90+ ///
91+ /// This structure can represent complex time intervals with separate
92+ /// components for months, days, and microseconds, allowing for precise
93+ /// duration calculations that account for calendar irregularities.
94+ /// Standard JSON has no native interval/duration type.
5795#[ derive( Debug , Clone , PartialEq , Eq , Ord , PartialOrd ) ]
5896pub struct Interval {
97+ /// Number of months in the interval
5998 pub months : i32 ,
99+ /// Number of days in the interval
60100 pub days : i32 ,
101+ /// Number of microseconds in the interval
61102 pub micros : i64 ,
62103}
63104
0 commit comments