/**
* String to period.
*
* @param s the s
* @return the period
* @throws MotuConverterException the motu converter exception
*/
public static Period stringToPeriod(String s) throws MotuConverterException {
if (LOG.isDebugEnabled()) {
LOG.debug("stringToPeriod(String) - entering");
}
Period period = null;
StringBuffer stringBuffer = new StringBuffer();
for (PeriodFormatter periodFormatter : DateUtils.PERIOD_FORMATTERS.values()) {
try {
period = periodFormatter.parsePeriod(s);
} catch (IllegalArgumentException e) {
// LOG.error("stringToPeriod(String)", e);
stringBuffer.append(e.getMessage());
stringBuffer.append("\n");
}
if (period != null) {
break;
}
}
if (period == null) {
throw new MotuConverterException(
String.format("Cannot convert '%s' to Period. Format '%s' is not valid.\nAcceptable format are '%s'",
s,
stringBuffer.toString(),
DateUtils.PERIOD_FORMATTERS.keySet().toString()));
}
if (LOG.isDebugEnabled()) {
LOG.debug("stringToPeriod(String) - exiting");
}
return period;
}
DateUtils.java 文件源码
java
阅读 27
收藏 0
点赞 0
评论 0
项目:motu
作者:
评论列表
文章目录