Example usage for java.time ZoneId of

List of usage examples for java.time ZoneId of

Introduction

In this page you can find the example usage for java.time ZoneId of.

Prototype

public static ZoneId of(String zoneId) 

Source Link

Document

Obtains an instance of ZoneId from an ID ensuring that the ID is valid and available for use.

Usage

From source file:defaultmethods.TimeClient.java

static ZoneId getZoneId(String zoneString) {
    try {/*from   w w  w  .j a  v a2 s  .c  om*/
        return ZoneId.of(zoneString);
    } catch (DateTimeException e) {
        System.err.println("Invalid time zone: " + zoneString + "; using default time zone instead.");
        return ZoneId.systemDefault();
    }
}

From source file:com.github.shredder121.testannotations.timezone.TimeZoneRule.java

@IgnoreJRERequirement //conditionally executed
private static TimeZone getTimeZoneJavaTime(String id) {
    return TimeZone.getTimeZone(ZoneId.of(id));
}

From source file:com.inversoft.json.ZoneIdDeserializer.java

@Override
public ZoneId deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    return ZoneId.of(jp.getText());
}

From source file:com.khartec.waltz.model.accesslog.AccessLog.java

@Value.Default
public LocalDateTime createdAt() {
    return LocalDateTime.now(ZoneId.of("UTC"));
}

From source file:dhbw.clippinggorilla.external.mailserver.MailUtils.java

public static void sendClipping(Clipping clipping) {
    User user = UserUtils.getUser(clipping.getUserid());
    String email = user.getEmail();
    String html = CLIPPING_ROOT_HTML;
    String rows = "";
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd. LLLL. yyyy");
    formatter.withZone(ZoneId.of("Europe/Berlin"));

    rows = clipping.getArticles().entrySet().stream().map((entry) -> {
        InterestProfile userprofile = entry.getKey();
        LinkedHashSet<Article> articleSet = entry.getValue();
        String profileRow = CLIPPING_GROUP_HTML.replace("[GROUPNAME]", userprofile.getName());
        String articleRows = articleSet.stream()
                .map((article) -> CLIPPING_ARTICLE_HTML
                        .replace("[ARTICLE_IMAGE_URL]",
                                article.getUrlToImage().isEmpty()
                                        ? article.getSourceAsSource().getLogo().toExternalForm()
                                        : article.getUrlToImage())
                        .replace("[ARTICLE_TITLE]", article.getTitle())
                        .replace("[ARTICLE_DESCRIPTION]",
                                article.getDescription().length() > 400
                                        ? article.getDescription().substring(0, 400) + "..."
                                        : article.getDescription())
                        .replace("[SOURCE_NAME]", article.getSourceAsSource().getName())
                        .replace("[ARTICLE_DATE]",
                                article.getPublishedAtAsLocalDateTime().toLocalDate().format(formatter))
                        .replace("[AUTHOR]", article.getAuthor()))
                .reduce("", String::concat);
        return profileRow + "\n" + articleRows;
    }).reduce(rows, String::concat);

    rows = clipping.getArticlesFromGroup().entrySet().stream().map((entry) -> {
        GroupInterestProfile groupprofile = entry.getKey();
        LinkedHashSet<Article> articleSet = entry.getValue();
        String profileRow = CLIPPING_GROUP_HTML.replace("[GROUPNAME]", groupprofile.getName());
        String articleRows = articleSet.stream()
                .map((article) -> CLIPPING_ARTICLE_HTML
                        .replace("[ARTICLE_IMAGE_URL]",
                                article.getUrlToImage().isEmpty()
                                        ? article.getSourceAsSource().getLogo().toExternalForm()
                                        : article.getUrlToImage())
                        .replace("[ARTICLE_TITLE]", article.getTitle())
                        .replace("[ARTICLE_DESCRIPTION]",
                                article.getDescription().length() > 400
                                        ? article.getDescription().substring(0, 400) + "..."
                                        : article.getDescription())
                        .replace("[SOURCE_NAME]", article.getSourceAsSource().getName())
                        .replace("[ARTICLE_DATE]",
                                article.getPublishedAtAsLocalDateTime().toLocalDate().format(formatter))
                        .replace("[AUTHOR]", article.getAuthor()))
                .reduce("", String::concat);
        return profileRow + "\n" + articleRows;
    }).reduce(rows, String::concat);

    String clippingText = Language.get(Word.CLIPPING_TEXT).replace("[FIRSTNAME]", user.getFirstName())
            .replace("[LASTNAME]", user.getLastName()).replace("[DATE]", clipping.getDate().format(formatter));
    html = html.replace("[CLIPPING_TEXT]", clippingText).replace("[GROUPS]", rows);
    //        try {
    //            Files.write(Paths.get(System.getProperty("user.home"), "Desktop", "email.html"), html.getBytes("UTF-8"));
    //        } catch (IOException ex) {
    //            Logger.getLogger(MailUtils.class.getName()).log(Level.SEVERE, null, ex);
    //        }/*  w w w  . j a va2 s.c om*/
    try {
        Mail.send(email, "ClippingGorilla Clippings", "Your email client does not support HTML messages", html);
    } catch (EmailException ex) {
        Log.error("Could not send Clipping to user " + user.getFirstName() + " " + user.getLastName() + " ("
                + user.getUsername() + ")", ex);
    }
}

From source file:com.example.hello.HelloEndpoint.java

Mono<ServerResponse> hello(final ServerRequest serverRequest) {
    return ServerResponse.ok().contentType(MediaType.APPLICATION_JSON)
            .body(Mono.just(new HelloMessage("hello", OffsetDateTime.now(ZoneId.of("Z")))), HelloMessage.class);
}

From source file:de.rkl.tools.tzconv.configuration.ApplicationConfiguration.java

public List<ZoneId> getDefaultSelectedZoneIds() {
    return configuration.getList("defaultSelectedZoneIds.selectedZoneId[@id]").stream()
            .map(selectedZoneId -> ZoneId.of(selectedZoneId.toString())).collect(toList());
}

From source file:fr.javatic.mongo.jacksonCodec.javaTime.deserializers.ZonedDateTimeDeserializer.java

@Override
public ZonedDateTime deserialize(BsonParser bsonParser, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    if (bsonParser.getCurrentToken() != JsonToken.VALUE_EMBEDDED_OBJECT
            || bsonParser.getCurrentBsonType() != BsonConstants.TYPE_DATETIME) {
        throw ctxt.mappingException(Date.class);
    }/*  ww w .j  a v  a  2  s  .  c o  m*/

    Object obj = bsonParser.getEmbeddedObject();
    if (obj == null) {
        return null;
    }

    Date dt = (Date) obj;
    return Instant.ofEpochMilli(dt.getTime()).atZone(ZoneId.of("UTC"));
}

From source file:fi.helsinki.opintoni.service.TimeService.java

public LocalDateTime endOfDayHelsinki(LocalDateTime fromLocalDateTime) {
    ZonedDateTime zonedDateTime = fromLocalDateTime.atZone(HELSINKI_ZONE_ID).withHour(23).withMinute(59)
            .withSecond(59);//from   w w w  .j  av  a  2s  .  c  om
    return LocalDateTime.ofInstant(zonedDateTime.toInstant(), ZoneId.of("UTC"));
}

From source file:com.github.ibm.domino.resource.EventTime.java

public void setDateTime(ZonedDateTime zonedDateTime) {
    String s = zonedDateTime.withZoneSameInstant(ZoneId.of("GMT")).toString();
    seteDate(s.substring(0, 10));/*from w  ww .j a v  a 2 s  .c o m*/
    seteTime(s.substring(11, 19));
    setUtc(true);
}