Skip to content

Commit

Permalink
Adds support for an additional date format
Browse files Browse the repository at this point in the history
Temporarilly adds support for parsing dates from an additional date format.

We will remove this support when we eventually create a standardised file renaming tool.
  • Loading branch information
atruskie committed Jul 4, 2018
1 parent bbb3f40 commit 45728cd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
13 changes: 11 additions & 2 deletions src/Acoustics.Shared/FileDateHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class FileDateHelpers
new DateVariants(
@"^(.*)(?<date>(\d{4})(\d{2})(\d{2})(?<separator>T|-|_)(\d{2})(\d{2})(\d{2})(?![+-][\d:]{2,5}|Z)).*\.([a-zA-Z0-9]+)$",
AppConfigHelper.StandardDateFormatNoTimeZone,
false,
parseTimeZone: false,
AcceptedFormatsNoTimeZone),

// valid: prefix_20140101-235959+10.mp3, a_00000000-000000+00.a, a_99999999-999999+9999.dnsb48364JSFDSD
Expand All @@ -53,7 +53,16 @@ public class FileDateHelpers
new DateVariants(
@"^(.*)(?<date>(\d{4})(\d{2})(\d{2})(?<separator>T|-|_)(\d{2})(\d{2})(\d{2})(?![+-][:]{2,5})(?<offset>([+-](?!\d{0,5}:)(\d{4}|\d{2}))|Z)).*\.([a-zA-Z0-9]+)",
AppConfigHelper.StandardDateFormat,
true, AcceptedFormatsTimeZone),
parseTimeZone: true,
AcceptedFormatsTimeZone),

// temporary support for an alternate date format. We will remove support for this format. We're also not documenting support for this date format.
// valid: prefix_2359-01012015.mp3, a_2359-01012015.a, a_2359-01012015.dnsb48364JSFDSD
new DateVariants(
@"^(.*)(?<date>(\d{2})(\d{2})(?<separator>-)(\d{2})(\d{2})(\d{4})).*\.([a-zA-Z0-9]+)",
"HHmm-ddMMyyyy",
parseTimeZone: false,
Array.Empty<string>()),
};

private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
Expand Down
10 changes: 4 additions & 6 deletions tests/Acoustics.Test/FileDateHelpersTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ public void TestInvalidDateFormats()
}
}

//private static DateTimeOffset Parse(string date) => DateTimeOffset.Parse(date);

private Dictionary<string, DateTimeOffset> validFormats = new Dictionary<string, DateTimeOffset>
{
["sdncv*_-T&^%34jd_20140301_085031+0630blah_T-suffix.mp3"] = Parse("2014-03-01T08:50:31.000+06:30"),
Expand All @@ -116,7 +114,6 @@ public void TestValidDateFormats()
FileDateHelpers.FileNameContainsDateTime(example.Key, out parsedDate),
$"Testing format: {example}");


Assert.AreEqual(example.Value, parsedDate);
}
}
Expand All @@ -131,6 +128,10 @@ public void TestValidDateFormats()
["SERF_20130314_000021_000.wav"] = Parse("2013-03-14T00:00:21.000+06:30"),
["20150727T133138.wav"] = Parse("2015-07-27T13:31:38.000+06:30"),
["20150801-064555.wav"] = Parse("2015-08-01T06:45:55.000+06:30"),

// Temporary support for another date format
["0645-01082015.wav"] = Parse("2015-08-01T06:45:00.000+06:30"),
["test_0645-01082015_test.wav"] = Parse("2015-08-01T06:45:00.000+06:30"),
};

[TestMethod]
Expand All @@ -147,12 +148,10 @@ public void TestValidDateFormatsWithOffsetHint()
offsetHint: new TimeSpan(6, 30, 0)),
$"Testing format: {example}");


Assert.AreEqual(example.Value, parsedDate);
}
}


private readonly string[] unorderedFiles = new[]
{
@"Y:\2015Sept20\Woondum3\20150919_201742Z.wav", @"Y:\2015Sept20\Woondum3\20150920_000006Z.wav",
Expand All @@ -168,7 +167,6 @@ public void TestValidDateFormatsWithOffsetHint()
@"Y:\2015Sept20\Woondum3\20150918-133146+1130.wav", @"Y:\2015Sept20\Woondum3\20150918_201738.wav",
};


private DateTimeOffset[] orderedDates = new[]
{
Parse("2014-03-01T08:50:31.000+06:30"), Parse("2014-03-01T08:50:31.000+06:30"),
Expand Down

0 comments on commit 45728cd

Please sign in to comment.