-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fix assertions and max retry (#59)
Co-authored-by: Romuald Rousseau <[email protected]>
- Loading branch information
1 parent
a6faee4
commit 201ea8b
Showing
4 changed files
with
74 additions
and
68 deletions.
There are no files selected for viewing
137 changes: 71 additions & 66 deletions
137
...c/main/java/com/github/romualdrousseau/archery/commons/python/PythonSimpleDateFormat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,95 @@ | ||
package com.github.romualdrousseau.archery.commons.python; | ||
|
||
import java.text.SimpleDateFormat; | ||
import java.util.Calendar; | ||
import java.util.Locale; | ||
|
||
public class PythonSimpleDateFormat extends SimpleDateFormat { | ||
|
||
private final String pythonPattern; | ||
private final Locale locale; | ||
|
||
public PythonSimpleDateFormat() { | ||
this("", Locale.US); | ||
public PythonSimpleDateFormat(final String pythonPattern) { | ||
this(pythonPattern, Locale.getDefault()); | ||
} | ||
|
||
public PythonSimpleDateFormat(final String pattern) { | ||
this(pattern, PythonSimpleDateFormat.toJavaLocale(pattern)); | ||
} | ||
|
||
public PythonSimpleDateFormat(final String pattern, Locale locale) { | ||
super(PythonSimpleDateFormat.toJava(pattern), locale); | ||
public PythonSimpleDateFormat(final String pythonPattern, Locale locale) { | ||
super(PythonSimpleDateFormat.toJavaPattern(pythonPattern), locale); | ||
this.pythonPattern = pythonPattern; | ||
this.locale = locale; | ||
} | ||
|
||
public static String toPython(final String javaPattern) { | ||
return javaPattern | ||
.replaceAll("YYYY", "%G") | ||
.replaceAll("yyyy", "%Y") | ||
.replaceAll("yy", "%y") | ||
.replaceAll("y", "%-y") | ||
.replaceAll("MMMMM", "%B") | ||
.replaceAll("MMM", "%b") | ||
.replaceAll("MM", "%m") | ||
.replaceAll("M", "%-m") | ||
.replaceAll("DDD", "%j") | ||
.replaceAll("dd", "%d") | ||
.replaceAll("d", "%-d") | ||
.replaceAll("EEEEE", "%A") | ||
.replaceAll("EEE", "%a") | ||
.replaceAll("ww", "%W") | ||
.replaceAll("u", "%u") | ||
.replaceAll("HH", "%H") | ||
.replaceAll("H", "%-H") | ||
.replaceAll("hh", "%I") | ||
.replaceAll("h", "%-I") | ||
.replaceAll("mm", "%M") | ||
.replaceAll("m", "%-M") | ||
.replaceAll("ss", "%S") | ||
.replaceAll("s", "%-S"); | ||
public String getPythonPattern() { | ||
return this.pythonPattern; | ||
} | ||
|
||
public static String toJava(final String pythonPattern) { | ||
return pythonPattern | ||
.replaceAll("%G", "YYYY") | ||
.replaceAll("%Y", "yyyy") | ||
.replaceAll("%y", "yy") | ||
.replaceAll("%-y", "y") | ||
.replaceAll("%B", "MMMMM") | ||
.replaceAll("%b", "MMM") | ||
.replaceAll("%m", "MM") | ||
.replaceAll("%-m", "M") | ||
.replaceAll("%j", "DDD") | ||
.replaceAll("%d", "dd") | ||
.replaceAll("%-d", "d") | ||
.replaceAll("%A", "EEEEE") | ||
.replaceAll("%a", "EEE") | ||
.replaceAll("%W", "ww") | ||
.replaceAll("%w", "u") | ||
.replaceAll("%u", "u") | ||
.replaceAll("%U", "ww") | ||
.replaceAll("%H", "HH") | ||
.replaceAll("%-H", "H") | ||
.replaceAll("%I", "hh") | ||
.replaceAll("%-I", "h") | ||
.replaceAll("%M", "mm") | ||
.replaceAll("%-M", "m") | ||
.replaceAll("%S", "ss") | ||
.replaceAll("%-S", "s"); | ||
public Locale getLocale() { | ||
return this.locale; | ||
} | ||
|
||
public static Locale toJavaLocale(final String pythonPattern) { | ||
if (pythonPattern.contains("%w") || pythonPattern.contains("%W")) { | ||
return Locale.UK; | ||
public int getFirstDayOfWeek() { | ||
if (this.pythonPattern.contains("%w") || this.pythonPattern.contains("%W")) { | ||
return Calendar.MONDAY; | ||
} else if (this.pythonPattern.contains("%u") || this.pythonPattern.contains("%U")) { | ||
return Calendar.SUNDAY; | ||
} else { | ||
return Locale.US; | ||
return -1; | ||
} | ||
} | ||
|
||
public Locale getLocale() { | ||
return this.locale; | ||
public static String toPythonPattern(final String javaPattern) { | ||
return javaPattern | ||
.replaceAll("YYYY", "%G") | ||
.replaceAll("yyyy", "%Y") | ||
.replaceAll("yy", "%y") | ||
.replaceAll("y", "%-y") | ||
.replaceAll("MMMMM", "%B") | ||
.replaceAll("MMM", "%b") | ||
.replaceAll("MM", "%m") | ||
.replaceAll("M", "%-m") | ||
.replaceAll("DDD", "%j") | ||
.replaceAll("dd", "%d") | ||
.replaceAll("d", "%-d") | ||
.replaceAll("EEEEE", "%A") | ||
.replaceAll("EEE", "%a") | ||
.replaceAll("ww", "%W") | ||
.replaceAll("u", "%u") | ||
.replaceAll("HH", "%H") | ||
.replaceAll("H", "%-H") | ||
.replaceAll("hh", "%I") | ||
.replaceAll("h", "%-I") | ||
.replaceAll("mm", "%M") | ||
.replaceAll("m", "%-M") | ||
.replaceAll("ss", "%S") | ||
.replaceAll("s", "%-S"); | ||
} | ||
|
||
public static String toJavaPattern(final String pythonPattern) { | ||
return pythonPattern | ||
.replaceAll("%G", "YYYY") | ||
.replaceAll("%Y", "yyyy") | ||
.replaceAll("%y", "yy") | ||
.replaceAll("%-y", "y") | ||
.replaceAll("%B", "MMMMM") | ||
.replaceAll("%b", "MMM") | ||
.replaceAll("%m", "MM") | ||
.replaceAll("%-m", "M") | ||
.replaceAll("%j", "DDD") | ||
.replaceAll("%d", "dd") | ||
.replaceAll("%-d", "d") | ||
.replaceAll("%A", "EEEEE") | ||
.replaceAll("%a", "EEE") | ||
.replaceAll("%W", "ww") | ||
.replaceAll("%w", "u") | ||
.replaceAll("%u", "u") | ||
.replaceAll("%U", "ww") | ||
.replaceAll("%H", "HH") | ||
.replaceAll("%-H", "H") | ||
.replaceAll("%I", "hh") | ||
.replaceAll("%-I", "h") | ||
.replaceAll("%M", "mm") | ||
.replaceAll("%-M", "m") | ||
.replaceAll("%S", "ss") | ||
.replaceAll("%-S", "s"); | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters