当前位置: 首页>>代码示例>>Java>>正文


Java ISOPeriodFormat类代码示例

本文整理汇总了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;
}
 
开发者ID:cityzendata,项目名称:warp10-platform,代码行数:19,代码来源:ISODURATION.java

示例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);

}
 
开发者ID:OfficeDev,项目名称:ews-java-api,代码行数:36,代码来源:EwsUtilities.java

示例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;
}
 
开发者ID:ldp4j,项目名称:ldp4j,代码行数:19,代码来源:Literals.java

示例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
		}
}
 
开发者ID:Gadreel,项目名称:divconq,代码行数:18,代码来源:PeriodHelper.java

示例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);
}
 
开发者ID:equella,项目名称:Equella,代码行数:11,代码来源:YoutubeUtils.java

示例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);
  }
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:12,代码来源:VectorOutput.java

示例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();
}
 
开发者ID:89luca89,项目名称:ThunderMusic,代码行数:8,代码来源:OnlineTotalSearchTask.java

示例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()));
}
 
开发者ID:apache,项目名称:incubator-tamaya-sandbox,代码行数:16,代码来源:FullStackIT.java

示例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));
}
 
开发者ID:NovaOrdis,项目名称:playground,代码行数:16,代码来源:DurationSerializer.java

示例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);
}
 
开发者ID:NovaOrdis,项目名称:playground,代码行数:24,代码来源:DurationDeserializer.java

示例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 + '"');
    }
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:24,代码来源:StringConverter.java

示例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);
}
 
开发者ID:super-csv,项目名称:super-csv,代码行数:11,代码来源:ParsePeriodTest.java

示例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);
}
 
开发者ID:super-csv,项目名称:super-csv,代码行数:11,代码来源:FmtPeriodTest.java

示例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);
	}
}
 
开发者ID:ldp4j,项目名称:ldp4j,代码行数:10,代码来源:JodaDurationObjectFactory.java

示例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);
	}
}
 
开发者ID:ldp4j,项目名称:ldp4j,代码行数:10,代码来源:XmlDurationObjectFactory.java


注:本文中的org.joda.time.format.ISOPeriodFormat类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。