Skip to content

Commit

Permalink
修改 时间转化
Browse files Browse the repository at this point in the history
  • Loading branch information
toolgood committed Sep 14, 2023
1 parent 29e0c52 commit 3a8a4fb
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,31 @@ public void Add_test()
dt = engine.TryEvaluate("'2000-02-01 12:05:06'.AddSeconds(1).Second()", 0);
Assert.AreEqual(dt, 7);

dt = engine.TryEvaluate("'2000-02-01 10:05:06'.AddSeconds(1).Second()", 0);
Assert.AreEqual(dt, 7);

dt = engine.TryEvaluate("'2000-02-01 20:05:06'.AddSeconds(1).Second()", 0);
Assert.AreEqual(dt, 7);

dt = engine.TryEvaluate("'2000-02-01 9:05:06'.AddSeconds(1).Second()", 0);
Assert.AreEqual(dt, 7);

dt = engine.TryEvaluate("'7:05:06'.AddSeconds(1).Second()", 0);
Assert.AreEqual(dt, 7);

dt = engine.TryEvaluate("'10:05:06'.AddSeconds(1).Second()", 0);
Assert.AreEqual(dt, 7);

dt = engine.TryEvaluate("'20:05:06'.AddSeconds(1).Second()", 0);
Assert.AreEqual(dt, 7);

// 错误
dt = engine.TryEvaluate("'2000-02-01 24:05:06'.AddSeconds(1).Second()", 0);
Assert.AreEqual(dt, 0);

//
//dt = engine.TryEvaluate("'24:05:06'.AddSeconds(1).Second()", 0);
//Assert.AreEqual(dt, 0);
}

}
Expand Down
12 changes: 6 additions & 6 deletions csharp/ToolGood.Algorithm2/MyDate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public static MyDate Parse(String txt)
{
CultureInfo cultureInfo = CultureInfo.GetCultureInfo("en-US");
String t = txt.Trim();
var m = Regex.Match(t, "^(\\d{4})-(10|11|12|0?\\d)-(30|31|[012]?\\d) ([01]\\d?|2[1234]):([012345]?\\d):([012345]?\\d)$", RegexOptions.Compiled);
var m = Regex.Match(t, "^(\\d{4})-(1[012]|0?\\d)-(30|31|[012]?\\d) ([01]?\\d|2[0123]):([012345]?\\d):([012345]?\\d)$", RegexOptions.Compiled);
if (m.Success) {
MyDate date = new MyDate();
date.Year = int.Parse(m.Groups[(1)].Value, cultureInfo);
Expand All @@ -130,7 +130,7 @@ public static MyDate Parse(String txt)
date.Second = int.Parse(m.Groups[(6)].Value, cultureInfo);
return date;
}
m = Regex.Match(t, "^(\\d{4})-(10|11|12|0?\\d)-(30|31|[012]?\\d) ([01]\\d?|2[1234]):([012345]?\\d)$", RegexOptions.Compiled);
m = Regex.Match(t, "^(\\d{4})-(1[012]|0?\\d)-(30|31|[012]?\\d) ([01]?\\d|2[0123]):([012345]?\\d)$", RegexOptions.Compiled);
if (m.Success) {
MyDate date = new MyDate();
date.Year = int.Parse(m.Groups[(1)].Value, cultureInfo);
Expand All @@ -140,15 +140,15 @@ public static MyDate Parse(String txt)
date.Minute = int.Parse(m.Groups[(5)].Value, cultureInfo);
return date;
}
m = Regex.Match(t, "^(\\d{4})-(10|11|12|0?\\d)-(30|31|[012]?\\d)$");
m = Regex.Match(t, "^(\\d{4})-(1[012]|0?\\d)-(30|31|[012]?\\d)$");
if (m.Success) {
MyDate date = new MyDate();
date.Year = int.Parse(m.Groups[(1)].Value, cultureInfo);
date.Month = int.Parse(m.Groups[(2)].Value, cultureInfo);
date.Day = int.Parse(m.Groups[(3)].Value, cultureInfo);
return date;
}
m = Regex.Match(t, "^(\\d+) (2[1234]|[01]?\\d):([012345]?\\d):([012345]?\\d)$", RegexOptions.Compiled);
m = Regex.Match(t, "^(\\d+) (2[0123]|[01]?\\d):([012345]?\\d):([012345]?\\d)$", RegexOptions.Compiled);
if (m.Success) {
MyDate date = new MyDate();
date.Day = int.Parse(m.Groups[(1)].Value, cultureInfo);
Expand All @@ -157,15 +157,15 @@ public static MyDate Parse(String txt)
date.Second = int.Parse(m.Groups[(4)].Value, cultureInfo);
return date;
}
m = Regex.Match(t, "^(2[1234]|[01]?\\d):([012345]?\\d):([012345]?\\d)$", RegexOptions.Compiled);
m = Regex.Match(t, "^(2[0123]|[01]?\\d):([012345]?\\d):([012345]?\\d)$", RegexOptions.Compiled);
if (m.Success) {
MyDate date = new MyDate();
date.Hour = int.Parse(m.Groups[(1)].Value, cultureInfo);
date.Minute = int.Parse(m.Groups[(2)].Value, cultureInfo);
date.Second = int.Parse(m.Groups[(3)].Value, cultureInfo);
return date;
}
m = Regex.Match(t, "^(2[1234]|[01]?\\d):([012345]?\\d)$", RegexOptions.Compiled);
m = Regex.Match(t, "^(2[0123]|[01]?\\d):([012345]?\\d)$", RegexOptions.Compiled);
if (m.Success) {
MyDate date = new MyDate();
date.Hour = int.Parse(m.Groups[(1)].Value, cultureInfo);
Expand Down
2 changes: 1 addition & 1 deletion csharp/ToolGood.Algorithm2/ToolGood.Algorithm2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<Product>ToolGood.Algorithm</Product>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<SignAssembly>true</SignAssembly>
<Version>3.4.1.2</Version>
<Version>3.4.1.3</Version>
<AssemblyOriginatorKeyFile>ToolGood.Algorithm.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\ToolGood.Algorithm.xml</DocumentationFile>
Expand Down
2 changes: 1 addition & 1 deletion java/toolgood.algorithm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.github.toolgood</groupId>
<artifactId>toolgood-algorithm</artifactId>
<version>3.4.1.2</version>
<version>3.4.1.3</version>
<packaging>jar</packaging>

<name>toolgood.algorithm</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public MyDate(double num) {
public static MyDate parse(String txt) {
String t = txt.trim();
Matcher m = Pattern
.compile("^(\\d{4})-(10|11|12|0?\\d)-(30|31|[012]?\\d) ([01]\\d?|2[1234]):([012345]?\\d):([012345]?\\d)$")
.compile("^(\\d{4})-(1[012]|0?\\d)-(30|31|[012]?\\d) ([01]?\\d|2[0123]):([012345]?\\d):([012345]?\\d)$")
.matcher(t);
if (m.find()) {
MyDate date = new MyDate();
Expand All @@ -125,7 +125,7 @@ public static MyDate parse(String txt) {
date.Second = Integer.parseInt(m.group(6));
return date;
}
m = Pattern.compile("(\\d{4})-(10|11|12|0?\\d)-(30|31|[012]?\\d) ([01]\\d?|2[1234]):([012345]?\\d)").matcher(t);
m = Pattern.compile("(\\d{4})-(1[012]|0?\\d)-(30|31|[012]?\\d) ([01]?\\d|2[0123]):([012345]?\\d)").matcher(t);
if (m.find()) {
MyDate date = new MyDate();
date.Year = Integer.parseInt(m.group(1));
Expand All @@ -135,15 +135,15 @@ public static MyDate parse(String txt) {
date.Minute = Integer.parseInt(m.group(5));
return date;
}
m = Pattern.compile("(\\d{4})-(10|11|12|0?\\d)-(30|31|[012]?\\d)").matcher(t);
m = Pattern.compile("(\\d{4})-(1[012]|0?\\d)-(30|31|[012]?\\d)").matcher(t);
if (m.find()) {
MyDate date = new MyDate();
date.Year = Integer.parseInt(m.group(1));
date.Month = Integer.parseInt(m.group(2));
date.Day = Integer.parseInt(m.group(3));
return date;
}
m = Pattern.compile("^(\\d+) (2[1234]|[01]?\\d):([012345]?\\d):([012345]?\\d)$").matcher(t);
m = Pattern.compile("^(\\d+) (2[0123]|[01]?\\d):([012345]?\\d):([012345]?\\d)$").matcher(t);
if (m.find()) {
MyDate date = new MyDate();
date.Day = Integer.parseInt(m.group(1));
Expand All @@ -152,15 +152,15 @@ public static MyDate parse(String txt) {
date.Second = Integer.parseInt(m.group(4));
return date;
}
m = Pattern.compile("^(2[1234]|[01]?\\d):([012345]?\\d):([012345]?\\d)$").matcher(t);
m = Pattern.compile("^(2[0123]|[01]?\\d):([012345]?\\d):([012345]?\\d)$").matcher(t);
if (m.find()) {
MyDate date = new MyDate();
date.Hour = Integer.parseInt(m.group(1));
date.Minute = Integer.parseInt(m.group(2));
date.Second = Integer.parseInt(m.group(3));
return date;
}
m = Pattern.compile("^(2[1234]|[01]?\\d):([012345]?\\d)$").matcher(t);
m = Pattern.compile("^(2[0123]|[01]?\\d):([012345]?\\d)$").matcher(t);
if (m.find()) {
MyDate date = new MyDate();
date.Hour = Integer.parseInt(m.group(1));
Expand Down

0 comments on commit 3a8a4fb

Please sign in to comment.