Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f00a9a9

Browse filesBrowse files
committed
Small cleanup after PRs.
1 parent cb6293e commit f00a9a9
Copy full SHA for f00a9a9

File tree

Expand file treeCollapse file tree

2 files changed

+157
-180
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+157
-180
lines changed
+81-91Lines changed: 81 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,77 @@
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 (jiri@cincura.net)
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 (jiri@cincura.net)
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+
7575
public bool Equals(FbZonedDateTime other) => DateTime.Equals(other.DateTime) && TimeZone.Equals(other.TimeZone, StringComparison.OrdinalIgnoreCase);
7676

7777
TypeCode IConvertible.GetTypeCode() => TypeCode.Object;
@@ -81,35 +81,25 @@ public override int GetHashCode()
8181
string IConvertible.ToString(IFormatProvider provider) => ToString();
8282

8383
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);
8587

8688
bool IConvertible.ToBoolean(IFormatProvider provider) => throw new InvalidCastException(nameof(Boolean));
87-
8889
byte IConvertible.ToByte(IFormatProvider provider) => throw new InvalidCastException(nameof(Byte));
89-
9090
char IConvertible.ToChar(IFormatProvider provider) => throw new InvalidCastException(nameof(Char));
91-
9291
decimal IConvertible.ToDecimal(IFormatProvider provider) => throw new InvalidCastException(nameof(Decimal));
93-
9492
double IConvertible.ToDouble(IFormatProvider provider) => throw new InvalidCastException(nameof(Double));
95-
9693
short IConvertible.ToInt16(IFormatProvider provider) => throw new InvalidCastException(nameof(Int16));
97-
9894
int IConvertible.ToInt32(IFormatProvider provider) => throw new InvalidCastException(nameof(Int32));
99-
10095
long IConvertible.ToInt64(IFormatProvider provider) => throw new InvalidCastException(nameof(Int64));
101-
10296
sbyte IConvertible.ToSByte(IFormatProvider provider) => throw new InvalidCastException(nameof(SByte));
103-
10497
float IConvertible.ToSingle(IFormatProvider provider) => throw new InvalidCastException(nameof(Single));
105-
10698
ushort IConvertible.ToUInt16(IFormatProvider provider) => throw new InvalidCastException(nameof(UInt16));
107-
10899
uint IConvertible.ToUInt32(IFormatProvider provider) => throw new InvalidCastException(nameof(UInt32));
109-
110100
ulong IConvertible.ToUInt64(IFormatProvider provider) => throw new InvalidCastException(nameof(UInt64));
111101

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+
}
+76-89Lines changed: 76 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,75 @@
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 (jiri@cincura.net)
17-
18-
using System;
19-
using System.Runtime.InteropServices;
20-
21-
namespace FirebirdSql.Data.Types;
22-
23-
[StructLayout(LayoutKind.Auto)]
24-
public readonly struct FbZonedTime : IEquatable<FbZonedTime>, IConvertible
25-
{
26-
public TimeSpan Time { get; }
27-
public string TimeZone { get; }
28-
public TimeSpan? Offset { get; }
29-
30-
internal FbZonedTime(TimeSpan time, string timeZone, TimeSpan? offset)
31-
{
32-
if (timeZone == null)
33-
throw new ArgumentNullException(nameof(timeZone));
34-
if (string.IsNullOrWhiteSpace(timeZone))
35-
throw new ArgumentException(nameof(timeZone));
36-
37-
Time = time;
38-
TimeZone = timeZone;
39-
Offset = offset;
40-
}
41-
42-
public FbZonedTime(TimeSpan time, string timeZone)
43-
: this(time, timeZone, null)
44-
{ }
45-
46-
public override string ToString()
47-
{
48-
if (Offset != null)
49-
{
50-
return $"{Time} {TimeZone} ({Offset})";
51-
}
52-
return $"{Time} {TimeZone}";
53-
}
54-
55-
public override bool Equals(object obj)
56-
{
57-
return obj is FbZonedTime fbZonedTime && Equals(fbZonedTime);
58-
}
59-
60-
public override int GetHashCode()
61-
{
62-
unchecked
63-
{
64-
var hash = (int)2166136261;
65-
hash = (hash * 16777619) ^ Time.GetHashCode();
66-
hash = (hash * 16777619) ^ TimeZone.GetHashCode();
67-
if (Offset != null)
68-
hash = (hash * 16777619) ^ Offset.GetHashCode();
69-
return hash;
70-
}
71-
}
72-
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 (jiri@cincura.net)
17+
18+
using System;
19+
using System.Runtime.InteropServices;
20+
21+
namespace FirebirdSql.Data.Types;
22+
23+
[StructLayout(LayoutKind.Auto)]
24+
public readonly struct FbZonedTime : IEquatable<FbZonedTime>, IConvertible
25+
{
26+
public TimeSpan Time { get; }
27+
public string TimeZone { get; }
28+
public TimeSpan? Offset { get; }
29+
30+
internal FbZonedTime(TimeSpan time, string timeZone, TimeSpan? offset)
31+
{
32+
if (timeZone == null)
33+
throw new ArgumentNullException(nameof(timeZone));
34+
if (string.IsNullOrWhiteSpace(timeZone))
35+
throw new ArgumentException(nameof(timeZone));
36+
37+
Time = time;
38+
TimeZone = timeZone;
39+
Offset = offset;
40+
}
41+
42+
public FbZonedTime(TimeSpan time, string timeZone)
43+
: this(time, timeZone, null)
44+
{ }
45+
46+
public override string ToString()
47+
{
48+
if (Offset != null)
49+
{
50+
return $"{Time} {TimeZone} ({Offset})";
51+
}
52+
return $"{Time} {TimeZone}";
53+
}
54+
55+
public override bool Equals(object obj)
56+
{
57+
return obj is FbZonedTime fbZonedTime && Equals(fbZonedTime);
58+
}
59+
60+
public override int GetHashCode()
61+
{
62+
unchecked
63+
{
64+
var hash = (int)2166136261;
65+
hash = (hash * 16777619) ^ Time.GetHashCode();
66+
hash = (hash * 16777619) ^ TimeZone.GetHashCode();
67+
if (Offset != null)
68+
hash = (hash * 16777619) ^ Offset.GetHashCode();
69+
return hash;
70+
}
71+
}
72+
7373
public bool Equals(FbZonedTime other) => Time.Equals(other.Time) && TimeZone.Equals(other.TimeZone, StringComparison.OrdinalIgnoreCase);
7474

7575
TypeCode IConvertible.GetTypeCode() => TypeCode.Object;
@@ -84,34 +84,21 @@ object IConvertible.ToType(Type conversionType, IFormatProvider provider)
8484
: throw new InvalidCastException(conversionType?.FullName);
8585

8686
bool IConvertible.ToBoolean(IFormatProvider provider) => throw new InvalidCastException(nameof(Boolean));
87-
8887
byte IConvertible.ToByte(IFormatProvider provider) => throw new InvalidCastException(nameof(Byte));
89-
9088
char IConvertible.ToChar(IFormatProvider provider) => throw new InvalidCastException(nameof(Char));
91-
9289
DateTime IConvertible.ToDateTime(IFormatProvider provider) => throw new InvalidCastException(nameof(DateTime));
93-
9490
decimal IConvertible.ToDecimal(IFormatProvider provider) => throw new InvalidCastException(nameof(Decimal));
95-
9691
double IConvertible.ToDouble(IFormatProvider provider) => throw new InvalidCastException(nameof(Double));
97-
9892
short IConvertible.ToInt16(IFormatProvider provider) => throw new InvalidCastException(nameof(Int16));
99-
10093
int IConvertible.ToInt32(IFormatProvider provider) => throw new InvalidCastException(nameof(Int32));
101-
10294
long IConvertible.ToInt64(IFormatProvider provider) => throw new InvalidCastException(nameof(Int64));
103-
10495
sbyte IConvertible.ToSByte(IFormatProvider provider) => throw new InvalidCastException(nameof(SByte));
105-
10696
float IConvertible.ToSingle(IFormatProvider provider) => throw new InvalidCastException(nameof(Single));
107-
10897
ushort IConvertible.ToUInt16(IFormatProvider provider) => throw new InvalidCastException(nameof(UInt16));
109-
11098
uint IConvertible.ToUInt32(IFormatProvider provider) => throw new InvalidCastException(nameof(UInt32));
111-
11299
ulong IConvertible.ToUInt64(IFormatProvider provider) => throw new InvalidCastException(nameof(UInt64));
113100

114-
public static bool operator ==(FbZonedTime lhs, FbZonedTime rhs) => lhs.Equals(rhs);
115-
116-
public static bool operator !=(FbZonedTime lhs, FbZonedTime rhs) => lhs.Equals(rhs);
117-
}
101+
public static bool operator ==(FbZonedTime lhs, FbZonedTime rhs) => lhs.Equals(rhs);
102+
103+
public static bool operator !=(FbZonedTime lhs, FbZonedTime rhs) => lhs.Equals(rhs);
104+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.