Java Code Examples for java.time.ZonedDateTime#minusSeconds()

The following examples show how to use java.time.ZonedDateTime#minusSeconds() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DateTimeWithinPeriodTest.java    From rya with Apache License 2.0 6 votes vote down vote up
@Test
public void testSeconds() throws DatatypeConfigurationException, ValueExprEvaluationException {
    DatatypeFactory dtf = DatatypeFactory.newInstance();

    ZonedDateTime zTime = testThisTimeDate;
    String time = zTime.format(DateTimeFormatter.ISO_INSTANT);

    ZonedDateTime zTime1 = zTime.minusSeconds(1);
    String time1 = zTime1.format(DateTimeFormatter.ISO_INSTANT);

    Literal now = VF.createLiteral(dtf.newXMLGregorianCalendar(time));
    Literal nowMinusOne = VF.createLiteral(dtf.newXMLGregorianCalendar(time1));

    DateTimeWithinPeriod func = new DateTimeWithinPeriod();

    assertEquals(TRUE, func.evaluate(VF, now, now, VF.createLiteral(1), OWLTime.SECONDS_URI));
    assertEquals(FALSE, func.evaluate(VF, now, nowMinusOne,VF.createLiteral(1), OWLTime.SECONDS_URI));
    assertEquals(TRUE, func.evaluate(VF, now, nowMinusOne,VF.createLiteral(2), OWLTime.SECONDS_URI));
}
 
Example 2
Source File: TCKZonedDateTime.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_minusSeconds_seconds() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.minusSeconds(1);
    assertEquals(test, ZonedDateTime.of(ldt.minusSeconds(1), ZONE_0100));
}
 
Example 3
Source File: QueryIT.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void dateTimeWithinNow() throws Exception {

    final ValueFactory vf = SimpleValueFactory.getInstance();
    final DatatypeFactory dtf = DatatypeFactory.newInstance();
    FunctionRegistry.getInstance().add(new DateTimeWithinPeriod());

    final String sparql = "PREFIX fn: <" + FN.NAMESPACE +">"
            + "SELECT ?event ?startTime WHERE { ?event <uri:startTime> ?startTime. "
            + "FILTER(fn:dateTimeWithin(?startTime, NOW(), 30, <" + OWLTime.SECONDS_URI + "> ))}";

    final ZonedDateTime zTime = ZonedDateTime.now();
    final String time = zTime.format(DateTimeFormatter.ISO_INSTANT);

    final ZonedDateTime zTime1 = zTime.minusSeconds(30);
    final String time1 = zTime1.format(DateTimeFormatter.ISO_INSTANT);

    final Literal lit = vf.createLiteral(dtf.newXMLGregorianCalendar(time));
    final Literal lit1 = vf.createLiteral(dtf.newXMLGregorianCalendar(time1));

    // Create the Statements that will be loaded into Rya.
    final Collection<Statement> statements = Sets.newHashSet(
            vf.createStatement(vf.createIRI("uri:event1"), vf.createIRI("uri:startTime"), lit),
            vf.createStatement(vf.createIRI("uri:event2"), vf.createIRI("uri:startTime"), lit1)
           );

    // Create the expected results of the SPARQL query once the PCJ has been computed.
    final Set<BindingSet> expectedResults = new HashSet<>();

    final MapBindingSet bs = new MapBindingSet();
    bs.addBinding("event", vf.createIRI("uri:event1"));
    bs.addBinding("startTime", lit);
    expectedResults.add(bs);

    // Verify the end results of the query match the expected results.
    runTest(sparql, statements, expectedResults, ExportStrategy.RYA);
}
 
Example 4
Source File: HotTest.java    From expper with GNU General Public License v3.0 5 votes vote down vote up
public static void initialize(long size) {
    for (long i = 0; i < size; ++i) {
        PostMeta post = new PostMeta();
        post.id = i;
        post.ups = (int) (Math.random() * 10000);
        post.downs = (int) (Math.random() * 10000);
        ZonedDateTime date = ZonedDateTime.now();
        date = date.minusHours((int) (Math.random() * 24 * 30 * 6));
        date = date.minusSeconds((int) (Math.random() * 3600));
        post.createdAt = date;
        post.hot = (int) (Math.random() * 2000);

        posts.add(post);
    }
}
 
Example 5
Source File: TCKZonedDateTime.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_minusSeconds_seconds() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.minusSeconds(1);
    assertEquals(test, ZonedDateTime.of(ldt.minusSeconds(1), ZONE_0100));
}
 
Example 6
Source File: TCKZonedDateTime.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test
public void test_minusSeconds_seconds() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.minusSeconds(1);
    assertEquals(test, ZonedDateTime.of(ldt.minusSeconds(1), ZONE_0100));
}
 
Example 7
Source File: TCKZonedDateTime.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_minusSeconds_seconds() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.minusSeconds(1);
    assertEquals(test, ZonedDateTime.of(ldt.minusSeconds(1), ZONE_0100));
}
 
Example 8
Source File: TCKZonedDateTime.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_minusSeconds_seconds() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.minusSeconds(1);
    assertEquals(test, ZonedDateTime.of(ldt.minusSeconds(1), ZONE_0100));
}
 
Example 9
Source File: TCKZonedDateTime.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_minusSeconds_seconds() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.minusSeconds(1);
    assertEquals(test, ZonedDateTime.of(ldt.minusSeconds(1), ZONE_0100));
}
 
Example 10
Source File: TCKZonedDateTime.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_minusSeconds_seconds() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.minusSeconds(1);
    assertEquals(test, ZonedDateTime.of(ldt.minusSeconds(1), ZONE_0100));
}
 
Example 11
Source File: TCKZonedDateTime.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_minusSeconds_seconds() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.minusSeconds(1);
    assertEquals(test, ZonedDateTime.of(ldt.minusSeconds(1), ZONE_0100));
}
 
Example 12
Source File: InsightsUtils.java    From Insights with Apache License 2.0 5 votes vote down vote up
public static long getDataToTime(String schedule) {

		Long time = null;
		ZonedDateTime now = ZonedDateTime.now(zoneId);

		if (JobSchedule.DAILY.name().equalsIgnoreCase(schedule)) {
			ZonedDateTime today = now.toLocalDate().atStartOfDay(zoneId);
			ZonedDateTime yesterdayEnd = today.minusSeconds(1);
			time = yesterdayEnd.toInstant().toEpochMilli();
		} else if (JobSchedule.WEEKLY.name().equalsIgnoreCase(schedule)) {
			ZonedDateTime todayStart = now.toLocalDate().atStartOfDay(zoneId)
					.with(TemporalAdjusters.previousOrSame(DayOfWeek.SUNDAY));
			ZonedDateTime lastWeek = todayStart.minusSeconds(1);
			time = lastWeek.toInstant().toEpochMilli();
		} else if (JobSchedule.MONTHLY.name().equalsIgnoreCase(schedule)) {
			ZonedDateTime firstDayofMonth = now.with(TemporalAdjusters.firstDayOfMonth()).toLocalDate()
					.atStartOfDay(zoneId);
			ZonedDateTime firstDayofLastMonth = firstDayofMonth.minusMinutes(1)
					.with(TemporalAdjusters.firstDayOfMonth()).toLocalDate().atStartOfDay(zoneId);
			ZonedDateTime lastDayOftheMonth = firstDayofLastMonth.with(TemporalAdjusters.lastDayOfMonth()).toLocalDate()
					.atStartOfDay(zoneId);
			lastDayOftheMonth = lastDayOftheMonth.minusSeconds(1);
			time = lastDayOftheMonth.toInstant().toEpochMilli();
		} else if (JobSchedule.QUARTERLY.name().equalsIgnoreCase(schedule)) {
			// Will add code later for this usecase
			// zdt = zdt.plusMonths(3);
		} else if (JobSchedule.YEARLY.name().equalsIgnoreCase(schedule)) {
			ZonedDateTime firstDayofYear = now.with(TemporalAdjusters.firstDayOfYear()).toLocalDate()
					.atStartOfDay(zoneId);
			ZonedDateTime firstDayofLastYear = firstDayofYear.minusMinutes(1).with(TemporalAdjusters.firstDayOfYear())
					.toLocalDate().atStartOfDay(zoneId);
			ZonedDateTime lastDayofYear = firstDayofLastYear.with(TemporalAdjusters.lastDayOfYear()).toLocalDate()
					.atStartOfDay(zoneId);
			lastDayofYear = lastDayofYear.minusSeconds(1);
			time = lastDayofYear.toInstant().toEpochMilli();
		}
		return time;

	}
 
Example 13
Source File: StoredConfigService.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
private ZonedDateTime storedConfigPoller(int delay, ZonedDateTime then) {
    ZonedDateTime now = ZonedDateTime.now();

    if (then == null) {
        // on start set then
        now.minusSeconds(delay);
        then = now;
    }

    List<HibernateConfigItem> polled = findPollOn(then, now);

    int registered = 0;

    for (HibernateConfigItem item : polled) {
        if (item.isRegistered()) { // registering items that are not marked as registered leads to bad things in SCS
            ConfigItem cItem = serverConfigurationService.getConfigItem(item.getName());
            if (!item.similar(cItem)) { // only register items that are not similar, reduces history on items in SCS
                serverConfigurationService.registerConfigItem(createConfigItem(item));
                registered++;
            }
        } else {
            log.warn("Item {} is not registered skipping", item.getName());
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("storedConfigPoller() Polling found {} config item(s) (from {} to {}), {} item(s) registered",
                polled.size(),
                dtf.format(then),
                dtf.format(now),
                registered);
    }

    return now;
}
 
Example 14
Source File: TCKZonedDateTime.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_minusSeconds_seconds() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.minusSeconds(1);
    assertEquals(test, ZonedDateTime.of(ldt.minusSeconds(1), ZONE_0100));
}
 
Example 15
Source File: TCKZonedDateTime.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_minusSeconds_seconds() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.minusSeconds(1);
    assertEquals(test, ZonedDateTime.of(ldt.minusSeconds(1), ZONE_0100));
}
 
Example 16
Source File: TCKZonedDateTime.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_minusSeconds_seconds() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.minusSeconds(1);
    assertEquals(test, ZonedDateTime.of(ldt.minusSeconds(1), ZONE_0100));
}
 
Example 17
Source File: TCKZonedDateTime.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_minusSeconds_seconds() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.minusSeconds(1);
    assertEquals(test, ZonedDateTime.of(ldt.minusSeconds(1), ZONE_0100));
}
 
Example 18
Source File: PeriodicNotificationApplicationIT.java    From rya with Apache License 2.0 4 votes vote down vote up
@Test
public void periodicApplicationWithAggTest() throws Exception {

    final String sparql = "prefix function: <http://org.apache.rya/function#> " // n
            + "prefix time: <http://www.w3.org/2006/time#> " // n
            + "select (count(?obs) as ?total) where {" // n
            + "Filter(function:periodic(?time, 1, .25, time:minutes)) " // n
            + "?obs <uri:hasTime> ?time. " // n
            + "?obs <uri:hasId> ?id } "; // n

    //make data
    final int periodMult = 15;
    final ValueFactory vf = SimpleValueFactory.getInstance();
    final DatatypeFactory dtf = DatatypeFactory.newInstance();
    //Sleep until current time aligns nicely with period to make
    //results more predictable
    while(System.currentTimeMillis() % (periodMult*1000) > 500) {
    }
    final ZonedDateTime time = ZonedDateTime.now();

    final ZonedDateTime zTime1 = time.minusSeconds(2*periodMult);
    final String time1 = zTime1.format(DateTimeFormatter.ISO_INSTANT);

    final ZonedDateTime zTime2 = zTime1.minusSeconds(periodMult);
    final String time2 = zTime2.format(DateTimeFormatter.ISO_INSTANT);

    final ZonedDateTime zTime3 = zTime2.minusSeconds(periodMult);
    final String time3 = zTime3.format(DateTimeFormatter.ISO_INSTANT);

    final Collection<Statement> statements = Sets.newHashSet(
            vf.createStatement(vf.createIRI("urn:obs_1"), vf.createIRI("uri:hasTime"),
                    vf.createLiteral(dtf.newXMLGregorianCalendar(time1))),
            vf.createStatement(vf.createIRI("urn:obs_1"), vf.createIRI("uri:hasId"), vf.createLiteral("id_1")),
            vf.createStatement(vf.createIRI("urn:obs_2"), vf.createIRI("uri:hasTime"),
                    vf.createLiteral(dtf.newXMLGregorianCalendar(time2))),
            vf.createStatement(vf.createIRI("urn:obs_2"), vf.createIRI("uri:hasId"), vf.createLiteral("id_2")),
            vf.createStatement(vf.createIRI("urn:obs_3"), vf.createIRI("uri:hasTime"),
                    vf.createLiteral(dtf.newXMLGregorianCalendar(time3))),
            vf.createStatement(vf.createIRI("urn:obs_3"), vf.createIRI("uri:hasId"), vf.createLiteral("id_3")));

    try (FluoClient fluo = FluoClientFactory.getFluoClient(conf.getFluoAppName(), Optional.of(conf.getFluoTableName()), conf)) {
        final Connector connector = ConfigUtils.getConnector(conf);
        final PeriodicQueryResultStorage storage = new AccumuloPeriodicQueryResultStorage(connector, conf.getTablePrefix());
        final CreatePeriodicQuery periodicQuery = new CreatePeriodicQuery(fluo, storage);
        final String id = FluoQueryUtils.convertFluoQueryIdToPcjId(periodicQuery.createPeriodicQuery(sparql, registrar).getQueryId());
        addData(statements);
        app.start();

        final Multimap<Long, BindingSet> expected = HashMultimap.create();
        try (KafkaConsumer<String, BindingSet> consumer = new KafkaConsumer<>(kafkaProps, new StringDeserializer(), new BindingSetSerDe())) {
            consumer.subscribe(Arrays.asList(id));
            final long end = System.currentTimeMillis() + 4*periodMult*1000;
            long lastBinId = 0L;
            long binId = 0L;
            final List<Long> ids = new ArrayList<>();
            while (System.currentTimeMillis() < end) {
                final ConsumerRecords<String, BindingSet> records = consumer.poll(periodMult*1000);
                for(final ConsumerRecord<String, BindingSet> record: records){
                    final BindingSet result = record.value();
                    binId = Long.parseLong(result.getBinding(IncrementalUpdateConstants.PERIODIC_BIN_ID).getValue().stringValue());
                    if(lastBinId != binId) {
                        lastBinId = binId;
                        ids.add(binId);
                    }
                    expected.put(binId, result);
                }
            }

            Assert.assertEquals(3, expected.asMap().size());
            int i = 0;
            for(final Long ident: ids) {
                Assert.assertEquals(1, expected.get(ident).size());
                final BindingSet bs = expected.get(ident).iterator().next();
                final Value val = bs.getValue("total");
                final int total = Integer.parseInt(val.stringValue());
                Assert.assertEquals(3-i, total);
                i++;
            }
        }


        final Set<BindingSet> expectedResults = new HashSet<>();
        try (CloseableIterator<BindingSet> results = storage.listResults(id, Optional.empty())) {
            results.forEachRemaining(x -> expectedResults.add(x));
            Assert.assertEquals(0, expectedResults.size());
        }
    }

}
 
Example 19
Source File: PeriodicNotificationApplicationIT.java    From rya with Apache License 2.0 4 votes vote down vote up
@Test
public void periodicApplicationTest() throws Exception {

    final String sparql = "prefix function: <http://org.apache.rya/function#> " // n
            + "prefix time: <http://www.w3.org/2006/time#> " // n
            + "select ?obs ?id where {" // n
            + "Filter(function:periodic(?time, 1, .25, time:minutes)) " // n
            + "?obs <uri:hasTime> ?time. " // n
            + "?obs <uri:hasId> ?id } "; // n

    //make data
    final int periodMult = 15;
    final ValueFactory vf = SimpleValueFactory.getInstance();
    final DatatypeFactory dtf = DatatypeFactory.newInstance();
    //Sleep until current time aligns nicely with period to make
    //results more predictable
    while(System.currentTimeMillis() % (periodMult*1000) > 500) {
    }
    final ZonedDateTime time = ZonedDateTime.now();

    final ZonedDateTime zTime1 = time.minusSeconds(2*periodMult);
    final String time1 = zTime1.format(DateTimeFormatter.ISO_INSTANT);

    final ZonedDateTime zTime2 = zTime1.minusSeconds(periodMult);
    final String time2 = zTime2.format(DateTimeFormatter.ISO_INSTANT);

    final ZonedDateTime zTime3 = zTime2.minusSeconds(periodMult);
    final String time3 = zTime3.format(DateTimeFormatter.ISO_INSTANT);

    final Collection<Statement> statements = Sets.newHashSet(
            vf.createStatement(vf.createIRI("urn:obs_1"), vf.createIRI("uri:hasTime"),
                    vf.createLiteral(dtf.newXMLGregorianCalendar(time1))),
            vf.createStatement(vf.createIRI("urn:obs_1"), vf.createIRI("uri:hasId"), vf.createLiteral("id_1")),
            vf.createStatement(vf.createIRI("urn:obs_2"), vf.createIRI("uri:hasTime"),
                    vf.createLiteral(dtf.newXMLGregorianCalendar(time2))),
            vf.createStatement(vf.createIRI("urn:obs_2"), vf.createIRI("uri:hasId"), vf.createLiteral("id_2")),
            vf.createStatement(vf.createIRI("urn:obs_3"), vf.createIRI("uri:hasTime"),
                    vf.createLiteral(dtf.newXMLGregorianCalendar(time3))),
            vf.createStatement(vf.createIRI("urn:obs_3"), vf.createIRI("uri:hasId"), vf.createLiteral("id_3")));

    try (FluoClient fluo = FluoClientFactory.getFluoClient(conf.getFluoAppName(), Optional.of(conf.getFluoTableName()), conf)) {
        final Connector connector = ConfigUtils.getConnector(conf);
        final PeriodicQueryResultStorage storage = new AccumuloPeriodicQueryResultStorage(connector, conf.getTablePrefix());
        final CreatePeriodicQuery periodicQuery = new CreatePeriodicQuery(fluo, storage);
        final String id = FluoQueryUtils.convertFluoQueryIdToPcjId(periodicQuery.createPeriodicQuery(sparql, registrar).getQueryId());
        addData(statements);
        app.start();

        final Multimap<Long, BindingSet> expected = HashMultimap.create();
        try (KafkaConsumer<String, BindingSet> consumer = new KafkaConsumer<>(kafkaProps, new StringDeserializer(), new BindingSetSerDe())) {
            consumer.subscribe(Arrays.asList(id));
            final long end = System.currentTimeMillis() + 4*periodMult*1000;
            long lastBinId = 0L;
            long binId = 0L;
            final List<Long> ids = new ArrayList<>();
            while (System.currentTimeMillis() < end) {
                final ConsumerRecords<String, BindingSet> records = consumer.poll(periodMult*1000);
                for(final ConsumerRecord<String, BindingSet> record: records){
                    final BindingSet result = record.value();
                    binId = Long.parseLong(result.getBinding(IncrementalUpdateConstants.PERIODIC_BIN_ID).getValue().stringValue());
                    if(lastBinId != binId) {
                        lastBinId = binId;
                        ids.add(binId);
                    }
                    expected.put(binId, result);
                }
            }

            Assert.assertEquals(3, expected.asMap().size());
            int i = 0;
            for(final Long ident: ids) {
                Assert.assertEquals(3-i, expected.get(ident).size());
                i++;
            }
        }


        final Set<BindingSet> expectedResults = new HashSet<>();
        try (CloseableIterator<BindingSet> results = storage.listResults(id, Optional.empty())) {
            results.forEachRemaining(x -> expectedResults.add(x));
            Assert.assertEquals(0, expectedResults.size());
        }
    }

}
 
Example 20
Source File: DateTimeExtensions.java    From groovy with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a {@link java.time.ZonedDateTime} that is {@code seconds} seconds before this date/time.
 *
 * @param self    a ZonedDateTime
 * @param seconds the number of seconds to subtract
 * @return a ZonedDateTime
 * @since 2.5.0
 */
public static ZonedDateTime minus(final ZonedDateTime self, long seconds) {
    return self.minusSeconds(seconds);
}