Search in sources :

Example 81 with DateFormat

use of java.text.DateFormat in project bazel by bazelbuild.

the class ExperimentalTestRunner method main.

/**
   * Takes as arguments the classes or packages to test.
   *
   * <p>To help just run one test or method in a suite, the test suite
   * may be passed in via system properties (-Dbazel.test_suite).
   * An empty args parameter means to run all tests in the suite.
   * A non-empty args parameter means to run only the specified tests/methods.
   *
   * <p>Return codes:
   * <ul>
   * <li>Test runner failure, bad arguments, etc.: exit code of 2</li>
   * <li>Normal test failure: exit code of 1</li>
   * <li>All tests pass: exit code of 0</li>
   * </ul>
   */
public static void main(String[] args) {
    PrintStream stderr = System.err;
    String suiteClassName = System.getProperty(TEST_SUITE_PROPERTY_NAME);
    if ("true".equals(System.getenv("PERSISTENT_TEST_RUNNER"))) {
        System.exit(runPersistentTestRunner(suiteClassName));
    }
    System.out.println("WARNING: RUNNING EXPERIMENTAL TEST RUNNER");
    if (!checkTestSuiteProperty(suiteClassName)) {
        System.exit(2);
    }
    int exitCode = runTestsInSuite(suiteClassName, args);
    System.err.printf("%nExperimentalTestRunner exiting with a return value of %d%n", exitCode);
    System.err.println("JVM shutdown hooks (if any) will run now.");
    System.err.println("The JVM will exit once they complete.");
    System.err.println();
    printStackTracesIfJvmExitHangs(stderr);
    DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date shutdownTime = new Date();
    String formattedShutdownTime = format.format(shutdownTime);
    System.err.printf("-- JVM shutdown starting at %s --%n%n", formattedShutdownTime);
    System.exit(exitCode);
}
Also used : PrintStream(java.io.PrintStream) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 82 with DateFormat

use of java.text.DateFormat in project bazel by bazelbuild.

the class TestInterval method startInstantToString.

/** Exposed for testing because java Date does not allow setting of timezones. */
// VisibleForTesting
String startInstantToString(TimeZone tz) {
    DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
    format.setTimeZone(tz);
    return format.format(new Date(startInstant));
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 83 with DateFormat

use of java.text.DateFormat in project japid42 by branaway.

the class WebUtils method format.

public static String format(Date date, String pattern, String lang, String timezone) {
    DateFormat df = new SimpleDateFormat(pattern, new Locale(lang));
    df.setTimeZone(TimeZone.getTimeZone(timezone));
    return df.format(date);
}
Also used : Locale(java.util.Locale) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat)

Example 84 with DateFormat

use of java.text.DateFormat in project graphhopper by graphhopper.

the class GraphHopper method process.

/**
     * Creates the graph from OSM data.
     */
private GraphHopper process(String graphHopperLocation) {
    setGraphHopperLocation(graphHopperLocation);
    GHLock lock = null;
    try {
        if (ghStorage.getDirectory().getDefaultType().isStoring()) {
            lockFactory.setLockDir(new File(graphHopperLocation));
            lock = lockFactory.create(fileLockName, true);
            if (!lock.tryLock())
                throw new RuntimeException("To avoid multiple writers we need to obtain a write lock but it failed. In " + graphHopperLocation, lock.getObtainFailedReason());
        }
        try {
            DataReader reader = importData();
            DateFormat f = Helper.createFormatter();
            ghStorage.getProperties().put("datareader.import.date", f.format(new Date()));
            if (reader.getDataDate() != null)
                ghStorage.getProperties().put("datareader.data.date", f.format(reader.getDataDate()));
        } catch (IOException ex) {
            throw new RuntimeException("Cannot read file " + getDataReaderFile(), ex);
        }
        cleanUp();
        postProcessing();
        flush();
    } finally {
        if (lock != null)
            lock.release();
    }
    return this;
}
Also used : DataReader(com.graphhopper.reader.DataReader) DateFormat(java.text.DateFormat) IOException(java.io.IOException) File(java.io.File)

Example 85 with DateFormat

use of java.text.DateFormat in project graphhopper by graphhopper.

the class InstructionList method createGPX.

public String createGPX(String trackName, long startTimeMillis, boolean includeElevation, boolean withRoute, boolean withTrack, boolean withWayPoints) {
    DateFormat formatter = Helper.createFormatter();
    String header = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>" + "<gpx xmlns=\"http://www.topografix.com/GPX/1/1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + " creator=\"Graphhopper version " + Constants.VERSION + "\" version=\"1.1\"" + // Use a separate namespace for custom extensions to make basecamp happy.
    " xmlns:gh=\"https://graphhopper.com/public/schema/gpx/1.1\">" + "\n<metadata>" + "<copyright author=\"OpenStreetMap contributors\"/>" + "<link href=\"http://graphhopper.com\">" + "<text>GraphHopper GPX</text>" + "</link>" + "<time>" + formatter.format(startTimeMillis) + "</time>" + "</metadata>";
    StringBuilder gpxOutput = new StringBuilder(header);
    if (!isEmpty()) {
        if (withWayPoints) {
            // Start 
            createWayPointBlock(gpxOutput, instructions.get(0));
            for (Instruction currInstr : instructions) {
                if (// Via
                (currInstr.getSign() == Instruction.REACHED_VIA) || // End
                (currInstr.getSign() == Instruction.FINISH)) {
                    createWayPointBlock(gpxOutput, currInstr);
                }
            }
        }
        if (withRoute) {
            gpxOutput.append("\n<rte>");
            Instruction nextInstr = null;
            for (Instruction currInstr : instructions) {
                if (null != nextInstr)
                    createRteptBlock(gpxOutput, nextInstr, currInstr);
                nextInstr = currInstr;
            }
            createRteptBlock(gpxOutput, nextInstr, null);
            gpxOutput.append("\n</rte>");
        }
    }
    if (withTrack) {
        gpxOutput.append("\n<trk><name>").append(trackName).append("</name>");
        gpxOutput.append("<trkseg>");
        for (GPXEntry entry : createGPXList()) {
            gpxOutput.append("\n<trkpt lat=\"").append(Helper.round6(entry.getLat()));
            gpxOutput.append("\" lon=\"").append(Helper.round6(entry.getLon())).append("\">");
            if (includeElevation)
                gpxOutput.append("<ele>").append(Helper.round2(entry.getEle())).append("</ele>");
            gpxOutput.append("<time>").append(formatter.format(startTimeMillis + entry.getTime())).append("</time>");
            gpxOutput.append("</trkpt>");
        }
        gpxOutput.append("\n</trkseg>");
        gpxOutput.append("\n</trk>");
    }
    // we could now use 'wpt' for via points
    gpxOutput.append("\n</gpx>");
    return gpxOutput.toString();
}
Also used : DateFormat(java.text.DateFormat)

Aggregations

DateFormat (java.text.DateFormat)646 SimpleDateFormat (java.text.SimpleDateFormat)486 Date (java.util.Date)315 ParseException (java.text.ParseException)132 Calendar (java.util.Calendar)78 Test (org.junit.Test)69 ArrayList (java.util.ArrayList)48 IOException (java.io.IOException)43 File (java.io.File)31 HashMap (java.util.HashMap)27 GregorianCalendar (java.util.GregorianCalendar)24 TimeZone (java.util.TimeZone)23 Locale (java.util.Locale)18 Timestamp (java.sql.Timestamp)17 List (java.util.List)14 InputStream (java.io.InputStream)12 DateTime (org.joda.time.DateTime)11 Map (java.util.Map)10 Matcher (java.util.regex.Matcher)8 TestBean (org.springframework.tests.sample.beans.TestBean)8