Here you can find the source of getIndexGroupingPeriod_slow(String date_format)
Parameter | Description |
---|---|
date_format | a parameter |
private static ChronoUnit getIndexGroupingPeriod_slow(String date_format)
//package com.java2s; /******************************************************************************* * Copyright 2015, The IKANOW Open Source Project. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.//from w w w. j a v a2 s. c o m *******************************************************************************/ import java.text.SimpleDateFormat; import java.time.temporal.ChronoUnit; import java.util.Date; public class Main { /** Utility function to figure out the grouping period based on the index name * @param date_format * @return the date grouping type */ private static ChronoUnit getIndexGroupingPeriod_slow(String date_format) { final SimpleDateFormat d = new SimpleDateFormat(date_format); final long try_date_boxes[] = { 3601L, 25L * 3600L, 8L * 24L * 3600L, 32L * 24L * 3600L, 367L * 34L * 3600L }; final ChronoUnit ret_date_boxes[] = { ChronoUnit.HOURS, ChronoUnit.DAYS, ChronoUnit.WEEKS, ChronoUnit.MONTHS, ChronoUnit.YEARS }; final Date now = new Date(); final String now_string = d.format(now); for (int i = 0; i < try_date_boxes.length; ++i) { final String test_str = d.format(new Date(now.getTime() + 1000L * try_date_boxes[i])); if (!now_string.equals(test_str)) { final String test_str_2 = d.format(new Date(now.getTime() + 2000L * try_date_boxes[i])); if (!test_str.equals(test_str_2)) { // Need 2 consecutive indexes to be different, handles eg weeks at month boundaries return ret_date_boxes[i]; } } } return ChronoUnit.FOREVER; } }