From 80e04865d6f2274e1b7fb7b5892e427692c6ccf0 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Tue, 18 Aug 2015 18:18:31 +0200 Subject: [PATCH] Cleanup (API consistency; warnings; formatting) --- .../intellij/util/text/DateFormatUtil.java | 29 ++++++++++++++----- .../idea/svn/commandLine/CommandUtil.java | 17 ++++++++++- .../src/com/intellij/tasks/impl/TaskUtil.java | 24 +++++++-------- 3 files changed, 49 insertions(+), 21 deletions(-) diff --git a/platform/util/src/com/intellij/util/text/DateFormatUtil.java b/platform/util/src/com/intellij/util/text/DateFormatUtil.java index 8dfb8029a11d..dd7fdd5c14c5 100644 --- a/platform/util/src/com/intellij/util/text/DateFormatUtil.java +++ b/platform/util/src/com/intellij/util/text/DateFormatUtil.java @@ -48,23 +48,26 @@ public class DateFormatUtil { public static final long YEAR = DAY * 365; public static final long DAY_FACTOR = 24L * 60 * 60 * 1000; - public static final SyncDateFormat ISO8601_DATE_FORMAT = new SyncDateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")); - // do not expose this constants - they are very likely to be changed in future private static final SyncDateFormat DATE_FORMAT; private static final SyncDateFormat TIME_FORMAT; private static final SyncDateFormat TIME_WITH_SECONDS_FORMAT; private static final SyncDateFormat DATE_TIME_FORMAT; private static final SyncDateFormat ABOUT_DATE_FORMAT; + private static final SyncDateFormat ISO8601_FORMAT; + static { SyncDateFormat[] formats = getDateTimeFormats(); DATE_FORMAT = formats[0]; TIME_FORMAT = formats[1]; TIME_WITH_SECONDS_FORMAT = formats[2]; DATE_TIME_FORMAT = formats[3]; + ABOUT_DATE_FORMAT = new SyncDateFormat(DateFormat.getDateInstance(DateFormat.LONG, Locale.US)); - ISO8601_DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC")); + @SuppressWarnings("SpellCheckingInspection") DateFormat iso8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); + iso8601.setTimeZone(TimeZone.getTimeZone("UTC")); + ISO8601_FORMAT = new SyncDateFormat(iso8601); } private static final long[] DENOMINATORS = {YEAR, MONTH, WEEK, DAY, HOUR, MINUTE}; @@ -73,7 +76,11 @@ public class DateFormatUtil { private DateFormatUtil() { } - public static long getDifferenceInDays(final Date startDate, final Date endDate) { + /** @deprecated use {@link #getIso8601Format()} (to be removed in IDEA 16) */ + @SuppressWarnings("unused") + public static final SyncDateFormat ISO8601_DATE_FORMAT = ISO8601_FORMAT; + + public static long getDifferenceInDays(@NotNull Date startDate, @NotNull Date endDate) { return (endDate.getTime() - startDate.getTime() + DAY_FACTOR - 1000) / DAY_FACTOR; } @@ -97,6 +104,11 @@ public class DateFormatUtil { return DATE_TIME_FORMAT; } + @NotNull + public static SyncDateFormat getIso8601Format() { + return ISO8601_FORMAT; + } + @NotNull public static String formatTime(@NotNull Date time) { return formatTime(time.getTime()); @@ -182,8 +194,7 @@ public class DateFormatUtil { boolean isToday = currentYear == year && currentDayOfYear == dayOfYear; if (isToday) { String result = CommonBundle.message("date.format.today"); - if (formatTime) result += " " + TIME_FORMAT.format(time); - return result; + return formatTime ? result + " " + TIME_FORMAT.format(time) : result; } boolean isYesterdayOnPreviousYear = @@ -192,8 +203,7 @@ public class DateFormatUtil { if (isYesterday) { String result = CommonBundle.message("date.format.yesterday"); - if (formatTime) result += " " + TIME_FORMAT.format(time); - return result; + return formatTime ? result + " " + TIME_FORMAT.format(time) : result; } return formatTime ? DATE_TIME_FORMAT.format(time) : DATE_FORMAT.format(time); @@ -216,6 +226,7 @@ public class DateFormatUtil { return buf.toString().trim(); } + @SuppressWarnings("Duplicates") private static String composeDurationMessage(final Period period, final int n) { switch (period) { case DAY: @@ -280,6 +291,7 @@ public class DateFormatUtil { // helpers + @SuppressWarnings("Duplicates") private static String someTimeAgoMessage(final Period period, final int n) { switch (period) { case DAY: @@ -297,6 +309,7 @@ public class DateFormatUtil { } } + @SuppressWarnings("Duplicates") private static String composeInSomeTimeMessage(final Period period, final int n) { switch (period) { case DAY: diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/commandLine/CommandUtil.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/commandLine/CommandUtil.java index e6379c659082..5cca2417d81c 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/commandLine/CommandUtil.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/commandLine/CommandUtil.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2015 JetBrains s.r.o. + * + * 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. + */ package org.jetbrains.idea.svn.commandLine; import com.intellij.openapi.application.PathManager; @@ -123,7 +138,7 @@ public class CommandUtil { @NotNull public static String format(@NotNull SVNRevision revision) { - return revision.getDate() != null ? "{" + DateFormatUtil.ISO8601_DATE_FORMAT.format(revision.getDate()) + "}" : revision.toString(); + return revision.getDate() != null ? "{" + DateFormatUtil.getIso8601Format().format(revision.getDate()) + "}" : revision.toString(); } public static void put(@NotNull List parameters, @Nullable DiffOptions diffOptions) { diff --git a/plugins/tasks/tasks-core/src/com/intellij/tasks/impl/TaskUtil.java b/plugins/tasks/tasks-core/src/com/intellij/tasks/impl/TaskUtil.java index 29b1a01a209e..b7db9b9a9f68 100644 --- a/plugins/tasks/tasks-core/src/com/intellij/tasks/impl/TaskUtil.java +++ b/plugins/tasks/tasks-core/src/com/intellij/tasks/impl/TaskUtil.java @@ -1,17 +1,17 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * - * 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 + * 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 + * 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. + * 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. */ package com.intellij.tasks.impl; @@ -128,7 +128,7 @@ public class TaskUtil { } String canonicalForm = String.format("%sT%s.%s%s", datePart, timePart, milliseconds, timezone); try { - return DateFormatUtil.ISO8601_DATE_FORMAT.parse(canonicalForm); + return DateFormatUtil.getIso8601Format().parse(canonicalForm); } catch (ParseException e) { return null; @@ -136,7 +136,7 @@ public class TaskUtil { } public static String formatDate(@NotNull Date date) { - return DateFormatUtil.ISO8601_DATE_FORMAT.format(date); + return DateFormatUtil.getIso8601Format().format(date); } /**