1
- /*
2
- * The contents of this file are subject to the Initial
3
- * Developer's Public License Version 1.0 (the "License");
4
- * you may not use this file except in compliance with the
5
- * License. You may obtain a copy of the License at
6
- * https://github.com/FirebirdSQL/NETProvider/raw/master/license.txt.
7
- *
8
- * Software distributed under the License is distributed on
9
- * an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
10
- * express or implied. See the License for the specific
11
- * language governing rights and limitations under the License.
12
- *
13
- * All Rights Reserved.
14
- */
15
-
16
- //$Authors = Jiri Cincura ([email protected] )
17
-
18
- using System ;
19
- using System . Runtime . InteropServices ;
20
-
21
- namespace FirebirdSql . Data . Types ;
22
-
23
- [ StructLayout ( LayoutKind . Auto ) ]
24
- public readonly struct FbZonedDateTime : IEquatable < FbZonedDateTime > , IConvertible
25
- {
26
- public DateTime DateTime { get ; }
27
- public string TimeZone { get ; }
28
- public TimeSpan ? Offset { get ; }
29
-
30
- internal FbZonedDateTime ( DateTime dateTime , string timeZone , TimeSpan ? offset )
31
- {
32
- if ( dateTime . Kind != DateTimeKind . Utc )
33
- throw new ArgumentException ( "Value must be in UTC." , nameof ( dateTime ) ) ;
34
- if ( timeZone == null )
35
- throw new ArgumentNullException ( nameof ( timeZone ) ) ;
36
- if ( string . IsNullOrWhiteSpace ( timeZone ) )
37
- throw new ArgumentException ( nameof ( timeZone ) ) ;
38
-
39
- DateTime = dateTime ;
40
- TimeZone = timeZone ;
41
- Offset = offset ;
42
- }
43
-
44
- public FbZonedDateTime ( DateTime dateTime , string timeZone )
45
- : this ( dateTime , timeZone , null )
46
- { }
47
-
48
- public override string ToString ( )
49
- {
50
- if ( Offset != null )
51
- {
52
- return $ "{ DateTime } { TimeZone } ({ Offset } )";
53
- }
54
- return $ "{ DateTime } { TimeZone } ";
55
- }
56
-
57
- public override bool Equals ( object obj )
58
- {
59
- return obj is FbZonedDateTime fbZonedDateTime && Equals ( fbZonedDateTime ) ;
60
- }
61
-
62
- public override int GetHashCode ( )
63
- {
64
- unchecked
65
- {
66
- var hash = ( int ) 2166136261 ;
67
- hash = ( hash * 16777619 ) ^ DateTime . GetHashCode ( ) ;
68
- hash = ( hash * 16777619 ) ^ TimeZone . GetHashCode ( ) ;
69
- if ( Offset != null )
70
- hash = ( hash * 16777619 ) ^ Offset . GetHashCode ( ) ;
71
- return hash ;
72
- }
73
- }
74
-
1
+ /*
2
+ * The contents of this file are subject to the Initial
3
+ * Developer's Public License Version 1.0 (the "License");
4
+ * you may not use this file except in compliance with the
5
+ * License. You may obtain a copy of the License at
6
+ * https://github.com/FirebirdSQL/NETProvider/raw/master/license.txt.
7
+ *
8
+ * Software distributed under the License is distributed on
9
+ * an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
10
+ * express or implied. See the License for the specific
11
+ * language governing rights and limitations under the License.
12
+ *
13
+ * All Rights Reserved.
14
+ */
15
+
16
+ //$Authors = Jiri Cincura ([email protected] )
17
+
18
+ using System ;
19
+ using System . Runtime . InteropServices ;
20
+
21
+ namespace FirebirdSql . Data . Types ;
22
+
23
+ [ StructLayout ( LayoutKind . Auto ) ]
24
+ public readonly struct FbZonedDateTime : IEquatable < FbZonedDateTime > , IConvertible
25
+ {
26
+ public DateTime DateTime { get ; }
27
+ public string TimeZone { get ; }
28
+ public TimeSpan ? Offset { get ; }
29
+
30
+ internal FbZonedDateTime ( DateTime dateTime , string timeZone , TimeSpan ? offset )
31
+ {
32
+ if ( dateTime . Kind != DateTimeKind . Utc )
33
+ throw new ArgumentException ( "Value must be in UTC." , nameof ( dateTime ) ) ;
34
+ if ( timeZone == null )
35
+ throw new ArgumentNullException ( nameof ( timeZone ) ) ;
36
+ if ( string . IsNullOrWhiteSpace ( timeZone ) )
37
+ throw new ArgumentException ( nameof ( timeZone ) ) ;
38
+
39
+ DateTime = dateTime ;
40
+ TimeZone = timeZone ;
41
+ Offset = offset ;
42
+ }
43
+
44
+ public FbZonedDateTime ( DateTime dateTime , string timeZone )
45
+ : this ( dateTime , timeZone , null )
46
+ { }
47
+
48
+ public override string ToString ( )
49
+ {
50
+ if ( Offset != null )
51
+ {
52
+ return $ "{ DateTime } { TimeZone } ({ Offset } )";
53
+ }
54
+ return $ "{ DateTime } { TimeZone } ";
55
+ }
56
+
57
+ public override bool Equals ( object obj )
58
+ {
59
+ return obj is FbZonedDateTime fbZonedDateTime && Equals ( fbZonedDateTime ) ;
60
+ }
61
+
62
+ public override int GetHashCode ( )
63
+ {
64
+ unchecked
65
+ {
66
+ var hash = ( int ) 2166136261 ;
67
+ hash = ( hash * 16777619 ) ^ DateTime . GetHashCode ( ) ;
68
+ hash = ( hash * 16777619 ) ^ TimeZone . GetHashCode ( ) ;
69
+ if ( Offset != null )
70
+ hash = ( hash * 16777619 ) ^ Offset . GetHashCode ( ) ;
71
+ return hash ;
72
+ }
73
+ }
74
+
75
75
public bool Equals ( FbZonedDateTime other ) => DateTime . Equals ( other . DateTime ) && TimeZone . Equals ( other . TimeZone , StringComparison . OrdinalIgnoreCase ) ;
76
76
77
77
TypeCode IConvertible . GetTypeCode ( ) => TypeCode . Object ;
@@ -81,35 +81,25 @@ public override int GetHashCode()
81
81
string IConvertible . ToString ( IFormatProvider provider ) => ToString ( ) ;
82
82
83
83
object IConvertible . ToType ( Type conversionType , IFormatProvider provider )
84
- => ReferenceEquals ( conversionType , typeof ( FbZonedDateTime ) ) ? this : throw new InvalidCastException ( conversionType ? . FullName ) ;
84
+ => ReferenceEquals ( conversionType , typeof ( FbZonedDateTime ) )
85
+ ? this
86
+ : throw new InvalidCastException ( conversionType ? . FullName ) ;
85
87
86
88
bool IConvertible . ToBoolean ( IFormatProvider provider ) => throw new InvalidCastException ( nameof ( Boolean ) ) ;
87
-
88
89
byte IConvertible . ToByte ( IFormatProvider provider ) => throw new InvalidCastException ( nameof ( Byte ) ) ;
89
-
90
90
char IConvertible . ToChar ( IFormatProvider provider ) => throw new InvalidCastException ( nameof ( Char ) ) ;
91
-
92
91
decimal IConvertible . ToDecimal ( IFormatProvider provider ) => throw new InvalidCastException ( nameof ( Decimal ) ) ;
93
-
94
92
double IConvertible . ToDouble ( IFormatProvider provider ) => throw new InvalidCastException ( nameof ( Double ) ) ;
95
-
96
93
short IConvertible . ToInt16 ( IFormatProvider provider ) => throw new InvalidCastException ( nameof ( Int16 ) ) ;
97
-
98
94
int IConvertible . ToInt32 ( IFormatProvider provider ) => throw new InvalidCastException ( nameof ( Int32 ) ) ;
99
-
100
95
long IConvertible . ToInt64 ( IFormatProvider provider ) => throw new InvalidCastException ( nameof ( Int64 ) ) ;
101
-
102
96
sbyte IConvertible . ToSByte ( IFormatProvider provider ) => throw new InvalidCastException ( nameof ( SByte ) ) ;
103
-
104
97
float IConvertible . ToSingle ( IFormatProvider provider ) => throw new InvalidCastException ( nameof ( Single ) ) ;
105
-
106
98
ushort IConvertible . ToUInt16 ( IFormatProvider provider ) => throw new InvalidCastException ( nameof ( UInt16 ) ) ;
107
-
108
99
uint IConvertible . ToUInt32 ( IFormatProvider provider ) => throw new InvalidCastException ( nameof ( UInt32 ) ) ;
109
-
110
100
ulong IConvertible . ToUInt64 ( IFormatProvider provider ) => throw new InvalidCastException ( nameof ( UInt64 ) ) ;
111
101
112
- public static bool operator == ( FbZonedDateTime lhs , FbZonedDateTime rhs ) => lhs . Equals ( rhs ) ;
113
-
114
- public static bool operator != ( FbZonedDateTime lhs , FbZonedDateTime rhs ) => lhs . Equals ( rhs ) ;
115
- }
102
+ public static bool operator == ( FbZonedDateTime lhs , FbZonedDateTime rhs ) => lhs . Equals ( rhs ) ;
103
+
104
+ public static bool operator != ( FbZonedDateTime lhs , FbZonedDateTime rhs ) => lhs . Equals ( rhs ) ;
105
+ }
0 commit comments