Skip to content

Commit

Permalink
Merge pull request #850 from gbirchmeier/nanofix
Browse files Browse the repository at this point in the history
fix nanosecond-parsing bug #842, plus refactor DateTimeConverter and clean up its tests
  • Loading branch information
gbirchmeier authored May 20, 2024
2 parents 3200a30 + c9ce826 commit 9f4a9b5
Show file tree
Hide file tree
Showing 16 changed files with 576 additions and 772 deletions.
6 changes: 3 additions & 3 deletions QuickFIXn/DataDictionary/DataDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,11 @@ public void CheckValidFormat(Fields.IField field)
Fields.Converters.BoolConverter.Convert(field.ToString());

else if (type == typeof(DateTimeField))
Fields.Converters.DateTimeConverter.ConvertToDateTime(field.ToString());
Fields.Converters.DateTimeConverter.ParseToDateTime(field.ToString());
else if (type == typeof(DateOnlyField))
Fields.Converters.DateTimeConverter.ConvertToDateOnly(field.ToString());
Fields.Converters.DateTimeConverter.ParseToDateOnly(field.ToString());
else if (type == typeof(TimeOnlyField))
Fields.Converters.DateTimeConverter.ConvertToTimeOnly(field.ToString());
Fields.Converters.DateTimeConverter.ParseToTimeOnly(field.ToString());
return;

}
Expand Down
476 changes: 228 additions & 248 deletions QuickFIXn/Fields/Converters/DateTimeConverter.cs

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions QuickFIXn/Fields/Converters/TimeStampPrecision.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@

namespace QuickFix.Fields.Converters
{
/// <summary>
/// Enumerator to specify what precision times should be converted to
/// </summary>
public enum TimeStampPrecision
{
Second,
Expand Down
8 changes: 4 additions & 4 deletions QuickFIXn/Fields/DateTimeField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void setValue(DateTime dt)

protected override string makeString()
{
return Converters.DateTimeConverter.Convert(Obj, timePrecision);
return Converters.DateTimeConverter.ToFIX(Obj, timePrecision);
}
}

Expand All @@ -47,11 +47,11 @@ public DateOnlyField(int tag, DateTime dt, bool showMilliseconds)
: base(tag, dt, showMilliseconds) { }

public DateOnlyField(int tag, DateTime dt, TimeStampPrecision timeFormatPrecision)
: base(tag, dt, timeFormatPrecision) { }
: base(tag, dt, timeFormatPrecision) { }

protected override string makeString()
{
return Converters.DateTimeConverter.ConvertDateOnly(Obj);
return Converters.DateTimeConverter.ToFIXDateOnly(Obj);
}
}

Expand All @@ -71,7 +71,7 @@ public TimeOnlyField(int tag, DateTime dt, TimeStampPrecision timeFormatPrecisio

protected override string makeString()
{
return Converters.DateTimeConverter.ConvertTimeOnly(Obj, base.timePrecision);
return Converters.DateTimeConverter.ToFIXTimeOnly(Obj, base.timePrecision);
}
}
}
7 changes: 4 additions & 3 deletions QuickFIXn/Logger/FileLog.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#nullable enable
using System;
using QuickFix.Fields.Converters;
using QuickFix.Util;

namespace QuickFix.Logger;
Expand Down Expand Up @@ -95,7 +96,7 @@ public void OnIncoming(string msg)

lock (_sync)
{
_messageLog.WriteLine(Fields.Converters.DateTimeConverter.Convert(DateTime.UtcNow) + " : " + msg);
_messageLog.WriteLine(DateTimeConverter.ToFIX(DateTime.UtcNow, TimeStampPrecision.Millisecond) + " : " + msg);
}
}

Expand All @@ -105,7 +106,7 @@ public void OnOutgoing(string msg)

lock (_sync)
{
_messageLog.WriteLine(Fields.Converters.DateTimeConverter.Convert(DateTime.UtcNow) + " : " + msg);
_messageLog.WriteLine(DateTimeConverter.ToFIX(DateTime.UtcNow, TimeStampPrecision.Millisecond) + " : " + msg);
}
}

Expand All @@ -115,7 +116,7 @@ public void OnEvent(string s)

lock (_sync)
{
_eventLog.WriteLine(Fields.Converters.DateTimeConverter.Convert(DateTime.UtcNow) + " : "+ s);
_eventLog.WriteLine(DateTimeConverter.ToFIX(DateTime.UtcNow, TimeStampPrecision.Millisecond) + " : " + s);
}
}

Expand Down
6 changes: 3 additions & 3 deletions QuickFIXn/Message/FieldMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ public DateTime GetDateTime(int tag)
DateOnlyField dateOnlyField => dateOnlyField.Obj.Date,
TimeOnlyField timeOnlyField => new DateTime(1980, 01, 01).Add(timeOnlyField.Obj.TimeOfDay),
FieldBase<DateTime> dateTimeField => dateTimeField.Obj,
_ => DateTimeConverter.ConvertToDateTime(fld.ToString())
_ => DateTimeConverter.ParseToDateTime(fld.ToString())
};
}

Expand All @@ -378,7 +378,7 @@ public DateTime GetDateOnly(int tag)
if (fld is FieldBase<DateTime> dateTimeField)
return dateTimeField.Obj.Date;

return DateTimeConverter.ConvertToDateOnly(fld.ToString());
return DateTimeConverter.ParseToDateOnly(fld.ToString());
}

/// <summary>
Expand All @@ -395,7 +395,7 @@ public DateTime GetTimeOnly(int tag)
if (fld is FieldBase<DateTime> dateTimeField)
return new DateTime(1980, 01, 01).Add(dateTimeField.Obj.TimeOfDay);

return DateTimeConverter.ConvertToTimeOnly(fld.ToString());
return DateTimeConverter.ParseToTimeOnly(fld.ToString());
}

/// <summary>
Expand Down
4 changes: 3 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ What's New
ByteSizeString is public, but probably no one uses it
* #822 - cleanup/nullable-ize Message/ classes (gbirchmeier)
* FieldMap: getFieldOrder() deleted. Just call FieldOrder.
* FieldMap: GetGroup(int num, Group group) now returns null instead of redundant Group
* FieldMap: GetGroup(int num, Group group) now returns void instead of redundant Group
* Group: rename Field to CounterField
* Message: changed `SOH`'s type from string to char
* Message: ctor Message(string msgstr, DataDictionary.DataDictionary dataDictionary, bool validate) deleted.
Expand Down Expand Up @@ -56,6 +56,8 @@ What's New
* privatize a ctor that takes a generic Dict; apps shouldn't use it
* remove the copy ctor that takes only a SessionDict; replace it with one
that explicitly requires a name also
* #842 - Fix nano-datetime-to-string bug (gbirchmeier)
* Also refactor the heck out of DateTimeConverter & tests: many functions renamed/deprecated

**Non-breaking changes**
* #400 - added DDTool, a C#-based codegen, and deleted Ruby-based generator (gbirchmeier)
Expand Down
191 changes: 0 additions & 191 deletions UnitTests/ConverterTests.cs

This file was deleted.

5 changes: 3 additions & 2 deletions UnitTests/FieldTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using NUnit.Framework;
using QuickFix.Fields;
using UnitTests.TestHelpers;

namespace UnitTests
{
Expand Down Expand Up @@ -90,8 +91,8 @@ public void DateTimeFieldTest()
[Test]
public void DateTimeFieldNanoTest()
{
DateTime val = ConverterTests.makeDateTime(2009, 9, 4, 3, 44, 1, 100, 310, 300);
DateTime newval = ConverterTests.makeDateTime(2009, 9, 4, 3, 44, 1, 100, 310, 300);
DateTime val = TimeHelper.MakeDateTime(2009, 9, 4, 3, 44, 1, 100, 310, 300);
DateTime newval = TimeHelper.MakeDateTime(2009, 9, 4, 3, 44, 1, 100, 310, 300);
DateTimeField field = new DateTimeField(200, val, QuickFix.Fields.Converters.TimeStampPrecision.Nanosecond);
Assert.That(field.Obj, Is.EqualTo(val));
Assert.That(field.getValue(), Is.EqualTo(val));
Expand Down
20 changes: 20 additions & 0 deletions UnitTests/Fields/Converters/BoolConverterTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using NUnit.Framework;
using QuickFix;
using QuickFix.Fields.Converters;

namespace UnitTests.Fields.Converters;

[TestFixture]
public class BoolConverterTests {

[Test]
public void Convert()
{
Assert.That(BoolConverter.Convert("Y"), Is.EqualTo(true));
Assert.That(BoolConverter.Convert("N"), Is.EqualTo(false));
Assert.That(BoolConverter.Convert(true), Is.EqualTo("Y"));
Assert.That(BoolConverter.Convert(false), Is.EqualTo("N"));
Assert.Throws(typeof(FieldConvertError),
delegate { BoolConverter.Convert("Z"); });
}
}
18 changes: 18 additions & 0 deletions UnitTests/Fields/Converters/CharConverterTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using NUnit.Framework;
using QuickFix;
using QuickFix.Fields.Converters;

namespace UnitTests.Fields.Converters;

[TestFixture]
public class CharConverterTests {

[Test]
public void Convert()
{
Assert.That(CharConverter.Convert('A'), Is.EqualTo("A"));
Assert.That(CharConverter.Convert("B"), Is.EqualTo('B'));
Assert.Throws(typeof(FieldConvertError),
delegate { CharConverter.Convert("AB"); });
}
}
Loading

0 comments on commit 9f4a9b5

Please sign in to comment.