Cleanup (API consistency; warnings; formatting)

This commit is contained in:
Roman Shevchenko
2015-08-18 18:18:31 +02:00
parent 1a7018d3c0
commit 80e04865d6
3 changed files with 49 additions and 21 deletions
@@ -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:
@@ -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<String> parameters, @Nullable DiffOptions diffOptions) {
@@ -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);
}
/**