本文整理汇总了Java中org.joda.time.format.PeriodFormatter.parsePeriod方法的典型用法代码示例。如果您正苦于以下问题:Java PeriodFormatter.parsePeriod方法的具体用法?Java PeriodFormatter.parsePeriod怎么用?Java PeriodFormatter.parsePeriod使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.joda.time.format.PeriodFormatter
的用法示例。
在下文中一共展示了PeriodFormatter.parsePeriod方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: prettifyDuration
import org.joda.time.format.PeriodFormatter; //导入方法依赖的package包/类
private String prettifyDuration(String duration) {
PeriodFormatter formatter = new PeriodFormatterBuilder()
.appendDays().appendSuffix("d")
.appendHours().appendSuffix(":")
.appendMinutes().appendSuffix(":")
.appendSeconds().toFormatter();
Period p = formatter.parsePeriod(duration);
String day = context.getResources().getString(R.string.day_short);
if(p.getDays() > 0) {
return String.format("%d"+ day + " %dh %dm", p.getDays(), p.getHours(), p.getMinutes());
} else if (p.getHours() > 0) {
return String.format(Locale.getDefault(), "%dh %dm", p.getHours(), p.getMinutes());
} else {
return String.format(Locale.getDefault(), "%dm", p.getMinutes());
}
}
示例2: testRecompactionConditionBasedOnDuration
import org.joda.time.format.PeriodFormatter; //导入方法依赖的package包/类
@Test
public void testRecompactionConditionBasedOnDuration() {
RecompactionConditionFactory factory = new RecompactionConditionBasedOnDuration.Factory();
RecompactionCondition conditionBasedOnDuration = factory.createRecompactionCondition(dataset);
DatasetHelper helper = mock (DatasetHelper.class);
when(helper.getDataset()).thenReturn(dataset);
PeriodFormatter periodFormatter = new PeriodFormatterBuilder().appendMonths().appendSuffix("m").appendDays().appendSuffix("d").appendHours()
.appendSuffix("h").appendMinutes().appendSuffix("min").toFormatter();
DateTime currentTime = getCurrentTime();
Period period_A = periodFormatter.parsePeriod("11h59min");
DateTime earliest_A = currentTime.minus(period_A);
when(helper.getEarliestLateFileModificationTime()).thenReturn(Optional.of(earliest_A));
when(helper.getCurrentTime()).thenReturn(currentTime);
Assert.assertEquals(conditionBasedOnDuration.isRecompactionNeeded(helper), false);
Period period_B = periodFormatter.parsePeriod("12h01min");
DateTime earliest_B = currentTime.minus(period_B);
when(helper.getEarliestLateFileModificationTime()).thenReturn(Optional.of(earliest_B));
when(helper.getCurrentTime()).thenReturn(currentTime);
Assert.assertEquals(conditionBasedOnDuration.isRecompactionNeeded(helper), true);
}
示例3: getSessionMaxAge
import org.joda.time.format.PeriodFormatter; //导入方法依赖的package包/类
private Period getSessionMaxAge() {
String maxAge = environment.getRequiredProperty("auth.session.maxAge");
PeriodFormatter format = new PeriodFormatterBuilder()
.appendDays()
.appendSuffix("d", "d")
.printZeroRarelyFirst()
.appendHours()
.appendSuffix("h", "h")
.printZeroRarelyFirst()
.appendMinutes()
.appendSuffix("m", "m")
.toFormatter();
Period sessionMaxAge = format.parsePeriod(maxAge);
if (LOG.isDebugEnabled()) {
LOG.debug("Session maxAge is: "+
formatIfNotZero(sessionMaxAge.getDays(), "days", "day") +
formatIfNotZero(sessionMaxAge.getHours(), "hours", "hour") +
formatIfNotZero(sessionMaxAge.getMinutes(), "minutes", "minute")
);
}
return sessionMaxAge;
}
示例4: convertDuration
import org.joda.time.format.PeriodFormatter; //导入方法依赖的package包/类
/**
* Converts the duration in the format of HH:MM:SS:ss to HH:MM:SS
* @param periodHHMMSSmm
* @return
*/
public static String convertDuration(final String periodHHMMSSmm){
String newDuration = periodHHMMSSmm;
PeriodFormatter hoursMinutesSecondsMilli = new PeriodFormatterBuilder()
.appendHours()
.appendSeparator(":")
.appendMinutes()
.appendSeparator(":")
.appendSeconds()
.appendSeparator(":")
.appendMillis()
.toFormatter();
try{
if (StringUtils.isNotBlank(periodHHMMSSmm)){
Period period = hoursMinutesSecondsMilli.parsePeriod(periodHHMMSSmm);
newDuration = String.format("%02d:%02d:%02d", period.getHours(), period.getMinutes(), period.getSeconds());
}
}catch(IllegalArgumentException e){
log.error("Invalid duration format: " + periodHHMMSSmm);
}
return newDuration;
}
示例5: convertTime
import org.joda.time.format.PeriodFormatter; //导入方法依赖的package包/类
private int convertTime(String time) {
PeriodFormatter formatter = ISOPeriodFormat.standard();
Period p = formatter.parsePeriod(time);
Seconds s = p.toStandardSeconds();
return s.getSeconds();
}
示例6: stringToPeriod
import org.joda.time.format.PeriodFormatter; //导入方法依赖的package包/类
/**
* 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;
}
示例7: getEarliestAllowedTimestamp
import org.joda.time.format.PeriodFormatter; //导入方法依赖的package包/类
private Optional<Long> getEarliestAllowedTimestamp() {
if (!this.properties.contains(TIME_PARTITIONED_WRITER_MAX_TIME_AGO)) {
return Optional.<Long> absent();
} else {
DateTime currentTime = new DateTime(this.timeZone);
PeriodFormatter periodFormatter = getPeriodFormatter();
String maxTimeAgoStr = this.properties.getProp(TIME_PARTITIONED_WRITER_MAX_TIME_AGO);
Period maxTimeAgo = periodFormatter.parsePeriod(maxTimeAgoStr);
return Optional.of(currentTime.minus(maxTimeAgo).getMillis());
}
}
示例8: parsePeriod
import org.joda.time.format.PeriodFormatter; //导入方法依赖的package包/类
private static Period parsePeriod(PeriodFormatter periodFormatter, String value, IntervalField startField, IntervalField endField)
{
try {
return periodFormatter.parsePeriod(value);
}
catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Invalid INTERVAL " + startField + " to " + endField + " value: " + value, e);
}
}
示例9: Duration
import org.joda.time.format.PeriodFormatter; //导入方法依赖的package包/类
public Duration(String parse) {
PeriodFormatter formatter = new PeriodFormatterBuilder()
.appendDays().appendSuffix("d")
.appendHours().appendSuffix("h")
.appendMinutes().appendSuffix("m")
.appendSeconds().appendSuffix("s")
.toFormatter();
parse = parse.replace(" ", "");
Period p = formatter.parsePeriod(parse);
this.seconds = p.toStandardSeconds().getSeconds();
}
示例10: verify
import org.joda.time.format.PeriodFormatter; //导入方法依赖的package包/类
public Result verify (FileSystemDataset dataset) {
final DateTime earliest;
final DateTime latest;
try {
CompactionPathParser.CompactionParserResult result = new CompactionPathParser(state).parse(dataset);
DateTime folderTime = result.getTime();
DateTimeZone timeZone = DateTimeZone.forID(this.state.getProp(MRCompactor.COMPACTION_TIMEZONE, MRCompactor.DEFAULT_COMPACTION_TIMEZONE));
DateTime current = new DateTime(timeZone);
PeriodFormatter formatter = new PeriodFormatterBuilder().appendMonths().appendSuffix("m").appendDays().appendSuffix("d").appendHours()
.appendSuffix("h").toFormatter();
// get earliest time
String maxTimeAgoStr = this.state.getProp(TimeBasedSubDirDatasetsFinder.COMPACTION_TIMEBASED_MAX_TIME_AGO, TimeBasedSubDirDatasetsFinder.DEFAULT_COMPACTION_TIMEBASED_MAX_TIME_AGO);
Period maxTimeAgo = formatter.parsePeriod(maxTimeAgoStr);
earliest = current.minus(maxTimeAgo);
// get latest time
String minTimeAgoStr = this.state.getProp(TimeBasedSubDirDatasetsFinder.COMPACTION_TIMEBASED_MIN_TIME_AGO, TimeBasedSubDirDatasetsFinder.DEFAULT_COMPACTION_TIMEBASED_MIN_TIME_AGO);
Period minTimeAgo = formatter.parsePeriod(minTimeAgoStr);
latest = current.minus(minTimeAgo);
if (earliest.isBefore(folderTime) && latest.isAfter(folderTime)) {
log.debug("{} falls in the user defined time range", dataset.datasetRoot());
return new Result(true, "");
}
} catch (Exception e) {
log.error("{} cannot be verified because of {}", dataset.datasetRoot(), ExceptionUtils.getFullStackTrace(e));
return new Result(false, e.toString());
}
return new Result(false, dataset.datasetRoot() + " is not in between " + earliest + " and " + latest);
}
示例11: parseDuration
import org.joda.time.format.PeriodFormatter; //导入方法依赖的package包/类
private Duration parseDuration(String initParameter, Duration defaultDuration)
{
if (initParameter!=null)
{
PeriodFormatter formatter = new PeriodFormatterBuilder()
.appendDays().appendSuffix("d ")
.appendHours().appendSuffix("h ")
.appendMinutes().appendSuffix("min")
.toFormatter();
Period p = formatter.parsePeriod(initParameter);
return p.toDurationFrom(DateTime.now());
} else
return defaultDuration;
}
示例12: GetVideoLength
import org.joda.time.format.PeriodFormatter; //导入方法依赖的package包/类
public int[] GetVideoLength(String id) {
if (Quorrabot.enableDebugging) {
com.gmt2001.Console.out.println(">>>[DEBUG] YouTubeAPIv3.GetVideoLength Start id=" + id);
}
JSONObject j = GetData(request_type.GET, "https://www.googleapis.com/youtube/v3/videos?id=" + id + "&key=" + apikey + "&part=contentDetails");
if (j.getBoolean("_success")) {
if (j.getInt("_http") == 200) {
JSONArray a = j.getJSONArray("items");
if (a.length() > 0) {
JSONObject i = a.getJSONObject(0);
JSONObject cd = i.getJSONObject("contentDetails");
PeriodFormatter formatter = ISOPeriodFormat.standard();
Period d = formatter.parsePeriod(cd.getString("duration"));
//String d = cd.getString("duration").substring(2);
int h, m, s;
String hours = d.toStandardHours().toString().substring(2);
h = Integer.parseInt(hours.substring(0, hours.indexOf("H")));
String minutes = d.toStandardMinutes().toString().substring(2);
m = Integer.parseInt(minutes.substring(0, minutes.indexOf("M")));
String seconds = d.toStandardSeconds().toString().substring(2);
s = Integer.parseInt(seconds.substring(0, seconds.indexOf("S")));
/*
* if (d.contains("H")) { h =
* Integer.parseInt(d.substring(0, d.indexOf("H")));
*
* d = d.substring(0, d.indexOf("H")); }
*
* if (d.contains("M")) { m =
* Integer.parseInt(d.substring(0, d.indexOf("M")));
*
* d = d.substring(0, d.indexOf("M")); }
*
* s = Integer.parseInt(d.substring(0, d.indexOf("S")));
*/
if (Quorrabot.enableDebugging) {
com.gmt2001.Console.out.println(">>>[DEBUG] YouTubeAPIv3.GetVideoLength Success");
}
return new int[]{
h, m, s
};
} else {
if (Quorrabot.enableDebugging) {
com.gmt2001.Console.out.println(">>>[DEBUG] YouTubeAPIv3.GetVideoLength Fail");
}
return new int[]{
0, 0, 0
};
}
} else {
if (Quorrabot.enableDebugging) {
com.gmt2001.Console.out.println(">>>[DEBUG] YouTubeAPIv3.GetVideoLength Fail2");
}
return new int[]{
0, 0, 0
};
}
}
if (Quorrabot.enableDebugging) {
com.gmt2001.Console.out.println(">>>[DEBUG] YouTubeAPIv3.GetVideoLength Fail3");
}
return new int[]{
0, 0, 0
};
}
示例13: onCommand
import org.joda.time.format.PeriodFormatter; //导入方法依赖的package包/类
@Override
public void onCommand(IUser sender, IChannel channel, IMessage message, String[] args) {
if (getPermissions(channel).isCreator(sender)) {
if (args.length == 0) {
update(false, channel);
} else if (args.length == 1) {
if (args[0].equalsIgnoreCase("force")) {
update(true, channel);
} else if (args[0].equalsIgnoreCase("no-active-channels")) {
MessageUtils.sendMessage("I will now update to the latest version when no channels are playing music!", channel);
if (flareBot.getClient().getConnectedVoiceChannels().size() == 0) {
update(true, channel);
} else {
if (!queued.getAndSet(true)) {
NOVOICE_UPDATING.set(true);
} else
MessageUtils.sendMessage("There is already an update queued!", channel);
}
} else {
if (!queued.getAndSet(true)) {
Period p;
try {
PeriodFormatter formatter = new PeriodFormatterBuilder()
.appendDays().appendSuffix("d")
.appendHours().appendSuffix("h")
.appendMinutes().appendSuffix("m")
.appendSeconds().appendSuffix("s")
.toFormatter();
p = formatter.parsePeriod(args[0]);
new FlarebotTask("Scheduled-Update") {
@Override
public void run() {
update(true, channel);
}
}.delay(p.toStandardSeconds().getSeconds() * 1000);
} catch (IllegalArgumentException e) {
MessageUtils.sendMessage("That is an invalid time option!", channel);
return;
}
MessageUtils.sendMessage("I will now update to the latest version in " + p.toStandardSeconds().getSeconds() + " seconds.", channel);
} else
MessageUtils.sendMessage("There is already an update queued!", channel);
}
}
}
}
示例14: getEarliestAllowedFolderTime
import org.joda.time.format.PeriodFormatter; //导入方法依赖的package包/类
private DateTime getEarliestAllowedFolderTime(DateTime currentTime, PeriodFormatter periodFormatter) {
String maxTimeAgoStr =
this.state.getProp(COMPACTION_TIMEBASED_MAX_TIME_AGO, DEFAULT_COMPACTION_TIMEBASED_MAX_TIME_AGO);
Period maxTimeAgo = periodFormatter.parsePeriod(maxTimeAgoStr);
return currentTime.minus(maxTimeAgo);
}
示例15: getLatestAllowedFolderTime
import org.joda.time.format.PeriodFormatter; //导入方法依赖的package包/类
private DateTime getLatestAllowedFolderTime(DateTime currentTime, PeriodFormatter periodFormatter) {
String minTimeAgoStr =
this.state.getProp(COMPACTION_TIMEBASED_MIN_TIME_AGO, DEFAULT_COMPACTION_TIMEBASED_MIN_TIME_AGO);
Period minTimeAgo = periodFormatter.parsePeriod(minTimeAgoStr);
return currentTime.minus(minTimeAgo);
}