feat(io): let NestWriter keep a nest's own modified date

Write always stamped DateLastModified with the save time. That is right
for an ordinary save, but a converter carrying another system's date
cannot keep it: every PEP nest imported into the server recorded the
import time as its modified date.

PreserveDateLastModified (init, default false) writes the nest's own
date instead; every existing caller keeps stamping.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ajandClaude Opus 5.5 committed 2026-10-21 07:14:06 -04:00
1 parent 64e24fc6c8
commit 2963764215
2 files changed
+50 -1

No files matched your search

@@ -0,0 +1,41 @@
namespace OpenNest.IO.Tests;
/// <summary>
/// An ordinary save records when it happened; a converter can keep the source system's
/// modified date through write and read.
/// </summary>
public class NestWriterModifiedDateTests
{
private static readonly DateTime SourceDate = new(2019, 5, 2, 13, 50, 15, DateTimeKind.Unspecified);
[Fact]
public void Write_StampsTheSaveTimeByDefault()
{
var nest = new Nest("Stamped") { DateLastModified = SourceDate };
var before = DateTime.Now;
var restored = RoundTrip(new NestWriter(nest));
Assert.InRange(restored.DateLastModified, before.AddSeconds(-1), DateTime.Now.AddSeconds(1));
Assert.Equal(restored.DateLastModified, nest.DateLastModified);
}
[Fact]
public void Write_PreserveDateLastModified_KeepsTheNestsOwnDate()
{
var nest = new Nest("Preserved") { DateLastModified = SourceDate };
var restored = RoundTrip(new NestWriter(nest) { PreserveDateLastModified = true });
Assert.Equal(SourceDate, restored.DateLastModified);
Assert.Equal(SourceDate, nest.DateLastModified);
}
private static Nest RoundTrip(NestWriter writer)
{
using var stream = new MemoryStream();
Assert.True(writer.Write(stream));
stream.Position = 0;
return new NestReader(stream).Read();
}
}
+9 -1
View File
@@ -30,6 +30,13 @@ namespace OpenNest.IO
/// </summary>
public IBestFitStore BestFitStore { get; init; }
/// <summary>
/// Writes the nest's own <see cref="Nest.DateLastModified"/> instead of stamping the save
/// time. For converters and importers carrying another system's date; an ordinary save
/// leaves this false so the file records when it was saved.
/// </summary>
public bool PreserveDateLastModified { get; init; }
public NestWriter(Nest nest)
{
this.drawingDict = new Dictionary<int, Drawing>();
@@ -44,7 +51,8 @@ namespace OpenNest.IO
public bool Write(Stream stream)
{
nest.DateLastModified = DateTime.Now;
if (!PreserveDateLastModified)
nest.DateLastModified = DateTime.Now;
SetDrawingIds();
using var zipArchive = new ZipArchive(stream, ZipArchiveMode.Create, leaveOpen: true);