diff --git a/platform/util/testSrc/com/intellij/util/text/DateFormatUtilTest.java b/platform/util/testSrc/com/intellij/util/text/DateFormatUtilTest.java index 3097cb5f3fbc..b3365c76c1f0 100644 --- a/platform/util/testSrc/com/intellij/util/text/DateFormatUtilTest.java +++ b/platform/util/testSrc/com/intellij/util/text/DateFormatUtilTest.java @@ -58,14 +58,11 @@ public class DateFormatUtilTest { assertEquals("17:10:15", DateFormatUtil.formatTimeWithSeconds(Clock.getTime())); } else if (SystemInfo.isUnix) { - assertEquals("5:10:15 PM", printTimeForLocale("en_US.UTF-8")); - assertEquals("17:10:15", printTimeForLocale("de_DE.UTF-8")); + assertEquals("5:10:15 PM", printTimeForLocale("en_US.UTF-8", Clock.getTime())); + assertEquals("17:10:15", printTimeForLocale("de_DE.UTF-8", Clock.getTime())); } else if (SystemInfo.isWinVistaOrNewer) { - String[] system = getWindowsTime(); - Date now = new Date(); - assertEquals(system[0], DateFormatUtil.formatDate(now)); - assertEquals(system[1], DateFormatUtil.formatTimeWithSeconds(now)); + assertEquals(printWindowsTime(Clock.getTime()), DateFormatUtil.formatTimeWithSeconds(Clock.getTime())); } else { assertEquals(DateFormat.getTimeInstance(DateFormat.SHORT).format(Clock.getTime()), @@ -115,7 +112,7 @@ public class DateFormatUtilTest { return new GregorianCalendar(year, month - 1, day, hour, minute, second).getTime(); } - private static String printTimeForLocale(String locale) throws IOException { + private static String printTimeForLocale(String locale, long time) throws IOException { List classpath = ContainerUtil.newArrayList(); classpath.addAll(PathManager.getUtilClassPath()); classpath.add(PathManager.getJarPathForClass(PrintTime.class)); @@ -124,11 +121,20 @@ public class DateFormatUtilTest { "-classpath", StringUtil.join(classpath, File.pathSeparator), PrintTime.class.getName(), - String.valueOf(Clock.getTime())) - .redirectErrorStream(true); + String.valueOf(time)); builder.environment().put("LC_TIME", locale); - Process process = builder.start(); + return execAndGetOutput(builder); + } + private static String printWindowsTime(long time) throws IOException { + String script = DateFormatUtil.class.getResource("PrintTime.js").getPath(); + if (StringUtil.startsWithChar(script, '/')) script = script.substring(1); + ProcessBuilder builder = new ProcessBuilder().command("cscript", "//Nologo", script, String.valueOf(time)); + return execAndGetOutput(builder); + } + + private static String execAndGetOutput(ProcessBuilder builder) throws IOException { + Process process = builder.redirectErrorStream(true).start(); BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); try { return reader.readLine(); @@ -137,22 +143,4 @@ public class DateFormatUtilTest { reader.close(); } } - - private static String[] getWindowsTime() throws IOException { - Process process = new ProcessBuilder("cmd", "/c", "echo %DATE%@%TIME%").start(); - - BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); - try { - String datetime = reader.readLine(); - if (datetime.matches(".+[.,]\\d\\d")) { - datetime = datetime.substring(0, datetime.length() - 3); - } - String[] parts = datetime.split("@"); - assertEquals(2, parts.length); - return parts; - } - finally { - reader.close(); - } - } } diff --git a/platform/util/testSrc/com/intellij/util/text/PrintTime.js b/platform/util/testSrc/com/intellij/util/text/PrintTime.js new file mode 100644 index 000000000000..d57170702a38 --- /dev/null +++ b/platform/util/testSrc/com/intellij/util/text/PrintTime.js @@ -0,0 +1,18 @@ +/* + * Copyright 2000-2014 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. + */ +var dt = new Date(); +dt.setTime(WSH.Arguments(0)); +WSH.Echo(dt.toLocaleTimeString());