public void PatchDateOnlyAndTimeOnly() { using var store = GetDocumentStore(); var @do = new DateOnly(2022, 2, 21); var to = new TimeOnly(21, 11, 00); string id; var entity = new DateAndTimeOnly() { DateOnly = @do, TimeOnly = to }; { using var session = store.OpenSession(); session.Store(entity); session.SaveChanges(); id = session.Advanced.GetDocumentId(entity); } { using var session = store.OpenSession(); session.Advanced.Patch <DateAndTimeOnly, DateOnly>(id, x => x.DateOnly, @do.AddDays(1)); session.SaveChanges(); } { using var session = store.OpenSession(); var single = session.Query <DateAndTimeOnly>().Single(); Assert.Equal(@do.AddDays(1), single.DateOnly); } { using var session = store.OpenSession(); session.Advanced.Patch <DateAndTimeOnly, TimeOnly>(id, x => x.TimeOnly, to.AddHours(1)); session.SaveChanges(); } { using var session = store.OpenSession(); var single = session.Query <DateAndTimeOnly>().Single(); Assert.Equal(to.AddHours(1), single.TimeOnly); } }
public static void AddTest() { TimeOnly to = new TimeOnly(1, 10, 20, 900); to = to.Add(new TimeSpan(1)); Assert.Equal(TimeSpan.NanosecondsPerTick, to.Nanosecond); to = to.Add(new TimeSpan(TimeSpan.TicksPerMicrosecond)); Assert.Equal(1, to.Microsecond); to = to.Add(new TimeSpan(TimeSpan.TicksPerMillisecond)); Assert.Equal(901, to.Millisecond); to = to.Add(new TimeSpan(TimeSpan.TicksPerSecond)); Assert.Equal(21, to.Second); to = to.Add(new TimeSpan(TimeSpan.TicksPerMinute)); Assert.Equal(11, to.Minute); to = to.Add(new TimeSpan(TimeSpan.TicksPerHour)); Assert.Equal(2, to.Hour); to = TimeOnly.MinValue.Add(new TimeSpan(-1), out int wrappedDays); Assert.Equal(23, to.Hour); Assert.Equal(59, to.Minute); Assert.Equal(59, to.Second); Assert.Equal(999, to.Millisecond); Assert.Equal(-1, wrappedDays); to = TimeOnly.MinValue.Add(new TimeSpan(48, 0, 0), out wrappedDays); Assert.Equal(0, to.Hour); Assert.Equal(0, to.Minute); Assert.Equal(0, to.Second); Assert.Equal(0, to.Millisecond); Assert.Equal(2, wrappedDays); to = to.Add(new TimeSpan(1, 0, 0), out wrappedDays); Assert.Equal(0, wrappedDays); to = TimeOnly.MinValue.AddHours(1.5); Assert.Equal(1, to.Hour); Assert.Equal(30, to.Minute); Assert.Equal(0, to.Second); Assert.Equal(0, to.Millisecond); Assert.Equal(0, to.Microsecond); Assert.Equal(0, to.Nanosecond); to = to.AddHours(1.5, out wrappedDays); Assert.Equal(3, to.Hour); Assert.Equal(0, to.Minute); Assert.Equal(0, to.Second); Assert.Equal(0, to.Microsecond); Assert.Equal(0, to.Nanosecond); Assert.Equal(0, wrappedDays); to = to.AddHours(-28, out wrappedDays); Assert.Equal(23, to.Hour); Assert.Equal(0, to.Minute); Assert.Equal(-2, wrappedDays); to = to.AddHours(1, out wrappedDays); Assert.Equal(1, wrappedDays); Assert.Equal(0, to.Hour); Assert.Equal(0, to.Minute); to = to.AddMinutes(190.5); Assert.Equal(3, to.Hour); Assert.Equal(10, to.Minute); Assert.Equal(30, to.Second); to = to.AddMinutes(-4 * 60, out wrappedDays); Assert.Equal(23, to.Hour); Assert.Equal(10, to.Minute); Assert.Equal(30, to.Second); Assert.Equal(-1, wrappedDays); to = to.AddMinutes(60.5, out wrappedDays); Assert.Equal(0, to.Hour); Assert.Equal(11, to.Minute); Assert.Equal(0, to.Second); Assert.Equal(1, wrappedDays); }