本文整理了Java中org.joda.time.DateTime.minusMinutes()
方法的一些代码示例,展示了DateTime.minusMinutes()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DateTime.minusMinutes()
方法的具体详情如下:
包路径:org.joda.time.DateTime
类名称:DateTime
方法名:minusMinutes
[英]Returns a copy of this datetime minus the specified number of minutes.
The calculation will subtract a duration equivalent to the number of minutes expressed in milliseconds.
The following three lines are identical in effect:
DateTime subtracted = dt.minusMinutes(6);
DateTime subtracted = dt.minus(Period.minutes(6));
DateTime subtracted = dt.withFieldAdded(DurationFieldType.minutes(), -6);
This datetime instance is immutable and unaffected by this method call.
[中]返回此datetime减去指定分钟数的副本。
计算将减去一个持续时间,该持续时间等于以毫秒表示的分钟数。
以下三行实际上是相同的:
DateTime subtracted = dt.minusMinutes(6);
DateTime subtracted = dt.minus(Period.minutes(6));
DateTime subtracted = dt.withFieldAdded(DurationFieldType.minutes(), -6);
此datetime实例是不可变的,不受此方法调用的影响。
代码示例来源:origin: dlew/joda-time-android
private void sampleGetRelativeTimeSpanString() {
List<String> text = new ArrayList<String>();
DateTime now = DateTime.now();
text.add("Short future: " + DateUtils.getRelativeTimeSpanString(this, now.plusMinutes(25)));
text.add("Medium future: " + DateUtils.getRelativeTimeSpanString(this, now.plusHours(5)));
text.add("Long future: " + DateUtils.getRelativeTimeSpanString(this, now.plusDays(3)));
text.add("Short past: " + DateUtils.getRelativeTimeSpanString(this, now.minusMinutes(25)));
text.add("Medium past: " + DateUtils.getRelativeTimeSpanString(this, now.minusHours(5)));
text.add("Long past: " + DateUtils.getRelativeTimeSpanString(this, now.minusDays(3)));
addSample("DateUtils.getRelativeTimeSpanString()", text);
}
代码示例来源:origin: dlew/joda-time-android
private void sampleGetRelativeDateTimeString() {
List<String> text = new ArrayList<String>();
DateTime now = DateTime.now();
text.add("Short future: " + DateUtils.getRelativeDateTimeString(this, now.plusMinutes(25), null, 0));
text.add("Medium future: " + DateUtils.getRelativeDateTimeString(this, now.plusHours(5), null, 0));
text.add("Long future: " + DateUtils.getRelativeDateTimeString(this, now.plusDays(3), null, 0));
text.add("Short past: " + DateUtils.getRelativeDateTimeString(this, now.minusMinutes(25), null, 0));
text.add("Medium past: " + DateUtils.getRelativeDateTimeString(this, now.minusHours(5), null, 0));
text.add("Long past: " + DateUtils.getRelativeDateTimeString(this, now.minusDays(3), null, 0));
addSample("DateUtils.getRelativeDateTimeString()", text);
}
代码示例来源:origin: dlew/joda-time-android
private void sampleGetRelativeTimeSpanStringWithPreposition() {
List<String> text = new ArrayList<String>();
DateTime now = DateTime.now();
text.add("Short future: " + DateUtils.getRelativeTimeSpanString(this, now.plusMinutes(25), true));
text.add("Medium future: " + DateUtils.getRelativeTimeSpanString(this, now.plusHours(5), true));
text.add("Long future: " + DateUtils.getRelativeTimeSpanString(this, now.plusDays(3), true));
text.add("Short past: " + DateUtils.getRelativeTimeSpanString(this, now.minusMinutes(25), true));
text.add("Medium past: " + DateUtils.getRelativeTimeSpanString(this, now.minusHours(5), true));
text.add("Long past: " + DateUtils.getRelativeTimeSpanString(this, now.minusDays(3), true));
addSample("DateUtils.getRelativeTimeSpanString() (with preposition)", text);
}
代码示例来源:origin: gocd/gocd
public static void setBuildingState(JobInstance instance) {
instance.setAgentUuid("1234");
DateTime now = new DateTime();
Date scheduledDate = now.minusMinutes(5).toDate();
instance.setScheduledDate(scheduledDate);
setTransitionConditionally(instance, JobState.Scheduled, scheduledDate);
setTransitionConditionally(instance, JobState.Assigned, now.minusMinutes(4).toDate());
setTransitionConditionally(instance, JobState.Preparing, now.minusMinutes(3).toDate());
setTransitionConditionally(instance, JobState.Building, now.minusMinutes(2).toDate());
}
代码示例来源:origin: Graylog2/graylog2-server
private String buildStreamDetailsURL(URI baseUri, AlertCondition.CheckResult checkResult, Stream stream) {
// Return an informational message if the web interface URL hasn't been set
if (baseUri == null || isNullOrEmpty(baseUri.getHost())) {
return "Please configure 'transport_email_web_interface_url' in your Graylog configuration file.";
}
int time = 5;
if (checkResult.getTriggeredCondition().getParameters().get("time") != null) {
time = (int) checkResult.getTriggeredCondition().getParameters().get("time");
}
DateTime dateAlertEnd = checkResult.getTriggeredAt();
DateTime dateAlertStart = dateAlertEnd.minusMinutes(time);
String alertStart = Tools.getISO8601String(dateAlertStart);
String alertEnd = Tools.getISO8601String(dateAlertEnd);
return baseUri + "/streams/" + stream.getId() + "/messages?rangetype=absolute&from=" + alertStart + "&to=" + alertEnd + "&q=*";
}
代码示例来源:origin: Graylog2/graylog2-server
@Override
public void doRun() {
final DateTime now = Tools.nowUTC();
final int secondOfMinute = now.getSecondOfMinute();
// on the top of every minute, we flush the current throughput
if (secondOfMinute == 0) {
LOG.trace("Calculating input and output traffic for the previous minute");
final long currentInputBytes = inputCounter.getCount();
final long currentOutputBytes = outputCounter.getCount();
final long currentDecodedBytes = decodedCounter.getCount();
final long inputLastMinute = currentInputBytes - previousInputBytes;
previousInputBytes = currentInputBytes;
final long outputBytesLastMinute = currentOutputBytes - previousOutputBytes;
previousOutputBytes = currentOutputBytes;
final long decodedBytesLastMinute = currentDecodedBytes - previousDecodedBytes;
previousDecodedBytes = currentDecodedBytes;
if (LOG.isDebugEnabled()) {
final Size in = Size.bytes(inputLastMinute);
final Size out = Size.bytes(outputBytesLastMinute);
final Size decoded = Size.bytes(decodedBytesLastMinute);
LOG.debug("Traffic in the last minute: in: {} bytes ({} MB), out: {} bytes ({} MB}), decoded: {} bytes ({} MB})",
in, in.toMegabytes(), out, out.toMegabytes(), decoded, decoded.toMegabytes());
}
final DateTime previousMinute = now.minusMinutes(1);
trafficService.updateTraffic(previousMinute, nodeId, inputLastMinute, outputBytesLastMinute, decodedBytesLastMinute);
}
}
代码示例来源:origin: apache/incubator-druid
@Test(timeout = 60_000L)
public void testShutdownWithPrevTime() throws Exception
{
EasyMock.expect(req.getAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED))
.andReturn(null)
.anyTimes();
EasyMock.expect(req.getAttribute(AuthConfig.DRUID_ALLOW_UNSECURED_PATH)).andReturn(null).anyTimes();
EasyMock.expect(req.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT))
.andReturn(AllowAllAuthenticator.ALLOW_ALL_RESULT)
.anyTimes();
req.setAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED, true);
EasyMock.expectLastCall().anyTimes();
EasyMock.replay(req);
firehose.shutdown(DateTimes.nowUtc().minusMinutes(2).toString(), req);
while (!firehose.isClosed()) {
Thread.sleep(50);
}
}
代码示例来源:origin: gocd/gocd
public static JobInstance building(String jobConfigName, Date startBuildingDate) {
final JobInstance instance = new JobInstance(jobConfigName);
instance.changeState(JobState.Building, startBuildingDate);
instance.setScheduledDate(new DateTime().minusMinutes(5).toDate());
instance.setIdentifier(defaultJobIdentifier(jobConfigName));
return instance;
}
代码示例来源:origin: azkaban/azkaban
/**
* Test metric reporting methods, including InMemoryMetricEmitter methods
*/
@Test
public void managerEmitterHandlingTest() throws Exception {
// metrics use System.currentTimeMillis, so that method should be the millis provider
final DateTime aboutNow = new DateTime(System.currentTimeMillis());
this.emitter.purgeAllData();
final Date from = aboutNow.minusMinutes(1).toDate();
this.metric.notifyManager();
this.emitterWrapper.countDownLatch.await(10L, TimeUnit.SECONDS);
final Date to = aboutNow.plusMinutes(1).toDate();
final List<InMemoryHistoryNode> nodes = this.emitter.getMetrics("FakeMetric", from, to, false);
assertEquals("Failed to report metric", 1, nodes.size());
assertEquals("Failed to report metric", nodes.get(0).getValue(), 4);
}
代码示例来源:origin: apache/incubator-druid
while ((line = reader.readLine()) != null) {
if (i == 15) { // for the 15th line, use a time before the window
dt = dt.minusMinutes(10);
代码示例来源:origin: apache/incubator-druid
while ((line = reader.readLine()) != null) {
if (i == 15) { // for the 15th line, use a time before the window
dt = dt.minusMinutes(10);
} else if (i == 16) { // remember this time to use in the expected response from the groupBy query
dtGroupBy = dt;
代码示例来源:origin: gocd/gocd
public static JobInstance buildEndingWithState(JobState endState, JobResult result, String jobConfig) {
final JobInstance instance = new JobInstance(jobConfig);
instance.setAgentUuid("1234");
instance.setId(1L);
instance.setIdentifier(defaultJobIdentifier(jobConfig));
instance.setState(endState);
instance.setTransitions(new JobStateTransitions());
DateTime now = new DateTime();
Date scheduledDate = now.minusMinutes(5).toDate();
instance.setScheduledDate(scheduledDate);
List<JobState> orderedStates = orderedBuildStates();
DateTime stateDate = new DateTime(scheduledDate);
for (JobState stateToCompareTo : orderedStates) {
if (endState.compareTo(stateToCompareTo) >= 0) {
instance.changeState(stateToCompareTo, stateDate.toDate());
stateDate = stateDate.plusMinutes(1);
}
}
if (endState.equals(JobState.Completed)) {
instance.setResult(result);
}
return instance;
}
代码示例来源:origin: apache/incubator-gobblin
@Test
public void testWorksNoPrefix() throws IOException, DataRecordException {
DatePartitionedAvroFileSource source = new DatePartitionedAvroFileSource();
SourceState state = new SourceState();
state.setProp(ConfigurationKeys.SOURCE_FILEBASED_FS_URI, ConfigurationKeys.LOCAL_FS_URI);
state.setProp(ConfigurationKeys.EXTRACT_NAMESPACE_NAME_KEY, SOURCE_ENTITY);
state.setProp(ConfigurationKeys.SOURCE_FILEBASED_DATA_DIRECTORY, OUTPUT_DIR + Path.SEPARATOR + SOURCE_ENTITY + Path.SEPARATOR + PREFIX);
state.setProp(ConfigurationKeys.SOURCE_ENTITY, SOURCE_ENTITY);
state.setProp(ConfigurationKeys.SOURCE_MAX_NUMBER_OF_PARTITIONS, 2);
state.setProp("date.partitioned.source.partition.pattern", DATE_PATTERN);
state.setProp("date.partitioned.source.min.watermark.value", DateTimeFormat.forPattern(DATE_PATTERN).print(
this.startDateTime.minusMinutes(1)));
state.setProp(ConfigurationKeys.EXTRACT_TABLE_TYPE_KEY, TableType.SNAPSHOT_ONLY);
state.setProp("date.partitioned.source.partition.suffix", SUFFIX);
//Read data partitioned by minutes, i.e each workunit is assigned records under the same YYYY/MM/dd/HH_mm directory
List<WorkUnit> workunits = source.getWorkunits(state);
Assert.assertEquals(workunits.size(), 4);
verifyWorkUnits(workunits);
}
代码示例来源:origin: apache/incubator-gobblin
@Test
public void testReadPartitionsByMinute() throws IOException, DataRecordException {
DatePartitionedAvroFileSource source = new DatePartitionedAvroFileSource();
SourceState state = new SourceState();
state.setProp(ConfigurationKeys.SOURCE_FILEBASED_FS_URI, ConfigurationKeys.LOCAL_FS_URI);
state.setProp(ConfigurationKeys.EXTRACT_NAMESPACE_NAME_KEY, SOURCE_ENTITY);
state.setProp(ConfigurationKeys.SOURCE_FILEBASED_DATA_DIRECTORY, OUTPUT_DIR + Path.SEPARATOR + SOURCE_ENTITY);
state.setProp(ConfigurationKeys.SOURCE_ENTITY, SOURCE_ENTITY);
state.setProp(ConfigurationKeys.SOURCE_MAX_NUMBER_OF_PARTITIONS, 2);
state.setProp("date.partitioned.source.partition.pattern", DATE_PATTERN);
state.setProp("date.partitioned.source.min.watermark.value", DateTimeFormat.forPattern(DATE_PATTERN).print(
this.startDateTime.minusMinutes(1)));
state.setProp(ConfigurationKeys.EXTRACT_TABLE_TYPE_KEY, TableType.SNAPSHOT_ONLY);
state.setProp("date.partitioned.source.partition.prefix", PREFIX);
state.setProp("date.partitioned.source.partition.suffix", SUFFIX);
//Read data partitioned by minutes, i.e each workunit is assigned records under the same YYYY/MM/dd/HH_mm directory
List<WorkUnit> workunits = source.getWorkunits(state);
Assert.assertEquals(workunits.size(), 4);
verifyWorkUnits(workunits);
}
代码示例来源:origin: apache/incubator-druid
Interval interval = new Interval(t.minusMinutes(1), t.plusMinutes(1));
代码示例来源:origin: apache/incubator-gobblin
@Test
public void testReadPartitionsByMinuteWithLeadtime() throws IOException, DataRecordException {
DatePartitionedAvroFileSource source = new DatePartitionedAvroFileSource();
SourceState state = new SourceState();
state.setProp(ConfigurationKeys.SOURCE_FILEBASED_FS_URI, ConfigurationKeys.LOCAL_FS_URI);
state.setProp(ConfigurationKeys.EXTRACT_NAMESPACE_NAME_KEY, SOURCE_ENTITY);
state.setProp(ConfigurationKeys.SOURCE_FILEBASED_DATA_DIRECTORY, OUTPUT_DIR + Path.SEPARATOR + SOURCE_ENTITY);
state.setProp(ConfigurationKeys.SOURCE_ENTITY, SOURCE_ENTITY);
state.setProp(ConfigurationKeys.SOURCE_MAX_NUMBER_OF_PARTITIONS, 2);
state.setProp("date.partitioned.source.partition.pattern", DATE_PATTERN);
state.setProp("date.partitioned.source.min.watermark.value", DateTimeFormat.forPattern(DATE_PATTERN).print(
this.startDateTime.minusMinutes(1)));
state.setProp(ConfigurationKeys.EXTRACT_TABLE_TYPE_KEY, TableType.SNAPSHOT_ONLY);
state.setProp("date.partitioned.source.partition.prefix", PREFIX);
state.setProp("date.partitioned.source.partition.suffix", SUFFIX);
state.setProp("date.partitioned.source.partition.lead_time.size", "3");
state.setProp("date.partitioned.source.partition.lead_time.granularity", "HOUR");
/*
* Since lead time is 3 hours, only the first WorkUnit (which is 6 hours old, rest are 2hrs) should get
* picked up
*/
List<WorkUnit> workunits = source.getWorkunits(state);
Assert.assertEquals(workunits.size(), 1);
verifyWorkUnits(workunits, workunits.size());
}
代码示例来源:origin: apache/incubator-gobblin
@Test
public void testJobStateNotCopiedToWorkUnit() {
DatePartitionedAvroFileSource source = new DatePartitionedAvroFileSource();
SourceState state = new SourceState();
state.setProp(ConfigurationKeys.SOURCE_FILEBASED_FS_URI, ConfigurationKeys.LOCAL_FS_URI);
state.setProp(ConfigurationKeys.EXTRACT_NAMESPACE_NAME_KEY, SOURCE_ENTITY);
state.setProp(ConfigurationKeys.SOURCE_FILEBASED_DATA_DIRECTORY, OUTPUT_DIR + Path.SEPARATOR + SOURCE_ENTITY);
state.setProp(ConfigurationKeys.SOURCE_ENTITY, SOURCE_ENTITY);
state.setProp(ConfigurationKeys.SOURCE_MAX_NUMBER_OF_PARTITIONS, 2);
state.setProp("date.partitioned.source.partition.pattern", DATE_PATTERN);
state.setProp("date.partitioned.source.min.watermark.value", DateTimeFormat.forPattern(DATE_PATTERN).print(
this.startDateTime.minusMinutes(1)));
state.setProp(ConfigurationKeys.EXTRACT_TABLE_TYPE_KEY, TableType.SNAPSHOT_ONLY);
state.setProp("date.partitioned.source.partition.prefix", PREFIX);
state.setProp("date.partitioned.source.partition.suffix", SUFFIX);
String dummyKey = "dummy.job.config";
state.setProp(dummyKey, "dummy");
List<WorkUnit> workunits = source.getWorkunits(state);
Assert.assertEquals(workunits.size(), 4);
for(WorkUnit wu : workunits) {
if (wu instanceof MultiWorkUnit) {
for (WorkUnit workUnit : ((MultiWorkUnit) wu).getWorkUnits()) {
Assert.assertFalse(workUnit.contains(dummyKey));
}
} else {
Assert.assertFalse(wu.contains(dummyKey));
}
}
}
代码示例来源:origin: dlew/joda-time-android
assertEquals("1 minute ago", DateUtils.getRelativeTimeSpanString(ctx, DateTime.now().minusMinutes(1)));
assertEquals("30 minutes ago", DateUtils.getRelativeTimeSpanString(ctx, DateTime.now().minusMinutes(30)));
assertEquals("in 1 min", DateUtils.getRelativeTimeSpanString(ctx, DateTime.now().plusMinutes(1),
DateUtils.FORMAT_ABBREV_RELATIVE));
assertEquals("in 30 mins", DateUtils.getRelativeTimeSpanString(ctx, DateTime.now().plusMinutes(30),
DateUtils.FORMAT_ABBREV_RELATIVE));
assertEquals("1 min ago", DateUtils.getRelativeTimeSpanString(ctx, DateTime.now().minusMinutes(1),
DateUtils.FORMAT_ABBREV_RELATIVE));
assertEquals("30 mins ago", DateUtils.getRelativeTimeSpanString(ctx, DateTime.now().minusMinutes(30),
DateUtils.FORMAT_ABBREV_RELATIVE));
代码示例来源:origin: line/armeria
conditions.setNotBefore(DateTime.now().minusMinutes(1));
conditions.setNotOnOrAfter(DateTime.now().plusMinutes(1));
代码示例来源:origin: dlew/joda-time-android
assertEquals("30 seconds ago, 12:34", DateUtils.getRelativeDateTimeString(ctx, mNow.minusSeconds(30), null, 0));
assertEquals("in 30 minutes, 13:05", DateUtils.getRelativeDateTimeString(ctx, mNow.plusMinutes(30), null, 0));
assertEquals("30 minutes ago, 12:05", DateUtils.getRelativeDateTimeString(ctx, mNow.minusMinutes(30), null, 0));
assertEquals("in 3 hours, 15:35", DateUtils.getRelativeDateTimeString(ctx, mNow.plusHours(3), null, 0));
assertEquals("3 hours ago, 09:35", DateUtils.getRelativeDateTimeString(ctx, mNow.minusHours(3), null, 0));
内容来源于网络,如有侵权,请联系作者删除!