Created
September 23, 2019 11:52
-
-
Save almirus/94a0c997fada82e2a0c173c476f118da to your computer and use it in GitHub Desktop.
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
/** | |
* Преобразование Oracle строки с интервалов в строку со временем в формате ISO-8601 (для java класса Duration) | |
* @param oracleInterval строка в формате +83 18:47:29.000000, которую возвращает функция NUMTODSINTERVAL | |
* @return строка в формате ISO-8601 | |
*/ | |
private String getDurationISO8601(String oracleInterval){ | |
String result=null; | |
if (oracleInterval!=null){ | |
Pattern regex = Pattern.compile("([+-])?(\\d+)\\s(\\d+):(\\d+):(\\d+)\\.\\d+"); | |
Matcher regexMatcher = regex.matcher(oracleInterval); | |
if (regexMatcher.matches()) { | |
//+83 18:47:29.000000 -> +P83DT18H47M29S (ISO-8601) | |
result = (regexMatcher.group(1)!=null ? regexMatcher.group(1) : ""); // знак | |
result = result.concat("P").concat(regexMatcher.group(2)).concat("DT") // дней | |
.concat(regexMatcher.group(3)).concat("H").concat(regexMatcher.group(4)).concat("M") // часы минуты | |
.concat(regexMatcher.group(5)).concat("S"); // секунды | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment