public void CreateValidSleepDataStructSucceeds(int[] start, int[] end) { var s = new DateTime(start[0], start[1], start[2], start[3], start[4], start[5]).RoundToNearest(TimeSpan.FromMinutes(1)); var e = new DateTime(end[0], end[1], end[2], end[3], end[4], end[5]).RoundToNearest(TimeSpan.FromMinutes(1)); var struc = new SleepDataStruct(s, e); Assert.Equal(e, struc.End.AsDateTime()); Assert.Equal(s, struc.Start.AsDateTime()); }
public void CreateValidSleepBlockFromStructSucceeds() { var start = new DateTime(2020, 09, 10, 10, 10, 01).RoundToNearest(TimeSpan.FromMinutes(1)); var end = new DateTime(2020, 09, 11, 11, 5, 4).RoundToNearest(TimeSpan.FromMinutes(1)); var struc = new SleepDataStruct(start, end); Assert.Equal(start, struc.Start.AsDateTime()); Assert.Equal(end, struc.End.AsDateTime()); var block = new SleepBlock(ref struc); Assert.Equal(start, block.Start); Assert.Equal(end, block.End); Assert.Equal(struc.Start.AsDateTime(), block.Start); Assert.Equal(struc.End.AsDateTime(), block.End); }
public bool WriteSleepData(List <SleepBlock> blocks) { if (SMProcess.IsOpen()) { Console.WriteLine("Failed to write sleep data because there is a running SuperMemo process"); return(false); } using (BinaryWriter writer = new BinaryWriter(File.OpenWrite(SleepData))) { foreach (var block in blocks) { var sleepStruct = new SleepDataStruct(block.Start, block.End); if (!writer.WriteStruct(sleepStruct)) { return(false); } } return(true); } }