Example usage for java.time Clock systemDefaultZone

List of usage examples for java.time Clock systemDefaultZone

Introduction

In this page you can find the example usage for java.time Clock systemDefaultZone.

Prototype

public static Clock systemDefaultZone() 

Source Link

Document

Obtains a clock that returns the current instant using the best available system clock, converting to date and time using the default time-zone.

Usage

From source file:Main.java

public static void main(String[] args) {
    Clock utcClock = Clock.systemUTC();
    Clock defaultClock = Clock.systemDefaultZone();
    Clock offsetClock = Clock.offset(Clock.systemUTC(), Duration.ofHours(-5));

    ZoneId denverTimeZone = ZoneId.of("America/Denver");
    ZoneId newYorkTimeZone = ZoneId.of("America/New_York");
    ZoneId chicagoTimeZone = ZoneId.of("America/Chicago");
    ZoneId losAngelesTimeZone = ZoneId.of("America/Los_Angeles");

    Instant instant = Instant.now(defaultClock);
    Instant instant2 = Instant.now(utcClock);
    Instant instant3 = Instant.now(offsetClock);

    System.out.println(instant);/*from   ww  w .j a  v a  2  s  .co m*/
    System.out.println(instant2);
    System.out.println(instant3.plus(Duration.ofSeconds(90)));
    System.out.println(instant3.atZone(newYorkTimeZone));
    System.out.println(instant3.atZone(chicagoTimeZone));
    System.out.println(instant3.atZone(denverTimeZone));
    System.out.println(instant3.atZone(losAngelesTimeZone));
}

From source file:Main.java

public static void main(String[] args) {
    Clock defaultClock = Clock.systemDefaultZone();

    Instant instant = Instant.now(defaultClock);

    TemporalQuery query = (TemporalAccessor x) -> x.isSupported(ChronoField.MILLI_OF_DAY);

    System.out.println(instant.query(query));
}

From source file:cz.muni.fi.javaseminar.kafa.bookregister.gui.backend.BackendService.java

public static AuthorManager getAuthorManager() {
    if (bookManager == null) {
        dataSource = CTX.getBean(DataSource.class);
        authorManager = new AuthorManagerImpl();
        authorManager.setClock(Clock.systemDefaultZone());
        authorManager.setDataSource(dataSource);
        log.info("Inicializing AuthorManager");
    }/*  www  .j ava2  s  .  c  o m*/
    return authorManager;
}

From source file:com.kazuki43zoo.jpetstore.config.ApplicationConfig.java

@Bean
protected Clock clock() {
    return Clock.systemDefaultZone();
}

From source file:com.netflix.spinnaker.igor.config.LockManagerConfig.java

@Bean
Clock clock() {
    return Clock.systemDefaultZone();
}

From source file:com.create.application.configuration.IntegrationConfiguration.java

@Bean
public Clock clock() {
    return Clock.systemDefaultZone();
}

From source file:org.hawkular.apm.server.elasticsearch.ConfigurationServiceElasticsearch.java

public ConfigurationServiceElasticsearch() {
    super();
    this.clock = Clock.systemDefaultZone();
}

From source file:net.morimekta.idltool.IdlUtils.java

public static String formatAgo(long timestamp) {
    Instant instant = Instant.ofEpochSecond(timestamp / 1000);
    LocalDateTime local = instant.atZone(Clock.systemUTC().getZone())
            .withZoneSameInstant(Clock.systemDefaultZone().getZone()).toLocalDateTime();
    return DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(local).replaceAll("[T]", " ");
}

From source file:no.digipost.api.useragreements.client.filters.response.ResponseDateInterceptor.java

public ResponseDateInterceptor() {
    this(Clock.systemDefaultZone());
}

From source file:org.codelibs.fess.web.IndexAction.java

protected String doSearchInternal() {
    final StringBuilder queryBuf = new StringBuilder(255);
    if (StringUtil.isNotBlank(indexForm.query)) {
        queryBuf.append(indexForm.query);
    }/* w ww .  ja  va  2  s.  co  m*/
    if (StringUtil.isNotBlank(indexForm.op)) {
        request.setAttribute(Constants.DEFAULT_OPERATOR, indexForm.op);
    }
    if (queryBuf.indexOf(" OR ") >= 0) {
        queryBuf.insert(0, '(').append(')');
    }
    if (indexForm.additional != null) {
        final Set<String> fieldSet = new HashSet<String>();
        for (final String additional : indexForm.additional) {
            if (StringUtil.isNotBlank(additional) && additional.length() < 1000
                    && !hasFieldInQuery(fieldSet, additional)) {
                queryBuf.append(' ').append(additional);
            }
        }
    }
    if (!indexForm.fields.isEmpty()) {
        for (final Map.Entry<String, String[]> entry : indexForm.fields.entrySet()) {
            final List<String> valueList = new ArrayList<String>();
            final String[] values = entry.getValue();
            if (values != null) {
                for (final String v : values) {
                    valueList.add(v);
                }
            }
            if (valueList.size() == 1) {
                queryBuf.append(' ').append(entry.getKey()).append(":\"").append(valueList.get(0)).append('\"');
            } else if (valueList.size() > 1) {
                queryBuf.append(" (");
                for (int i = 0; i < valueList.size(); i++) {
                    if (i != 0) {
                        queryBuf.append(" OR");
                    }
                    queryBuf.append(' ').append(entry.getKey()).append(":\"").append(valueList.get(i))
                            .append('\"');
                }
                queryBuf.append(')');
            }

        }
    }
    if (StringUtil.isNotBlank(indexForm.sort)) {
        queryBuf.append(" sort:").append(indexForm.sort);
    }
    if (indexForm.lang != null) {
        final Set<String> langSet = new HashSet<>();
        for (final String lang : indexForm.lang) {
            if (StringUtil.isNotBlank(lang) && lang.length() < 1000) {
                if (Constants.ALL_LANGUAGES.equalsIgnoreCase(lang)) {
                    langSet.add(Constants.ALL_LANGUAGES);
                } else {
                    final String normalizeLang = systemHelper.normalizeLang(lang);
                    if (normalizeLang != null) {
                        langSet.add(normalizeLang);
                    }
                }
            }
        }
        if (langSet.size() > 1 && langSet.contains(Constants.ALL_LANGUAGES)) {
            langSet.clear();
            indexForm.lang = new String[] { Constants.ALL_LANGUAGES };
        } else {
            langSet.remove(Constants.ALL_LANGUAGES);
        }
        appendLangQuery(queryBuf, langSet);
    } else if (Constants.TRUE.equals(
            crawlerProperties.getProperty(Constants.USE_BROWSER_LOCALE_FOR_SEARCH_PROPERTY, Constants.FALSE))) {
        final Set<String> langSet = new HashSet<>();
        final Enumeration<Locale> locales = request.getLocales();
        if (locales != null) {
            while (locales.hasMoreElements()) {
                final Locale locale = locales.nextElement();
                final String normalizeLang = systemHelper.normalizeLang(locale.toString());
                if (normalizeLang != null) {
                    langSet.add(normalizeLang);
                }
            }
            if (!langSet.isEmpty()) {
                appendLangQuery(queryBuf, langSet);
            }
        }
    }

    final String query = queryBuf.toString().trim();

    // init pager
    if (StringUtil.isBlank(indexForm.start)) {
        indexForm.start = String.valueOf(DEFAULT_START_COUNT);
    } else {
        try {
            Long.parseLong(indexForm.start);
        } catch (final NumberFormatException e) {
            indexForm.start = String.valueOf(DEFAULT_START_COUNT);
        }
    }
    if (StringUtil.isBlank(indexForm.num)) {
        indexForm.num = String.valueOf(getDefaultPageSize());
    }
    normalizePageNum();

    final int pageStart = Integer.parseInt(indexForm.start);
    final int pageNum = Integer.parseInt(indexForm.num);
    try {
        documentItems = searchService.getDocumentList(query, pageStart, pageNum, indexForm.facet, indexForm.geo,
                indexForm.mlt, queryHelper.getResponseFields(), queryHelper.getResponseDocValuesFields());
    } catch (final SolrLibQueryException e) {
        if (logger.isDebugEnabled()) {
            logger.debug(e.getMessage(), e);
        }
        throw new SSCActionMessagesException(e, "errors.invalid_query_unknown");
    } catch (final InvalidQueryException e) {
        if (logger.isDebugEnabled()) {
            logger.debug(e.getMessage(), e);
        }
        throw new SSCActionMessagesException(e, e.getMessageCode());
    } catch (final ResultOffsetExceededException e) {
        if (logger.isDebugEnabled()) {
            logger.debug(e.getMessage(), e);
        }
        throw new SSCActionMessagesException(e, "errors.result_size_exceeded");
    }
    // search
    final QueryResponseList queryResponseList = (QueryResponseList) documentItems;
    facetResponse = queryResponseList.getFacetResponse();
    moreLikeThisResponse = queryResponseList.getMoreLikeThisResponse();
    final NumberFormat nf = NumberFormat.getInstance(RequestUtil.getRequest().getLocale());
    nf.setMaximumIntegerDigits(2);
    nf.setMaximumFractionDigits(2);
    try {
        execTime = nf.format((double) queryResponseList.getExecTime() / 1000);
    } catch (final Exception e) {
        // ignore
    }

    final Clock clock = Clock.systemDefaultZone();
    indexForm.rt = Long.toString(clock.millis());

    // favorite
    if (favoriteSupport || screenShotManager != null) {
        indexForm.queryId = userInfoHelper.generateQueryId(query, documentItems);
        if (screenShotManager != null) {
            screenShotManager.storeRequest(indexForm.queryId, documentItems);
            screenShotSupport = true;
        }
    }

    // search log
    if (searchLogSupport) {
        final LocalDateTime now = systemHelper.getCurrentTime();

        final SearchLogHelper searchLogHelper = ComponentUtil.getSearchLogHelper();
        final SearchLog searchLog = new SearchLog();

        String userCode = null;
        if (Constants.TRUE
                .equals(crawlerProperties.getProperty(Constants.USER_INFO_PROPERTY, Constants.TRUE))) {
            userCode = userInfoHelper.getUserCode();
            if (StringUtil.isNotBlank(userCode)) {
                final UserInfo userInfo = new UserInfo();
                userInfo.setCode(userCode);
                userInfo.setCreatedTime(now);
                userInfo.setUpdatedTime(now);
                searchLog.setUserInfo(OptionalEntity.of(userInfo));
            }
        }

        searchLog.setHitCount(queryResponseList.getAllRecordCount());
        searchLog.setResponseTime(Integer.valueOf((int) queryResponseList.getExecTime()));
        searchLog.setSearchWord(StringUtils.abbreviate(query, 1000));
        searchLog.setSearchQuery(StringUtils.abbreviate(queryResponseList.getSearchQuery(), 1000));
        searchLog.setSolrQuery(StringUtils.abbreviate(queryResponseList.getSolrQuery(), 1000));
        searchLog.setRequestedTime(now);
        searchLog.setQueryOffset(pageStart);
        searchLog.setQueryPageSize(pageNum);

        searchLog.setClientIp(StringUtils.abbreviate(request.getRemoteAddr(), 50));
        searchLog.setReferer(StringUtils.abbreviate(request.getHeader("referer"), 1000));
        searchLog.setUserAgent(StringUtils.abbreviate(request.getHeader("user-agent"), 255));
        if (userCode != null) {
            searchLog.setUserSessionId(userCode);
        }
        final Object accessType = request.getAttribute(Constants.SEARCH_LOG_ACCESS_TYPE);
        if (accessType instanceof CDef.AccessType) {
            switch ((CDef.AccessType) accessType) {
            case Json:
                searchLog.setAccessType_Json();
                searchLog.setAccessType_Others();
                searchLog.setAccessType_Xml();
                break;
            case Xml:
                searchLog.setAccessType_Xml();
                break;
            case Others:
                searchLog.setAccessType_Others();
                break;
            default:
                searchLog.setAccessType_Web();
                break;
            }
        } else {
            searchLog.setAccessType_Web();
        }

        @SuppressWarnings("unchecked")
        final Map<String, List<String>> fieldLogMap = (Map<String, List<String>>) request
                .getAttribute(Constants.FIELD_LOGS);
        if (fieldLogMap != null) {
            for (final Map.Entry<String, List<String>> logEntry : fieldLogMap.entrySet()) {
                for (final String value : logEntry.getValue()) {
                    searchLog.addSearchFieldLogValue(logEntry.getKey(), StringUtils.abbreviate(value, 1000));
                }
            }
        }

        searchLogHelper.addSearchLog(searchLog);
    }

    final String[] highlightQueries = (String[]) request.getAttribute(Constants.HIGHLIGHT_QUERIES);
    if (highlightQueries != null) {
        final StringBuilder buf = new StringBuilder(100);
        for (final String q : highlightQueries) {
            buf.append("&hq=").append(q);
        }
        appendHighlightQueries = buf.toString();
    }

    Beans.copy(documentItems, this)
            .includes("pageSize", "currentPageNumber", "allRecordCount", "allPageCount", "existNextPage",
                    "existPrevPage", "currentStartRecordNumber", "currentEndRecordNumber", "pageNumberList",
                    "partialResults", "queryTime", "searchTime")
            .execute();

    return query;
}