Example usage for java.time ZoneOffset UTC

List of usage examples for java.time ZoneOffset UTC

Introduction

In this page you can find the example usage for java.time ZoneOffset UTC.

Prototype

ZoneOffset UTC

To view the source code for java.time ZoneOffset UTC.

Click Source Link

Document

The time-zone offset for UTC, with an ID of 'Z'.

Usage

From source file:org.bedework.synch.cnctrs.orgSyncV2.OrgSyncV2ConnectorInstance.java

private IcalendarType toXcal(final List<OrgSyncV2Event> osEvents, final boolean onlyPublic) {
    final IcalendarType ical = new IcalendarType();
    final VcalendarType vcal = new VcalendarType();

    ical.getVcalendar().add(vcal);/*from  w ww  .j  av a2 s.c o m*/

    vcal.setProperties(new ArrayOfProperties());
    final List<JAXBElement<? extends BasePropertyType>> vcalProps = vcal.getProperties()
            .getBasePropertyOrTzid();

    final VersionPropType vers = new VersionPropType();
    vers.setText("2.0");
    vcalProps.add(of.createVersion(vers));

    final ProdidPropType prod = new ProdidPropType();
    prod.setText("//Bedework.org//BedeWork V3.11.1//EN");
    vcalProps.add(of.createProdid(prod));

    final ArrayOfComponents aoc = new ArrayOfComponents();
    vcal.setComponents(aoc);

    for (final OrgSyncV2Event osev : osEvents) {
        if (onlyPublic && !osev.getIsPublic()) {
            continue;
        }

        final VeventType ev = new VeventType();

        aoc.getBaseComponent().add(of.createVevent(ev));

        ev.setProperties(new ArrayOfProperties());
        final List<JAXBElement<? extends BasePropertyType>> evProps = ev.getProperties()
                .getBasePropertyOrTzid();

        final UidPropType uid = new UidPropType();
        uid.setText(config.getUidPrefix() + "-" + osev.getId());
        evProps.add(of.createUid(uid));

        final DtstampPropType dtstamp = new DtstampPropType();
        try {
            //Get todays date
            final ZonedDateTime today = ZonedDateTime.now(ZoneOffset.UTC);
            final String todayStr = today.format(DateTimeFormatter.ISO_INSTANT);

            dtstamp.setUtcDateTime(XcalUtil.getXMlUTCCal(todayStr));
            evProps.add(of.createDtstamp(dtstamp));

            final CreatedPropType created = new CreatedPropType();
            created.setUtcDateTime(XcalUtil.getXMlUTCCal(todayStr));
            evProps.add(of.createCreated(created));

            final SummaryPropType sum = new SummaryPropType();
            sum.setText(osev.getName());
            evProps.add(of.createSummary(sum));

            final DescriptionPropType desc = new DescriptionPropType();
            desc.setText(osev.getDescription());
            evProps.add(of.createDescription(desc));

            final LocationPropType l = new LocationPropType();
            l.setText(osev.getLocation());
            evProps.add(of.createLocation(l));

            if (info.getLocationKey() != null) {
                final XBedeworkLocKeyParamType par = of.createXBedeworkLocKeyParamType();

                par.setText(info.getLocationKey());
                l.setParameters(new ArrayOfParameters());
                l.getParameters().getBaseParameter().add(of.createXBedeworkLocKey(par));
            }
        } catch (final Throwable t) {
            error(t);
            continue;
        }

        if (osev.getCategory() != null) {
            final CategoriesPropType cat = new CategoriesPropType();
            cat.getText().add(osev.getCategory().getName());
            evProps.add(of.createCategories(cat));
        }

        /* The first (only) element of occurrences is the start/end of the
           event or master.
                
           If there are more occurrences these become rdates and the event is
           recurring.
         */

        if (Util.isEmpty(osev.getOccurrences())) {
            // warn?
            continue;
        }

        boolean first = true;
        for (final OrgSyncV2Occurrence occ : osev.getOccurrences()) {
            if (first) {
                final DtstartPropType dtstart = (DtstartPropType) makeDt(new DtstartPropType(),
                        occ.getStartsAt());
                evProps.add(of.createDtstart(dtstart));

                final DtendPropType dtend = (DtendPropType) makeDt(new DtendPropType(), occ.getEndsAt());
                evProps.add(of.createDtend(dtend));

                first = false;
                continue;
            }

            // Add an rdate
            // TODO - add duration if different from the master
            final RdatePropType rdate = (RdatePropType) makeDt(new RdatePropType(), occ.getStartsAt());
            evProps.add(of.createRdate(rdate));
        }
    }

    return ical;
}

From source file:com.example.geomesa.lambda.LambdaQuickStart.java

@Override
public void run() {
    try {//from   w w  w.j  av  a 2s . c o m
        // create the schema
        final String sftName = "lambda-quick-start";
        final String sftSchema = "name:String,age:Int,dtg:Date,*geom:Point:srid=4326";
        SimpleFeatureType sft = SimpleFeatureTypes.createType(sftName, sftSchema);

        if (ds.getSchema(sftName) != null) {
            out.println("'" + sftName + "' feature type already exists - quick start will not work correctly");
            out.println("Please delete it and re-run");
            return;
        }

        out.println("Creating feature type '" + sftName + "'");

        ds.createSchema(sft);

        out.println("Feature type created - register the layer '" + sftName
                + "' in geoserver then hit <enter> to continue");
        in.read();

        SimpleFeatureWriter writer = ds.getFeatureWriterAppend(sftName, Transaction.AUTO_COMMIT);

        out.println("Writing features to Kafka... refresh GeoServer layer preview to see changes");

        // creates and adds SimpleFeatures to the producer every 1/5th of a second

        final int COUNT = 1000;
        final int MIN_X = -180;
        final int MAX_X = 180;
        final int MIN_Y = -90;
        final int MAX_Y = 90;
        final int DX = 2;
        final String[] PEOPLE_NAMES = { "James", "John", "Peter", "Hannah", "Claire", "Gabriel" };
        final long SECONDS_PER_YEAR = 365L * 24L * 60L * 60L;
        ZonedDateTime MIN_DATE = ZonedDateTime.of(2015, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC);
        final Random random = new Random();

        int numUpdates = (MAX_X - MIN_X) / DX;
        for (int j = 0; j < numUpdates; j++) {
            for (int i = 0; i < COUNT; i++) {
                SimpleFeature feature = writer.next();
                feature.setAttribute(0, PEOPLE_NAMES[i % PEOPLE_NAMES.length]); // name
                feature.setAttribute(1, (int) Math.round(random.nextDouble() * 110)); // age
                feature.setAttribute(2, Date.from(MIN_DATE
                        .plusSeconds((int) Math.round(random.nextDouble() * SECONDS_PER_YEAR)).toInstant())); // dtg
                feature.setAttribute(3, "POINT(" + (MIN_X + (DX * j)) + " "
                        + (MIN_Y + ((MAX_Y - MIN_Y) / ((double) COUNT)) * i) + ")"); // geom
                feature.getUserData().put(Hints.PROVIDED_FID, String.format("%04d", i));
                writer.write();
            }
            Thread.sleep(200);
        }

        writer.close();

        out.println("Waiting for expiry and persistence...");

        long total = 0, persisted = 0;
        do {
            long newTotal = (long) ds.stats().getCount(sft, Filter.INCLUDE, true).get();
            long newPersisted = (long) ((AccumuloDataStore) ds.persistence()).stats()
                    .getCount(sft, Filter.INCLUDE, true).get();
            if (newTotal != total || newPersisted != persisted) {
                total = newTotal;
                persisted = newPersisted;
                out.println("Total features: " + total + ", features persisted to Accumulo: " + persisted);
            }
            Thread.sleep(100);
        } while (persisted < COUNT || total > COUNT);
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        ds.dispose();
    }
}

From source file:org.silverpeas.core.calendar.CalendarEventOccurrence.java

/**
 * Gets optionally an event occurrence from the specified data.
 * @param event an event./*from w  ww.  j  a v a2s .com*/
 * @param occurrenceStartDate a start date.
 * @return the computed occurrence identifier.
 */
public static Optional<CalendarEventOccurrence> getBy(CalendarEvent event, Temporal occurrenceStartDate) {
    Temporal startDate = occurrenceStartDate;
    if (startDate instanceof OffsetDateTime) {
        startDate = ((OffsetDateTime) occurrenceStartDate).atZoneSameInstant(ZoneOffset.UTC).toOffsetDateTime();
    }
    return getById(generateId(event, startDate));
}

From source file:com.epam.parso.impl.CSVDataWriterImpl.java

/**
 * The function to convert a Java 8 LocalDateTime into a string according to the format used.
 *
 * @param currentDate the LocalDateTime to convert.
 * @param format      the string with the format that must belong to the set of
 *                    {@link CSVDataWriterImpl#DATE_OUTPUT_FORMAT_STRINGS} mapping keys.
 * @return the string that corresponds to the date in the format used.
 *//*w w  w .j  a  v  a 2s  .c  om*/
protected static String convertLocalDateTimeElementToString(LocalDateTime currentDate, String format) {
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DATE_OUTPUT_FORMAT_STRINGS.get(format));
    String valueToPrint = "";
    ZonedDateTime zonedDateTime = currentDate.atZone(ZoneOffset.UTC);
    if (zonedDateTime.toInstant().toEpochMilli() != 0 && zonedDateTime.getNano() != 0) {
        valueToPrint = formatter.format(currentDate);
    }
    return valueToPrint;
}

From source file:org.openecomp.sdc.action.impl.ActionManagerImpl.java

/**
 * Get Current Timestamp in UTC format./*w  w  w.  j  a  va2s.co m*/
 *
 * @return Current Timestamp in UTC format.
 */
public static Date getCurrentTimeStampUtc() {
    return Date.from(java.time.ZonedDateTime.now(ZoneOffset.UTC).toInstant());
}

From source file:com.example.app.support.AppUtil.java

/**
 * Convert the given ZonedDateTime to a UTC date for persistence
 *
 * @param dt the ZonedDateTime to convert to UTC
 *
 * @return a Date object that represents the same instant as the ZonedDateTime, but at UTC.
 *///from   www .  j  av a2s  . c  om
@Nullable
public static Date convertForPersistence(@Nullable ZonedDateTime dt) {
    if (dt == null)
        return null;
    ZonedDateTime atUtc = dt.withZoneSameInstant(ZoneOffset.UTC);
    return new Date(atUtc.toInstant().toEpochMilli());
}

From source file:org.apache.metron.dataloads.nonbulk.geo.MaxmindDbEnrichmentLoader.java

protected void loadGeoLiteDatabase(CommandLine cli) throws IOException {
    // Retrieve the database file
    System.out.println("Retrieving GeoLite2 archive");

    String geo_url = GeoEnrichmentOptions.GEO_URL.get(cli, GEO_CITY_URL_DEFAULT);
    String asn_url = GeoEnrichmentOptions.ASN_URL.get(cli, ASN_URL_DEFAULT);

    String tmpDir = GeoEnrichmentOptions.TMP_DIR.get(cli, "/tmp") + "/"; // Make sure there's a file separator at the end
    int numRetries = Integer.parseInt(GeoEnrichmentOptions.RETRIES.get(cli, DEFAULT_RETRIES));
    File localGeoFile = null;//from w  w  w  . j  a v  a  2  s  . com
    File localAsnFile = null;
    try {
        localGeoFile = downloadGeoFile(geo_url, tmpDir, numRetries);
        localAsnFile = downloadGeoFile(asn_url, tmpDir, numRetries);
    } catch (IllegalStateException ies) {
        System.err.println("Failed to download geo db file. Aborting");
        System.exit(5);
    }
    // Want to delete the tar in event of failure
    localGeoFile.deleteOnExit();
    localAsnFile.deleteOnExit();
    System.out.println("GeoIP files downloaded successfully");

    // Push the Geo file to HDFS and update Configs to ensure clients get new view
    String zookeeper = GeoEnrichmentOptions.ZK_QUORUM.get(cli);
    long millis = LocalDateTime.now().toInstant(ZoneOffset.UTC).toEpochMilli();
    String hdfsGeoLoc = GeoEnrichmentOptions.REMOTE_GEO_DIR.get(cli, "/apps/metron/geo/" + millis);
    System.out.println("Putting GeoLite City file into HDFS at: " + hdfsGeoLoc);

    // Put Geo into HDFS
    Path srcPath = new Path(localGeoFile.getAbsolutePath());
    Path dstPath = new Path(hdfsGeoLoc);
    putDbFile(srcPath, dstPath);
    pushConfig(srcPath, dstPath, GeoLiteCityDatabase.GEO_HDFS_FILE, zookeeper);

    // Push the ASN file to HDFS and update Configs to ensure clients get new view
    String hdfsAsnLoc = GeoEnrichmentOptions.REMOTE_ASN_DIR.get(cli, "/apps/metron/asn/" + millis);
    System.out.println("Putting ASN file into HDFS at: " + hdfsAsnLoc);

    // Put ASN into HDFS
    srcPath = new Path(localAsnFile.getAbsolutePath());
    dstPath = new Path(hdfsAsnLoc);
    putDbFile(srcPath, dstPath);
    pushConfig(srcPath, dstPath, GeoLiteAsnDatabase.ASN_HDFS_FILE, zookeeper);

    System.out.println("GeoLite2 file placement complete");
    System.out.println("Successfully created and updated new GeoLite information");
}

From source file:com.example.app.support.AppUtil.java

/**
 * Convert the given Date from UTC to a ZonedDateTime at the given TimeZone
 *
 * @param date the UTC date/*from w  ww.  j av a2s.co  m*/
 * @param zone the TimeZone to convert the time to
 *
 * @return a ZonedDateTime that represents the same instant as the UTC date, but at the given TimeZone.
 */
@Nullable
public static ZonedDateTime convertFromPersisted(@Nullable Date date, @Nullable TimeZone zone) {
    if (date == null || zone == null)
        return null;
    ZonedDateTime from = ZonedDateTime.ofInstant(date.toInstant(), ZoneOffset.UTC);
    return from.withZoneSameInstant(zone.toZoneId());
}

From source file:org.openmhealth.shim.jawbone.mapper.JawboneDataPointMapper.java

/**
 * Translates a time zone descriptor from one of various representations (Olson, seconds offset, GMT offset) into a
 * {@link ZoneId}.//from  w  w w.j  a  va 2  s.c om
 *
 * @param timeZoneValueNode the value associated with a timezone property
 */
static ZoneId parseZone(JsonNode timeZoneValueNode) {

    // default to UTC if timezone is not present
    if (timeZoneValueNode.isNull()) {
        return ZoneOffset.UTC;
    }

    // "-25200"
    if (timeZoneValueNode.asInt() != 0) {
        ZoneOffset zoneOffset = ZoneOffset.ofTotalSeconds(timeZoneValueNode.asInt());

        // TODO confirm if this is even necessary, since ZoneOffset is a ZoneId
        return ZoneId.ofOffset("GMT", zoneOffset);
    }

    // e.g., "GMT-0700" or "America/Los_Angeles"
    if (timeZoneValueNode.isTextual()) {
        return ZoneId.of(timeZoneValueNode.textValue());
    }

    throw new IllegalArgumentException(format("The time zone node '%s' can't be parsed.", timeZoneValueNode));
}

From source file:arxiv.xml.XMLParser.java

/**
 * Parse the response date.  The result will be in UTC.
 *///from   w ww . j av  a 2s.  co  m
private ZonedDateTime parseResponseDate(XMLGregorianCalendar xmlGregorianCalendar) {
    return xmlGregorianCalendar.toGregorianCalendar().toZonedDateTime().withZoneSameInstant(ZoneOffset.UTC);
}