Example usage for java.util GregorianCalendar getTimeInMillis

List of usage examples for java.util GregorianCalendar getTimeInMillis

Introduction

In this page you can find the example usage for java.util GregorianCalendar getTimeInMillis.

Prototype

public long getTimeInMillis() 

Source Link

Document

Returns this Calendar's time value in milliseconds.

Usage

From source file:org.sakaiproject.nakamura.cluster.ClusterTrackingServiceImpl.java

/**
 * Constructor for testing purposes only.
 *
 * @param cacheManagerService2//  w ww . j a va  2  s .c om
 */
protected ClusterTrackingServiceImpl(CacheManagerService cacheManagerService) {
    this.cacheManagerService = cacheManagerService;
    GregorianCalendar calendar = new GregorianCalendar(2009, 8, 22);
    epoch = calendar.getTimeInMillis();

}

From source file:org.outermedia.solrfusion.SolrFusionServletTest.java

@Test
public void testConfigReload() throws ServletException, IOException, InterruptedException {
    TestSolrFusionServlet servlet = new TestSolrFusionServlet();
    GregorianCalendar currentCal = new GregorianCalendar(2014, 6, 3, 12, 0, 0);
    long startTime = currentCal.getTimeInMillis();
    servlet.currentTime = startTime;/*  w ww .  ja v  a 2s .  c o  m*/
    File tmpSchema = File.createTempFile("test-schema-", ".xml", new File("target/test-classes"));
    FileUtils.copyFile(new File("target/test-classes/test-fusion-schema.xml"), tmpSchema);
    FileUtils.touch(tmpSchema);
    servlet.loadSolrFusionConfig(tmpSchema.getName(), false);
    Configuration oldCfg = servlet.getCfg();
    Assert.assertNotNull("Solr Fusion schema not loaded", oldCfg);

    // try to re-load immediately, which should be done after 5 minutes only
    log.info("----1");
    servlet.loadSolrFusionConfig(tmpSchema.getName(), false);
    Assert.assertEquals("Solr Fusion schema re-loaded", oldCfg, servlet.getCfg());

    // 6 minutes in the future, without schema modifications, nothing should happen
    currentCal.add(Calendar.MINUTE, 6);
    servlet.currentTime = currentCal.getTimeInMillis();
    log.info("----2");
    servlet.loadSolrFusionConfig(tmpSchema.getName(), false);
    Assert.assertEquals("Solr Fusion schema re-loaded", oldCfg, servlet.getCfg());

    // 6 minutes in the future with schema modifications
    servlet.setSolrFusionSchemaLoadTime(startTime); // modified after loadSolrFusionConfig() call
    Thread.sleep(1001); // await new time
    FileUtils.touch(tmpSchema);
    log.info("----3");
    servlet.loadSolrFusionConfig(tmpSchema.getName(), false);
    Assert.assertNotSame("Solr Fusion schema not re-loaded", oldCfg, servlet.getCfg());
    oldCfg = servlet.getCfg();

    // force re-load
    currentCal.add(Calendar.MINUTE, 1);
    servlet.currentTime = currentCal.getTimeInMillis();
    log.info("----4");
    servlet.loadSolrFusionConfig(tmpSchema.getName(), false);
    Assert.assertEquals("Solr Fusion schema re-loaded", oldCfg, servlet.getCfg());
    log.info("----5");
    servlet.loadSolrFusionConfig(tmpSchema.getName(), true);
    Assert.assertNotSame("Solr Fusion schema not re-loaded", oldCfg, servlet.getCfg());
}

From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.operations.FetchActivityOperation.java

private boolean needsAnotherFetch(GregorianCalendar lastSyncTimestamp) {
    if (fetchCount > 5) {
        LOG.warn("Already jave 5 fetch rounds, not doing another one.");
        return false;
    }//from ww w .  jav a2s  . com

    if (DateUtils.isToday(lastSyncTimestamp.getTimeInMillis())) {
        LOG.info("Hopefully no further fetch needed, last synced timestamp is from today.");
        return false;
    }
    if (lastSyncTimestamp.getTimeInMillis() > System.currentTimeMillis()) {
        LOG.warn("Not doing another fetch since last synced timestamp is in the future: "
                + DateTimeUtils.formatDateTime(lastSyncTimestamp.getTime()));
        return false;
    }
    LOG.info("Doing another fetch since last sync timestamp is still too old: "
            + DateTimeUtils.formatDateTime(lastSyncTimestamp.getTime()));
    return true;
}

From source file:org.callimachusproject.behaviours.SqlDatasourceSupport.java

private void setValue(PreparedStatement insert, int col, Value value, Integer type) throws SQLException {
    if (value == null) {
        insert.setNull(col, type);/*  www  . j ava2 s .  co m*/
    } else if (value instanceof Literal) {
        Literal lit = (Literal) value;
        URI datatype = lit.getDatatype();
        if (datatype == null) {
            insert.setString(col, value.stringValue());
        } else if (XMLDatatypeUtil.isCalendarDatatype(datatype)) {
            GregorianCalendar cal = lit.calendarValue().toGregorianCalendar();
            insert.setDate(col, new java.sql.Date(cal.getTimeInMillis()), cal);
        } else {
            insert.setString(col, value.stringValue());
        }
    } else {
        insert.setString(col, value.stringValue());
    }
}

From source file:org.apache.juddi.validation.ValidateSubscription.java

public void validateGetSubscriptionResults(EntityManager em, GetSubscriptionResults body)
        throws DispositionReportFaultMessage {
    // No null input
    if (body == null) {
        throw new FatalErrorException(new ErrorMessage("errors.NullInput"));
    }/*from  w  w w . j  av a 2  s  .co  m*/

    String subscriptionKey = body.getSubscriptionKey();
    if (subscriptionKey == null || subscriptionKey.length() == 0) {
        throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.NullKey", subscriptionKey));
    }

    // Per section 4.4: keys must be case-folded
    subscriptionKey = subscriptionKey.toLowerCase();
    body.setSubscriptionKey(subscriptionKey);

    Object obj = em.find(org.apache.juddi.model.Subscription.class, subscriptionKey);
    if (obj == null) {
        throw new InvalidKeyPassedException(
                new ErrorMessage("errors.invalidkey.SubscriptionNotFound", subscriptionKey));
    }

    Date expiresAfter = ((org.apache.juddi.model.Subscription) obj).getExpiresAfter();
    Date now = new Date();
    if (expiresAfter.getTime() < now.getTime()) {
        throw new InvalidKeyPassedException(
                new ErrorMessage("errors.getsubscriptionresult.SubscriptionExpired", subscriptionKey));
    }

    CoveragePeriod coveragePeriod = body.getCoveragePeriod();
    if (coveragePeriod == null) {
        throw new InvalidTimeException(new ErrorMessage("errors.getsubscriptionresult.NullCoveragePeriod"));
    }

    if (coveragePeriod.getStartPoint() == null || coveragePeriod.getEndPoint() == null) {
        throw new InvalidTimeException(
                new ErrorMessage("errors.getsubscriptionresult.InvalidDateInCoveragePeriod"));
    }

    GregorianCalendar startPoint = coveragePeriod.getStartPoint().toGregorianCalendar();
    GregorianCalendar endPoint = coveragePeriod.getEndPoint().toGregorianCalendar();
    if (startPoint.getTimeInMillis() > endPoint.getTimeInMillis()) {
        throw new InvalidTimeException(new ErrorMessage("errors.getsubscriptionresult.StartPointAfterEndPoint",
                startPoint.toString()));
    }
}

From source file:com.projity.interval.ValueObjectForIntervalTable.java

/**
 * Create a new entry one year later//from  www .  jav  a2  s .c o m
 */
public Object createUnvalidatedObject(NodeModel nodeModel, Object parent) {
    long baseDate = DateTime.midnightToday();
    ValueObjectForInterval last = (ValueObjectForInterval) valueObjects.get(valueObjects.size() - 1); // get last one
    baseDate = Math.max(baseDate, last.getStart()); // latest of today or last entry
    GregorianCalendar cal = DateTime.calendarInstance();
    cal.setTimeInMillis(baseDate);
    cal.roll(GregorianCalendar.YEAR, true); // one year later than last one's start or today
    long date = cal.getTimeInMillis();
    try {
        return newValueObject(date);
    } catch (InvalidValueObjectForIntervalException e) {
        // TODO Auto-generated catch block
        e.printStackTrace(); // should not ever happen
        return null;
    }
}

From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.operations.FetchActivityOperation.java

private GregorianCalendar saveSamples() {
    if (samples.size() > 0) {
        // save all the samples that we got
        try (DBHandler handler = GBApplication.acquireDB()) {
            DaoSession session = handler.getDaoSession();
            SampleProvider<MiBandActivitySample> sampleProvider = new MiBandSampleProvider(getDevice(),
                    session);// ww  w .  j  ava 2 s . c  om
            Device device = DBHelper.getDevice(getDevice(), session);
            User user = DBHelper.getUser(session);

            GregorianCalendar timestamp = (GregorianCalendar) startTimestamp.clone();
            for (MiBandActivitySample sample : samples) {
                sample.setDevice(device);
                sample.setUser(user);
                sample.setTimestamp((int) (timestamp.getTimeInMillis() / 1000));
                sample.setProvider(sampleProvider);

                if (LOG.isDebugEnabled()) {
                    //                        LOG.debug("sample: " + sample);
                }

                timestamp.add(Calendar.MINUTE, 1);
            }
            sampleProvider.addGBActivitySamples(samples.toArray(new MiBandActivitySample[0]));

            saveLastSyncTimestamp(timestamp);
            LOG.info("Mi2 activity data: last sample timestamp: "
                    + DateTimeUtils.formatDateTime(timestamp.getTime()));
            return timestamp;

        } catch (Exception ex) {
            GB.toast(getContext(), "Error saving activity samples", Toast.LENGTH_LONG, GB.ERROR);
        } finally {
            samples.clear();
        }
    }
    return null;
}

From source file:br.gov.frameworkdemoiselle.internal.configuration.ConfigurationLoaderWithListTest.java

@Test
public void testConfigurationPropertiesWithDateList() {
    ConfigurationPropertiesWithList config = prepareConfigurationPropertiesWithList();

    Date dateValue = config.dateList.get(0);

    GregorianCalendar calendar = new GregorianCalendar(2012, Calendar.AUGUST, 14, 18, 10, 50);

    Date date = new Date(calendar.getTimeInMillis());

    assertEquals(Date.class, dateValue.getClass());
    assertEquals(date.getTime(), dateValue.getTime());
    assertEquals(3, config.dateList.size());
}

From source file:br.gov.frameworkdemoiselle.internal.configuration.ConfigurationLoaderWithListTest.java

@Test
public void testConfigurationXMLWithDateList() {
    ConfigurationXMLWithList config = prepareConfigurationXMLWithList();

    Date dateValue = config.dateList.get(0);

    GregorianCalendar calendar = new GregorianCalendar(2012, Calendar.AUGUST, 14, 18, 10, 50);

    Date date = new Date(calendar.getTimeInMillis());

    assertEquals(Date.class, dateValue.getClass());
    assertEquals(date.getTime(), dateValue.getTime());
    assertEquals(3, config.dateList.size());
}

From source file:br.gov.frameworkdemoiselle.internal.configuration.ConfigurationLoaderWithArrayTest.java

@Test
public void testConfigurationPropertiesWithDateArray() {
    ConfigurationPropertiesWithArray config = prepareConfigurationPropertiesWithArray();

    Date dateValue = config.dateArray[0];

    GregorianCalendar calendar = new GregorianCalendar(2012, Calendar.AUGUST, 14, 18, 10, 50);

    Date date = new Date(calendar.getTimeInMillis());

    assertEquals(Date.class, dateValue.getClass());
    assertEquals(date.getTime(), dateValue.getTime());
    assertEquals(3, config.dateArray.length);
}