All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.intelie.pipes.time.TimeSpanParser Maven / Gradle / Ivy

There is a newer version: 0.25.5
Show newest version
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());
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy