Skip to content

Commit

Permalink
Fixed AM/PM (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
picrap committed Aug 20, 2017
1 parent 262ed66 commit 69d95f8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
Binary file added .vs/ArxOne.Ftp/v15/sqlite3/storage.ide
Binary file not shown.
14 changes: 11 additions & 3 deletions ArxOne.Ftp/Platform/FtpPlatform.cs
Expand Up @@ -78,7 +78,8 @@ public virtual FtpEntry Parse(string directoryLine, FtpPath parent)
protected static DateTime ParseDateTime(Match match, DateTime now)
{
return ParseDateTime(match.Groups["year"].Value, match.Groups["month"].Value, match.Groups["day"].Value,
match.Groups["hour"].Value, match.Groups["minute"].Value, match.Groups["pm"].Value, now);
match.Groups["hour"].Value, match.Groups["minute"].Value, match.Groups["am"].Value, match.Groups["pm"].Value,
now);
}


Expand All @@ -90,11 +91,12 @@ protected static DateTime ParseDateTime(Match match, DateTime now)
/// <param name="literalDay">The literal day.</param>
/// <param name="literalHour">The literal hour.</param>
/// <param name="literalMinute">The literal minute.</param>
/// <param name="am">The am.</param>
/// <param name="pm">PM.</param>
/// <param name="now">The now.</param>
/// <returns></returns>
private static DateTime ParseDateTime(string literalYear, string literalMonth, string literalDay,
string literalHour, string literalMinute, string pm, DateTime now)
string literalHour, string literalMinute, string am, string pm, DateTime now)
{
var month = ParseMonth(literalMonth);
var day = int.Parse(literalDay);
Expand All @@ -119,6 +121,12 @@ protected static DateTime ParseDateTime(Match match, DateTime now)
if (hour < 12) // because 12PM is 12 so 12 stays 12
hour += 12;
}
else if (!string.IsNullOrEmpty(am))
{
// 12AM is 0
if (hour == 12)
hour = 0;
}
var minute = string.IsNullOrEmpty(literalMinute) ? 0 : int.Parse(literalMinute);
return new DateTime(year, month, day, hour, minute, 0, DateTimeKind.Local);
}
Expand Down Expand Up @@ -148,7 +156,7 @@ public virtual string EscapePath(string path)
{
return path;
}

/// <summary>
/// Escapes the path.
/// Provided at this level for convenience
Expand Down
14 changes: 14 additions & 0 deletions ArxOne.FtpTest/ListParseTest.cs
Expand Up @@ -64,6 +64,7 @@ public void ParseWindowsTest()
{
var entry = WindowsFtpPlatform.ParseLine(" 03-07-15 03:52PM 22286 03265480-photo-logo.png", null);
Assert.IsNotNull(entry);
Assert.AreEqual(15, entry.Date.Hour);
Assert.AreEqual(FtpEntryType.File, entry.Type);
Assert.AreEqual("03265480-photo-logo.png", entry.Name);
}
Expand All @@ -75,6 +76,19 @@ public void ParseWindows2Test()
{
var entry = WindowsFtpPlatform.ParseLine(" 04-04-15 12:12PM <DIR> New folder", null);
Assert.IsNotNull(entry);
Assert.AreEqual(12, entry.Date.Hour);
Assert.AreEqual(FtpEntryType.Directory, entry.Type);
Assert.AreEqual("New folder", entry.Name);
}

[TestMethod]
[TestCategory("Parsing")]
[TestProperty("OS", "Windows")]
public void ParseWindowsAmTest()
{
var entry = WindowsFtpPlatform.ParseLine(" 04-04-15 12:12AM <DIR> New folder", null);
Assert.IsNotNull(entry);
Assert.AreEqual(0, entry.Date.Hour);
Assert.AreEqual(FtpEntryType.Directory, entry.Type);
Assert.AreEqual("New folder", entry.Name);
}
Expand Down

0 comments on commit 69d95f8

Please sign in to comment.