2
0
Fork 0
mirror of https://github.com/sphildreth/roadie synced 2025-02-19 06:28:27 +00:00

Beta v20180202.1

This commit is contained in:
Steven Hildreth 2019-02-02 21:26:25 -06:00
parent 192a57baa4
commit f8df3af90d
3 changed files with 38 additions and 5 deletions
Roadie.Api.Library.Tests
Roadie.Api.Library

View file

@ -56,18 +56,39 @@ namespace Roadie.Library.Tests
}
[Theory]
[InlineData("02-22-88")]
[InlineData("02/22/1988")]
[InlineData("02/22/88")]
[InlineData("2004")]
[InlineData("02-22-1988")]
[InlineData("02-22-88")]
[InlineData("04/1988")]
[InlineData("04//1988")]
[InlineData("04///1988")]
[InlineData("04-1988")]
[InlineData("04\\1988")]
[InlineData("04\\\\1988")]
[InlineData("1988")]
[InlineData("1988/05")]
[InlineData("1988/05/02")]
[InlineData("88")]
[InlineData("04/2015")]
[InlineData("2015/05")]
public void Parse_Datetime(string input)
public void Parse_Datetime_ShouldBe1988(string input)
{
var parsed = SafeParser.ToDateTime(input);
Assert.NotNull(parsed);
Assert.Equal(1988, parsed.Value.Year);
}
[Theory]
[InlineData("2004//2004")]
[InlineData("2004////2004")]
[InlineData("2004\\2004")]
[InlineData("2004\\\\2004")]
public void Parse_Datetime_ShouldBe2004(string input)
{
var parsed = SafeParser.ToDateTime(input);
Assert.NotNull(parsed);
}
[Theory]
[InlineData("DEB4F298-5D22-4304-916E-F130B02864B7")]
[InlineData("12d65c61-1b7d-4c43-9aab-7d398a1a880e")]

View file

@ -20,6 +20,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.1" />
<PackageReference Include="Microsoft.Extensions.Caching.Redis" Version="2.2.0" />
<PackageReference Include="MimeMapping" Version="1.0.1.12" />
<PackageReference Include="NodaTime" Version="2.4.4" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.1.4" />
<PackageReference Include="RestSharp" Version="106.6.7" />
<PackageReference Include="SixLabors.Core" Version="1.0.0-beta0006" />

View file

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace Roadie.Library.Utility
{
@ -90,8 +91,17 @@ namespace Roadie.Library.Utility
var i = input as string ?? input.ToString();
if (!string.IsNullOrEmpty(i))
{
i = Regex.Replace(i, @"(\\)", "/");
i = Regex.Replace(i, @"(\/+)", "/");
i.Replace("-", "/");
var parts = i.Contains("/") ? i.Split('/').ToList() : new List<string> { i };
if(parts.Count == 2)
{
if(parts[0] != null && parts[1] != null && parts[0] == parts[1])
{
parts = new List<string>(new string[2] { parts[0], "01" });
}
}
while (parts.Count() < 3)
{
parts.Insert(0, "01");
@ -106,6 +116,7 @@ namespace Roadie.Library.Utility
tsRaw += part;
}
DateTime.TryParse(tsRaw, out dt);
}
try
{