Skip to content

Commit eca2805

Browse files
committed
InfinityAliasTest changes
1 parent 50ff658 commit eca2805

1 file changed

Lines changed: 24 additions & 9 deletions

File tree

Orm/Xtensive.Orm.Tests.Sql/PostgreSql/InfinityAliasTest.cs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public sealed class InfinityAliasTest : SqlTest
2929
private TypeMapping dateTimeTypeMapping;
3030
private TypeMapping dateTimeOffsetTypeMapping;
3131

32+
private TimeSpan localTimezone;
33+
3234
protected override void CheckRequirements()
3335
{
3436
Require.ProviderIs(StorageProvider.PostgreSql);
@@ -39,6 +41,7 @@ protected override void TestFixtureSetUp()
3941
base.TestFixtureSetUp();
4042

4143
var localZone = DateTimeOffset.Now.ToLocalTime().Offset;
44+
localTimezone = localZone;
4245
var localZoneString = ((localZone < TimeSpan.Zero) ? "-" : "+") + localZone.ToString(@"hh\:mm");
4346
var initConnectionCommand = Connection.CreateCommand($"SET TIME ZONE INTERVAL '{localZoneString}' HOUR TO MINUTE");
4447
_ = initConnectionCommand.ExecuteNonQuery();
@@ -546,27 +549,39 @@ public void DateTimeOffsetMaxSelectDatePartDateTest()
546549

547550
private void TestMaxDateTimeOffsetSelectDatePart(bool isOn)
548551
{
552+
var overflowHappens = localTimezone > TimeSpan.Zero;
553+
549554
// There is overflow of year because of PostgreSQL time zone functionality
555+
var overflowYearValue = overflowHappens ? 1 : 0;
550556
TestDateTimeOffsetPartExtraction(DateTimeOffsetMaxValueTable, SqlDateTimeOffsetPart.Year,
551-
DateTimeOffset.MaxValue.Year + 1,
552-
(isOn) ? DateTimeOffset.MaxValue.Year : DateTimeOffset.MaxValue.Year + 1,
557+
DateTimeOffset.MaxValue.Year + overflowYearValue,
558+
(isOn) ? DateTimeOffset.MaxValue.Year + overflowYearValue : DateTimeOffset.MaxValue.Year + overflowYearValue,
553559
isOn);
554560

555561
// there is value overflow to 01 in case of no aliases
562+
var serverSideMonths = (localTimezone > TimeSpan.Zero) ? 1 : 12;
556563
TestDateTimeOffsetPartExtraction(DateTimeOffsetMaxValueTable, SqlDateTimeOffsetPart.Month,
557-
1,
558-
(isOn) ? DateTimeOffset.MaxValue.Month : 1,
564+
serverSideMonths,
565+
(isOn) ? serverSideMonths : serverSideMonths,
559566
isOn);
567+
560568
// there is value overflow to 01 in case of no aliases
569+
var serverSideDays = (localTimezone > TimeSpan.Zero) ? 1 : 31;
561570
TestDateTimeOffsetPartExtraction(DateTimeOffsetMaxValueTable, SqlDateTimeOffsetPart.Day,
562-
1,
563-
(isOn) ? DateTimeOffset.MaxValue.Day : 1,
571+
serverSideDays,
572+
(isOn) ? serverSideDays : serverSideDays,
564573
isOn);
565574

566575
// timezone for DateTimeOffset.MaxValue value in postgre is set to 04:59:59.999999, at least when instance is in UTC+5 timezone
576+
var serverSideHours = (localTimezone > TimeSpan.Zero)
577+
? localTimezone.Hours - 1 // positive zone
578+
: (localTimezone < TimeSpan.Zero)
579+
? 24 + localTimezone.Hours // negative zone
580+
: 0; // UTC
581+
567582
TestDateTimeOffsetPartExtraction(DateTimeOffsetMaxValueTable, SqlDateTimeOffsetPart.Hour,
568-
4,
569-
(isOn) ? DateTimeOffset.MaxValue.Hour : 4,
583+
serverSideHours,
584+
(isOn) ? serverSideHours : serverSideHours,
570585
isOn);
571586
TestDateTimeOffsetPartExtraction(DateTimeOffsetMaxValueTable, SqlDateTimeOffsetPart.Minute,
572587
DateTimeOffset.MaxValue.Minute,
@@ -686,7 +701,7 @@ private void TestDateTimeOffsetPartExtraction(string table, SqlDateTimeOffsetPar
686701
Assert.That(partValue, Is.Zero);
687702
}
688703
}
689-
if (Driver.CoreServerInfo.ServerVersion < StorageProviderVersion.PostgreSql96) {
704+
else if (Driver.CoreServerInfo.ServerVersion < StorageProviderVersion.PostgreSql96) {
690705
var partValue = reader.GetDouble(0);
691706
Assert.That(partValue, Is.Zero);
692707
}

0 commit comments

Comments
 (0)