net.intelie.pipes.time.TimeSpanParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pipes-api Show documentation
Show all versions of pipes-api Show documentation
Intelie Pipes' API classes and interfaces
package net.intelie.pipes.time;
import net.intelie.pipes.PipeException;
import net.intelie.pipes.generated.*;
import net.intelie.pipes.util.PipesCharStream;
import java.time.ZoneId;
public class TimeSpanParser {
private final ZoneId defaultTZ;
public TimeSpanParser() {
this(ZoneId.systemDefault());
}
public TimeSpanParser(ZoneId defaultTZ) {
this.defaultTZ = defaultTZ;
}
public TimeSpan parse(String s) throws PipeException {
return parse(s, null);
}
public Period parsePeriod(String s) throws PipeException {
return parsePeriod(s, null);
}
public Period parsePeriod(String s, ZoneId zone) throws PipeException {
PipesParser.Span parser = new PipesParser.Span(s);
try {
if (zone == null) zone = defaultTZ;
return parser.startPeriod(zone);
} catch (Throwable e) {
throw ParseExceptionMessage.handle(e, parser.location());
}
}
public TimeSpan parse(String s, ZoneId zone) throws PipeException {
PipesParser.Span parser = new PipesParser.Span(s);
try {
if (zone == null) zone = defaultTZ;
return parser.start(zone);
} catch (Throwable e) {
throw ParseExceptionMessage.handle(e, parser.location());
}
}
}