2 * Copyright (c) 2017-2019. Developed by Hedgecode.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.hedgecode.snooker;
19 import java.text.DateFormat;
20 import java.text.SimpleDateFormat;
21 import java.util.Date;
22 import java.util.TimeZone;
25 * Date and Time Utils for Matches and Events.
27 * @author Dmitry Samoshin aka gotty
29 public final class SnookerDateUtils {
31 public static final String DATE_PATTERN = "dd.MM.yyyy";
32 public static final String TIME_PATTERN = "HH:mm";
33 public static final String DATETIME_PATTERN = TIME_PATTERN + " " + DATE_PATTERN;
35 private static final TimeZone CTZ = TimeZone.getTimeZone("CET");
36 private static final TimeZone LTZ = TimeZone.getDefault();
38 private static final DateFormat DATE_FORMAT = new SimpleDateFormat(DATE_PATTERN);
39 private static final DateFormat CET_TIME_FORMAT = new SimpleDateFormat(TIME_PATTERN);
40 private static final DateFormat CET_DATETIME_FORMAT = new SimpleDateFormat(DATETIME_PATTERN);
41 private static final DateFormat LOCAL_TIME_FORMAT = new SimpleDateFormat(TIME_PATTERN);
42 private static final DateFormat LOCAL_DATETIME_FORMAT = new SimpleDateFormat(DATETIME_PATTERN);
45 CET_TIME_FORMAT.setTimeZone(CTZ);
46 CET_DATETIME_FORMAT.setTimeZone(CTZ);
47 LOCAL_TIME_FORMAT.setTimeZone(LTZ);
48 LOCAL_DATETIME_FORMAT.setTimeZone(LTZ);
51 public static String formatDate(Date date) {
52 return DATE_FORMAT.format(date);
55 public static String formatTime(Date date) {
56 return formatTime(date, false);
59 public static String formatTime(Date date, boolean withDate) {
60 return withDate ? CET_DATETIME_FORMAT.format(date) : CET_TIME_FORMAT.format(date);
63 public static String formatLocalTime(Date date) {
64 return formatLocalTime(date, false);
67 public static String formatLocalTime(Date date, boolean withDate) {
68 return withDate ? LOCAL_DATETIME_FORMAT.format(date) : LOCAL_TIME_FORMAT.format(date);