Skip to content

Instantly share code, notes, and snippets.

@almirus
Created September 23, 2019 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save almirus/94a0c997fada82e2a0c173c476f118da to your computer and use it in GitHub Desktop.
Save almirus/94a0c997fada82e2a0c173c476f118da to your computer and use it in GitHub Desktop.
/**
* Преобразование 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