本文整理汇总了Java中org.joda.time.format.ISOPeriodFormat类的典型用法代码示例。如果您正苦于以下问题:Java ISOPeriodFormat类的具体用法?Java ISOPeriodFormat怎么用?Java ISOPeriodFormat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ISOPeriodFormat类属于org.joda.time.format包,在下文中一共展示了ISOPeriodFormat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: apply
import org.joda.time.format.ISOPeriodFormat; //导入依赖的package包/类
@Override
public Object apply(WarpScriptStack stack) throws WarpScriptException {
Object top = stack.pop();
if (!(top instanceof Long)) {
throw new WarpScriptException(getName() + " expects a number of time units (LONG) on top of the stack.");
}
long duration = ((Number) top).longValue();
StringBuffer buf = new StringBuffer();
ReadablePeriod period = new MutablePeriod(duration / Constants.TIME_UNITS_PER_MS);
ISOPeriodFormat.standard().getPrinter().printTo(buf, period, Locale.US);
stack.push(buf.toString());
return stack;
}
示例2: getXSDurationToTimeSpan
import org.joda.time.format.ISOPeriodFormat; //导入依赖的package包/类
/**
* Takes an xs:duration string as defined by the W3 Consortiums
* Recommendation "XML Schema Part 2: Datatypes Second Edition",
* http://www.w3.org/TR/xmlschema-2/#duration, and converts it into a
* System.TimeSpan structure This method uses the following approximations:
* 1 year = 365 days 1 month = 30 days Additionally, it only allows for four
* decimal points of seconds precision.
*
* @param xsDuration xs:duration string to convert
* @return System.TimeSpan structure
*/
public static TimeSpan getXSDurationToTimeSpan(String xsDuration) {
// TODO: Need to check whether this should be the equivalent or not
Matcher m = PATTERN_TIME_SPAN.matcher(xsDuration);
boolean negative = false;
if (m.find()) {
negative = true;
}
// Removing leading '-'
if (negative) {
xsDuration = xsDuration.replace("-P", "P");
}
Period period = Period.parse(xsDuration, ISOPeriodFormat.standard());
long retval = period.toStandardDuration().getMillis();
if (negative) {
retval = -retval;
}
return new TimeSpan(retval);
}
示例3: coherceDuration
import org.joda.time.format.ISOPeriodFormat; //导入依赖的package包/类
private static <T> DurationLiteral coherceDuration(T value) {
DurationLiteral duration=null;
if(value instanceof Duration) {
duration=of((Duration)value);
} else if(value instanceof javax.xml.datatype.Duration) {
duration=of((javax.xml.datatype.Duration)value);
} else if(value instanceof String) {
try {
Period period = ISOPeriodFormat.standard().parsePeriod((String)value);
duration=of(period.toStandardDuration());
} catch (Exception e) {
throw new DatatypeCohercionException(value,Datatypes.DURATION,e);
}
} else {
throw new DatatypeCohercionException(value,Datatypes.DURATION);
}
return duration;
}
示例4: init
import org.joda.time.format.ISOPeriodFormat; //导入依赖的package包/类
@Override
public void init(CommonSchedule schedule, XElement config) {
super.init(schedule, config);
if (config == null)
return;
String period = config.getAttribute("Value");
if (!StringUtil.isEmpty(period))
try {
this.period = ISOPeriodFormat.standard().parsePeriod(period);
}
catch (Exception x) {
// TODO log
}
}
示例5: formatDuration
import org.joda.time.format.ISOPeriodFormat; //导入依赖的package包/类
public static String formatDuration(String duration)
{
Duration d = ISOPeriodFormat.standard().parsePeriod(duration).toStandardDuration();
long hours = d.getStandardHours();
Duration minusHours = d.minus(Duration.standardHours(hours));
long minutes = minusHours.getStandardMinutes();
long seconds = minusHours.minus(Duration.standardMinutes(minutes)).getStandardSeconds();
String format = hours > 0 ? "%3$d:%2$02d:%1$02d" : "%2$d:%1$02d";
return String.format(format, seconds, minutes, hours);
}
示例6: writeInterval
import org.joda.time.format.ISOPeriodFormat; //导入依赖的package包/类
@Override
public void writeInterval(boolean isNull) throws IOException {
IntervalWriter intervalWriter = writer.interval();
if(!isNull){
final Period p = ISOPeriodFormat.standard().parsePeriod(parser.getValueAsString());
int months = DateUtility.monthsFromPeriod(p);
int days = p.getDays();
int millis = DateUtility.millisFromPeriod(p);
intervalWriter.writeInterval(months, days, millis);
}
}
示例7: convertTime
import org.joda.time.format.ISOPeriodFormat; //导入依赖的package包/类
private int convertTime(String time) {
PeriodFormatter formatter = ISOPeriodFormat.standard();
Period p = formatter.parsePeriod(time);
Seconds s = p.toStandardSeconds();
return s.getSeconds();
}
示例8: retrievePeriodValueFromConfiguration
import org.joda.time.format.ISOPeriodFormat; //导入依赖的package包/类
@Test
public void retrievePeriodValueFromConfiguration() {
Configuration configuration = ConfigurationProvider.getConfiguration();
MutablePeriod referenceValue = new MutablePeriod();
ISOPeriodFormat.standard().getParser().parseInto(referenceValue, "P1Y1M1W1DT1H1M1S", 0,
Locale.ENGLISH);
String periodAsString = configuration.get("periodValueA");
Period period = configuration.get("periodValueA", Period.class);
assertThat(periodAsString, equalTo("P1Y1M1W1DT1H1M1S"));
assertThat(period, equalTo(referenceValue.toPeriod()));
}
示例9: serialize
import org.joda.time.format.ISOPeriodFormat; //导入依赖的package包/类
@Override
public void serialize(
final Duration duration,
final JsonGenerator jgen,
final SerializerProvider provider) throws IOException, JsonProcessingException
{
if (duration == null)
{
jgen.writeNull();
return;
}
final PeriodFormatter formatter = ISOPeriodFormat.standard();
jgen.writeString(duration.toPeriod().toString(formatter));
}
示例10: deserialize
import org.joda.time.format.ISOPeriodFormat; //导入依赖的package包/类
@Override
public Duration deserialize(final JsonParser parser, final DeserializationContext ctxt)
throws JsonParseException, IOException
{
final JsonToken jsonToken = parser.getCurrentToken();
if (jsonToken == JsonToken.VALUE_NUMBER_INT)
{
return new Duration(parser.getLongValue());
}
else if (jsonToken == JsonToken.VALUE_STRING)
{
final String str = parser.getText().trim();
if (str.length() == 0)
{
return null;
}
final PeriodFormatter formatter = ISOPeriodFormat.standard();
return formatter.parsePeriod(str).toStandardDuration();
}
throw ctxt.mappingException(Duration.class);
}
示例11: setInto
import org.joda.time.format.ISOPeriodFormat; //导入依赖的package包/类
/**
* Extracts duration values from an object of this converter's type, and
* sets them into the given ReadWritableDuration.
*
* @param period period to get modified
* @param object the String to convert, must not be null
* @param chrono the chronology to use
* @return the millisecond duration
* @throws ClassCastException if the object is invalid
*/
public void setInto(ReadWritablePeriod period, Object object, Chronology chrono) {
String str = (String) object;
PeriodFormatter parser = ISOPeriodFormat.standard();
period.clear();
int pos = parser.parseInto(period, str, 0);
if (pos < str.length()) {
if (pos < 0) {
// Parse again to get a better exception thrown.
parser.withParseType(period.getPeriodType()).parseMutablePeriod(str);
}
throw new IllegalArgumentException("Invalid format: \"" + str + '"');
}
}
示例12: setUp
import org.joda.time.format.ISOPeriodFormat; //导入依赖的package包/类
@Before
public void setUp() {
formatter = ISOPeriodFormat.standard();
processor1 = new ParsePeriod();
processor2 = new ParsePeriod(formatter);
processorChain1 = new ParsePeriod(new IdentityTransform());
processorChain2 = new ParsePeriod(formatter, new IdentityTransform());
processors = Arrays.asList(processor1, processor2, processorChain1,
processorChain2);
}
示例13: setUp
import org.joda.time.format.ISOPeriodFormat; //导入依赖的package包/类
@Before
public void setUp() {
formatter = ISOPeriodFormat.standard();
processor1 = new FmtPeriod();
processor2 = new FmtPeriod(formatter);
processorChain1 = new FmtPeriod(new IdentityTransform());
processorChain2 = new FmtPeriod(formatter, new IdentityTransform());
processors = Arrays.asList(processor1, processor2, processorChain1,
processorChain2);
}
示例14: fromString
import org.joda.time.format.ISOPeriodFormat; //导入依赖的package包/类
@Override
public Duration fromString(String rawValue) {
try {
Period period = ISOPeriodFormat.standard().parsePeriod(rawValue);
return period.toStandardDuration();
} catch (Exception e) {
throw new ObjectParseException(e,Duration.class,rawValue);
}
}
示例15: fromString
import org.joda.time.format.ISOPeriodFormat; //导入依赖的package包/类
@Override
public Duration fromString(String rawValue) {
try {
Period period = ISOPeriodFormat.standard().parsePeriod(rawValue);
return TimeUtils.newInstance().from(period.toStandardDuration()).toDuration();
} catch (Exception e) {
throw new ObjectParseException(e,Duration.class,rawValue);
}
}