From 85c6191e3aeb19fa0be7f6ad68db02669f1780dd Mon Sep 17 00:00:00 2001 From: mark-sil Date: Tue, 9 Apr 2024 15:34:48 -0400 Subject: [PATCH 1/2] LT-21703: Fix problem with time/date format changing Instead of using a hardcoded time/date format string use the one from LCM. https://jira.sil.org/browse/LT-21703 --- .../Handling/PreferMostRecentTimePreMerger.cs | 5 ++- .../BaseFieldWorksTypeHandlerTests.cs | 2 +- .../Handling/DateTimeMergingTests.cs | 38 +++++++++---------- .../FieldWorksLexiconTypeHandlerTests.cs | 10 ++--- .../PreferMostRecentTimePreMergerTests.cs | 4 +- .../TestData/DataNotebook_Ann.ntbk | 14 +++---- .../TestData/DataNotebook_Common.ntbk | 14 +++---- .../TestData/DataNotebook_Susanna.ntbk | 14 +++---- 8 files changed, 52 insertions(+), 49 deletions(-) diff --git a/src/LibFLExBridge-ChorusPlugin/Handling/PreferMostRecentTimePreMerger.cs b/src/LibFLExBridge-ChorusPlugin/Handling/PreferMostRecentTimePreMerger.cs index 9b870e3bf..4d1f15573 100644 --- a/src/LibFLExBridge-ChorusPlugin/Handling/PreferMostRecentTimePreMerger.cs +++ b/src/LibFLExBridge-ChorusPlugin/Handling/PreferMostRecentTimePreMerger.cs @@ -44,7 +44,10 @@ void IPremerger.Premerge(IMergeEventListener listener, ref XmlNode ourDateTimeNo // something else besides the timestamp changed. Set timestamp to current time. newestDateTime = DateTimeProvider.Current.UtcNow; } - var newestDateTimeString = newestDateTime.ToString("yyyy-M-d H:m:s.fff", CultureInfo.InvariantCulture); + + string formatStr = SIL.LCModel.Utils.SilUtilsExtensions.LCMTimeFormatWithMillis; + var newestDateTimeString = newestDateTime.ToString(formatStr, CultureInfo.InvariantCulture); + UpdateDateTimeVal(newestDateTimeString, ourDateTimeNode); UpdateDateTimeVal(newestDateTimeString, theirDateTimeNode); } diff --git a/src/LibFLExBridge-ChorusPluginTests/Handling/BaseFieldWorksTypeHandlerTests.cs b/src/LibFLExBridge-ChorusPluginTests/Handling/BaseFieldWorksTypeHandlerTests.cs index cd8bd1d37..864b2f2be 100644 --- a/src/LibFLExBridge-ChorusPluginTests/Handling/BaseFieldWorksTypeHandlerTests.cs +++ b/src/LibFLExBridge-ChorusPluginTests/Handling/BaseFieldWorksTypeHandlerTests.cs @@ -51,7 +51,7 @@ public static string GetXPathNodeFrom(string xml, string xpath) public static DateTime _expectedUtcDateTime; - public static string ExpectedUtcDateTimeString => ExpectedDateTime.ToString("yyyy-M-d H:m:s.fff", CultureInfo.InvariantCulture); + public static string ExpectedUtcDateTimeString => ExpectedDateTime.ToString(SIL.LCModel.Utils.SilUtilsExtensions.LCMTimeFormatWithMillis, CultureInfo.InvariantCulture); public static DateTime ExpectedDateTime { diff --git a/src/LibFLExBridge-ChorusPluginTests/Handling/DateTimeMergingTests.cs b/src/LibFLExBridge-ChorusPluginTests/Handling/DateTimeMergingTests.cs index f0e312420..8bda7d554 100644 --- a/src/LibFLExBridge-ChorusPluginTests/Handling/DateTimeMergingTests.cs +++ b/src/LibFLExBridge-ChorusPluginTests/Handling/DateTimeMergingTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2010-2016 SIL International +// Copyright (c) 2010-2016 SIL International // This software is licensed under the MIT License (http://opensource.org/licenses/MIT) using System; @@ -41,7 +41,7 @@ public override void TestTearDown() private const string CommonOwnSeqAncestor = @" - + commonName @@ -51,7 +51,7 @@ public override void TestTearDown() [Test] public void OurOriginalTimestampRestoredToAncestorValueIfOnlyChangeWasTimestampAndTheyDeletedParent() { - var ourContent = CommonOwnSeqAncestor.Replace("2000-1-1 23:59:59.123", "2002-1-1 23:59:59.123"); + var ourContent = CommonOwnSeqAncestor.Replace("2000-01-01 23:59:59.123", "2002-01-01 23:59:59.123"); var ancestorNode = XmlUtilities.GetDocumentNodeFromRawXml(CommonOwnSeqAncestor, new XmlDocument()); var ancestorModPropNode = ancestorNode.SelectSingleNode("DateModified"); @@ -60,13 +60,13 @@ public void OurOriginalTimestampRestoredToAncestorValueIfOnlyChangeWasTimestampA IPremerger premerger = new PreferMostRecentTimePreMerger(); premerger.Premerge(new ListenerForUnitTests(), ref ourModPropNode, null, ancestorModPropNode); - Assert.AreEqual("2000-1-1 23:59:59.123", ourModPropNode.Attributes["val"].Value); + Assert.AreEqual("2000-01-01 23:59:59.123", ourModPropNode.Attributes["val"].Value); } [Test] public void TimestampUpdatedIfAnotherChangedWasMadeAndTheyDeletedParent() { - var ourContent = CommonOwnSeqAncestor.Replace("2000-1-1 23:59:59.123", "2002-1-1 23:59:59.123").Replace("commonName", "ourModifiedName"); + var ourContent = CommonOwnSeqAncestor.Replace("2000-01-01 23:59:59.123", "2002-01-01 23:59:59.123").Replace("commonName", "ourModifiedName"); var ancestorNode = XmlUtilities.GetDocumentNodeFromRawXml(CommonOwnSeqAncestor, new XmlDocument()); var ancestorModPropNode = ancestorNode.SelectSingleNode("DateModified"); @@ -81,7 +81,7 @@ public void TimestampUpdatedIfAnotherChangedWasMadeAndTheyDeletedParent() [Test] public void TheirOriginalTimestampRestoredToAncestorValueIfOnlyChangeWasTimestampAndWeDeletedParent() { - var theirContent = CommonOwnSeqAncestor.Replace("2000-1-1 23:59:59.123", "2002-1-1 23:59:59.123"); + var theirContent = CommonOwnSeqAncestor.Replace("2000-01-01 23:59:59.123", "2002-01-01 23:59:59.123"); var ancestorNode = XmlUtilities.GetDocumentNodeFromRawXml(CommonOwnSeqAncestor, new XmlDocument()); var ancestorModPropNode = ancestorNode.SelectSingleNode("DateModified"); @@ -91,13 +91,13 @@ public void TheirOriginalTimestampRestoredToAncestorValueIfOnlyChangeWasTimestam XmlNode ourNode = null; premerger.Premerge(new ListenerForUnitTests(), ref ourNode, theirModPropNode, ancestorModPropNode); - Assert.AreEqual("2000-1-1 23:59:59.123", theirModPropNode.Attributes["val"].Value); + Assert.AreEqual("2000-01-01 23:59:59.123", theirModPropNode.Attributes["val"].Value); } [Test] public void TimestampUpdatedIfAnotherChangeWasMadeAndWeDeletedParent() { - var theirContent = CommonOwnSeqAncestor.Replace("2000-1-1 23:59:59.123", "2002-1-1 23:59:59.123").Replace("commonName", "theirModifiedName"); + var theirContent = CommonOwnSeqAncestor.Replace("2000-01-01 23:59:59.123", "2002-01-01 23:59:59.123").Replace("commonName", "theirModifiedName"); var ancestorNode = XmlUtilities.GetDocumentNodeFromRawXml(CommonOwnSeqAncestor, new XmlDocument()); var ancestorModPropNode = ancestorNode.SelectSingleNode("DateModified"); @@ -130,16 +130,16 @@ public void TimestampUpdatedIfAnotherChangeWasMadeAndWeDeletedParent() "; - [TestCase("", "2002-1-1 23:59:59.123", "2001-1-1 23:59:59.123", "newModifiedName", 2, new[]{ typeof(XmlAttributeBothMadeSameChangeReport), typeof(XmlTextBothMadeSameChangeReport) }, TestName = "Timestamp updated")] - [TestCase("", "2002-1-1 23:59:59.123", "2001-1-1 23:59:59.123", "newModifiedName", 2, new[] { typeof(XmlAttributeBothAddedReport), typeof(XmlTextBothMadeSameChangeReport) }, TestName = "Timestamp updated - no ancestor timestamp")] - [TestCase("", "2002-1-1 23:59:59.123", "2001-1-1 23:59:59.123", "commonName", 1, new[] { typeof(XmlAttributeBothAddedReport) }, TestName = "DateModified-only change - Timestamp updated")] - [TestCase("", "2001-1-1 23:59:59.123", "2002-1-1 23:59:59.123", "newModifiedName", 2, new[]{ typeof(XmlAttributeBothMadeSameChangeReport), typeof(XmlTextBothMadeSameChangeReport) })] - [TestCase("", "2001-1-1 23:59:59.123", "2002-1-1 23:59:59.123", "commonName", 1, new[] { typeof(XmlAttributeBothAddedReport) })] + [TestCase("", "2002-01-01 23:59:59.123", "2001-01-01 23:59:59.123", "newModifiedName", 2, new[]{ typeof(XmlAttributeBothMadeSameChangeReport), typeof(XmlTextBothMadeSameChangeReport) }, TestName = "Timestamp updated")] + [TestCase("", "2002-01-01 23:59:59.123", "2001-01-01 23:59:59.123", "newModifiedName", 2, new[] { typeof(XmlAttributeBothAddedReport), typeof(XmlTextBothMadeSameChangeReport) }, TestName = "Timestamp updated - no ancestor timestamp")] + [TestCase("", "2002-01-01 23:59:59.123", "2001-01-01 23:59:59.123", "commonName", 1, new[] { typeof(XmlAttributeBothAddedReport) }, TestName = "DateModified-only change - Timestamp updated")] + [TestCase("", "2001-01-01 23:59:59.123", "2002-01-01 23:59:59.123", "newModifiedName", 2, new[]{ typeof(XmlAttributeBothMadeSameChangeReport), typeof(XmlTextBothMadeSameChangeReport) })] + [TestCase("", "2001-01-01 23:59:59.123", "2002-01-01 23:59:59.123", "commonName", 1, new[] { typeof(XmlAttributeBothAddedReport) })] public void MergeConflict_TimestampUpdated(string ancestorDate, string ourDate, string theirDate, string modification, int expectedChangeCount, Type[] expectedChangeTypes) { var ancestorContent = CommonPosAncestor.Replace("DateGoesHere", ancestorDate); - var ourContent = CommonPosAncestor.Replace("DateGoesHere", "").Replace("commonName", modification); - var theirContent = CommonPosAncestor.Replace("DateGoesHere", "").Replace("commonName", modification); + var ourContent = CommonPosAncestor.Replace("DateGoesHere", "").Replace("commonName", modification); + var theirContent = CommonPosAncestor.Replace("DateGoesHere", "").Replace("commonName", modification); var results = FieldWorksTestServices.DoMerge( FileHandler, @@ -153,12 +153,12 @@ public void MergeConflict_TimestampUpdated(string ancestorDate, string ourDate, Is.EqualTo(ExpectedUtcDateTimeString)); } - [TestCase("", "commonName", 0, new Type[0], TestName = "DateModified-only change sets ancestor timestamp")] + [TestCase("", "commonName", 0, new Type[0], TestName = "DateModified-only change sets ancestor timestamp")] public void TimestampOnlyChange_TimestampKept(string ancestorDate, string modification, int expectedChangeCount, Type[] expectedChangeTypes) { var ancestorContent = CommonPosAncestor.Replace("DateGoesHere", ancestorDate); - var ourContent = CommonPosAncestor.Replace("DateGoesHere", "").Replace("commonName", modification); - var theirContent = CommonPosAncestor.Replace("DateGoesHere", "").Replace("commonName", modification); + var ourContent = CommonPosAncestor.Replace("DateGoesHere", "").Replace("commonName", modification); + var theirContent = CommonPosAncestor.Replace("DateGoesHere", "").Replace("commonName", modification); var results = FieldWorksTestServices.DoMerge( FileHandler, @@ -169,7 +169,7 @@ public void TimestampOnlyChange_TimestampKept(string ancestorDate, string modifi 0, new List(), expectedChangeCount, new List(expectedChangeTypes)); Assert.That(GetXPathNodeFrom(results, "Root/ReversalIndex/PartsOfSpeech/CmPossibilityList/Possibilities/ownseq/DateModified/@val"), - Is.EqualTo("2000-1-1 23:59:59.123")); + Is.EqualTo("2000-01-01 23:59:59.123")); } private static DateTime GetMergedTime(string filePath) diff --git a/src/LibFLExBridge-ChorusPluginTests/Handling/Linguistics/Lexicon/FieldWorksLexiconTypeHandlerTests.cs b/src/LibFLExBridge-ChorusPluginTests/Handling/Linguistics/Lexicon/FieldWorksLexiconTypeHandlerTests.cs index f274802fc..2e773a98a 100644 --- a/src/LibFLExBridge-ChorusPluginTests/Handling/Linguistics/Lexicon/FieldWorksLexiconTypeHandlerTests.cs +++ b/src/LibFLExBridge-ChorusPluginTests/Handling/Linguistics/Lexicon/FieldWorksLexiconTypeHandlerTests.cs @@ -281,7 +281,7 @@ public void SampleMergeWithAtomicConflictWeWin() - + @@ -298,8 +298,8 @@ public void SampleMergeWithAtomicConflictWeWin() public void MergeHasNoReportsForDeepDateModifiedChangesAndKeepsMostRecent() { const string commonAncestor = baseDocument; - var ourContent = commonAncestor.Replace("2011-2-2 19:39:28.829", "2012-2-2 19:39:28.829").Replace("False", "True"); - var theirContent = commonAncestor.Replace("2011-2-2 19:39:28.829", "2013-2-2 19:39:28.829").Replace("False", "True"); + var ourContent = commonAncestor.Replace("2011-02-02 19:39:28.829", "2012-02-02 19:39:28.829").Replace("False", "True"); + var theirContent = commonAncestor.Replace("2011-02-02 19:39:28.829", "2013-02-02 19:39:28.829").Replace("False", "True"); var results = FieldWorksTestServices.DoMerge( FileHandler, @@ -320,8 +320,8 @@ public void SampleMergeWithConflicts() Original Dictionary "); - var ourContent = commonAncestor.Replace("Original Dictionary", "My Dictionary").Replace("2011-2-2 19:39:28.829", "2012-2-2 19:39:28.829"); - var theirContent = commonAncestor.Replace("Original Dictionary", "Their Dictionary").Replace("2011-2-2 19:39:28.829", "2013-2-2 19:39:28.829"); + var ourContent = commonAncestor.Replace("Original Dictionary", "My Dictionary").Replace("2011-02-02 19:39:28.829", "2012-02-02 19:39:28.829"); + var theirContent = commonAncestor.Replace("Original Dictionary", "Their Dictionary").Replace("2011-02-02 19:39:28.829", "2013-02-02 19:39:28.829"); var results = FieldWorksTestServices.DoMerge( FileHandler, diff --git a/src/LibFLExBridge-ChorusPluginTests/Handling/PreferMostRecentTimePreMergerTests.cs b/src/LibFLExBridge-ChorusPluginTests/Handling/PreferMostRecentTimePreMergerTests.cs index 9d0a50cba..1672fd2b5 100644 --- a/src/LibFLExBridge-ChorusPluginTests/Handling/PreferMostRecentTimePreMergerTests.cs +++ b/src/LibFLExBridge-ChorusPluginTests/Handling/PreferMostRecentTimePreMergerTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2017 SIL International +// Copyright (c) 2017 SIL International // This software is licensed under the MIT License (http://opensource.org/licenses/MIT) using System.Xml; @@ -139,7 +139,7 @@ public void PreMerge_WithAncestorOnlyTimestampChange_KeepsTimestamp() var ours = CreateNode(CommonAncestor); _preMerger.Premerge(null, ref ours, theirs, ancestor); - Assert.That(GetDateTimeValue(ours), Is.EqualTo("2010-1-3 3:4:5.678")); + Assert.That(GetDateTimeValue(ours), Is.EqualTo("2010-01-03 03:04:05.678")); } [Test] diff --git a/src/LibFLExBridge-ChorusPluginTests/TestData/DataNotebook_Ann.ntbk b/src/LibFLExBridge-ChorusPluginTests/TestData/DataNotebook_Ann.ntbk index bb7056a31..905f20da7 100644 --- a/src/LibFLExBridge-ChorusPluginTests/TestData/DataNotebook_Ann.ntbk +++ b/src/LibFLExBridge-ChorusPluginTests/TestData/DataNotebook_Ann.ntbk @@ -4,9 +4,9 @@ + val="2012-05-11 20:30:59.450" /> + val="2012-05-11 21:25:40.965" /> Data Notebook @@ -23,9 +23,9 @@ t="r" /> + val="2012-05-11 21:25:40.964" /> + val="2012-05-11 21:25:55.978" /> @@ -50,7 +50,7 @@ + val="2012-05-11 21:20:21.980" /> + val="2012-05-11 21:20:21.80" /> + val="2012-05-11 21:25:40.965" /> diff --git a/src/LibFLExBridge-ChorusPluginTests/TestData/DataNotebook_Common.ntbk b/src/LibFLExBridge-ChorusPluginTests/TestData/DataNotebook_Common.ntbk index 2b23d6375..44730680b 100644 --- a/src/LibFLExBridge-ChorusPluginTests/TestData/DataNotebook_Common.ntbk +++ b/src/LibFLExBridge-ChorusPluginTests/TestData/DataNotebook_Common.ntbk @@ -4,9 +4,9 @@ + val="2012-05-11 20:30:59.450" /> + val="2012-05-11 21:25:40.965" /> Data Notebook @@ -23,9 +23,9 @@ t="r" /> + val="2012-05-11 21:25:40.964" /> + val="2012-05-11 21:25:55.978" /> @@ -50,7 +50,7 @@ + val="2012-05-11 21:20:21.980" /> + val="2012-05-11 21:20:21.80" /> + val="2012-05-11 21:25:40.965" /> diff --git a/src/LibFLExBridge-ChorusPluginTests/TestData/DataNotebook_Susanna.ntbk b/src/LibFLExBridge-ChorusPluginTests/TestData/DataNotebook_Susanna.ntbk index cfe06ddee..1c0a1379b 100644 --- a/src/LibFLExBridge-ChorusPluginTests/TestData/DataNotebook_Susanna.ntbk +++ b/src/LibFLExBridge-ChorusPluginTests/TestData/DataNotebook_Susanna.ntbk @@ -4,9 +4,9 @@ + val="2012-05-11 20:30:59.450" /> + val="2012-05-11 21:25:40.965" /> Data Notebook @@ -23,9 +23,9 @@ t="r" /> + val="2012-05-11 21:25:40.964" /> + val="2012-05-11 21:25:55.978" /> @@ -50,16 +50,16 @@ + val="2012-05-11 21:20:21.980" /> + val="2012-05-11 21:20:21.80" /> + val="2012-05-11 21:25:40.965" /> From bced352de8885f293b0c5e3826ffb66ab296c037 Mon Sep 17 00:00:00 2001 From: mark-sil Date: Tue, 9 Apr 2024 15:51:19 -0400 Subject: [PATCH 2/2] Fix build error: NU1605 : Warning As error : Detected package downgrade: SIL.Chorus.Mercurial from 6.5.1.25 to 6.5.1.22. Reference the package directly from the project to select a different version. --- .../LibFLExBridge-ChorusPluginTests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LibFLExBridge-ChorusPluginTests/LibFLExBridge-ChorusPluginTests.csproj b/src/LibFLExBridge-ChorusPluginTests/LibFLExBridge-ChorusPluginTests.csproj index e934f0be5..6f639b0c8 100644 --- a/src/LibFLExBridge-ChorusPluginTests/LibFLExBridge-ChorusPluginTests.csproj +++ b/src/LibFLExBridge-ChorusPluginTests/LibFLExBridge-ChorusPluginTests.csproj @@ -12,7 +12,7 @@ - +