Search in sources :

Example 6 with Calendar

use of java.util.Calendar in project Meizhi by drakeet.

the class Dates method getNextdayDate.

public static Date getNextdayDate(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    calendar.add(Calendar.DATE, 1);
    return calendar.getTime();
}
Also used : Calendar(java.util.Calendar)

Example 7 with Calendar

use of java.util.Calendar in project lucida by claritylab.

the class EphyraTREC13To16 method main.

/**
	 * Runs Ephyra on the TREC questions.
	 * 
	 * @param args argument 1: questionfile<br>
	 * 			   [argument 2: tag=runtag (uniquely identifies the run, also
	 * 							used as output file name, if not set an
	 * 							unambiguous tag is generated automatically)]<br>
	 * 			   [argument 3: log=logfile (if not set an unambiguous file name
	 * 							is generated automatically)]<br>
	 * 			   [argument 4: lin=input_logfile (specifies a separate logfile
	 * 							that is used as a source for answers to some of
	 * 							the	questions, if not set the standard log file
	 * 							is used)]<br>
	 * 			   [argument 5: lflags=[f][l][o] (answers to these types of
	 * 							questions are loaded from the log file instead
	 * 							of querying Ephyra,	e.g. "flo" for factoid, list
	 * 							and other questions)]<br>
	 * 			   [argument 6: fp=factoid_patternfile]<br>
	 * 			   [argument 7: lp=list_patternfile]
	 */
public static void main(String[] args) {
    // enable output of status and error messages
    MsgPrinter.enableStatusMsgs(true);
    MsgPrinter.enableErrorMsgs(true);
    if (args.length < 1) {
        MsgPrinter.printUsage("java EphyraTREC13To16 questionfile " + "[tag=runtag] [log=logfile] " + "[lin=input_logfile] " + "[lflags=[f][l][o]] " + "[fp=factoid_patternfile] " + "[lp=list_patternfile]");
        System.exit(1);
    }
    // load targets
    targets = TREC13To16Parser.loadTargets(args[0]);
    for (int i = 1; i < args.length; i++) if (args[i].matches("tag=.*")) {
        // set run tag
        runTag = args[i].substring(4);
    } else if (args[i].matches("log=.*")) {
        // set log file
        logFile = args[i].substring(4);
    } else if (args[i].matches("lin=.*")) {
        // set separate input log file
        inputLogFile = args[i].substring(4);
    } else if (args[i].matches("lflags=.*")) {
        // answers for some question types are loaded from log file
        String flags = args[i].substring(7).toLowerCase();
        if (flags.contains("f"))
            factoidLog = true;
        if (flags.contains("l"))
            listLog = true;
        if (flags.contains("o"))
            otherLog = true;
    } else if (args[i].matches("fp=.*")) {
        // load factoid patterns
        factoidPatterns = TREC13To16Parser.loadPatterns(args[i].substring(3));
    } else if (args[i].matches("lp=.*")) {
        // load list patterns
        listPatterns = TREC13To16Parser.loadPatterns(args[i].substring(3));
    }
    // if run tag or log file not set, generate unambiguous names
    if (runTag == null || logFile == null) {
        String n = "";
        Matcher m = Pattern.compile("\\d++").matcher(args[0]);
        if (m.find())
            n = m.group(0);
        String date = "";
        Calendar c = new GregorianCalendar();
        date += c.get(Calendar.DAY_OF_MONTH);
        if (date.length() == 1)
            date = "0" + date;
        date = (c.get(Calendar.MONTH) + 1) + date;
        if (date.length() == 3)
            date = "0" + date;
        date = c.get(Calendar.YEAR) + date;
        if (runTag == null)
            runTag = "TREC" + n + "_" + date + "_out";
        if (logFile == null)
            logFile = "log/TREC" + n + "_" + date;
    }
    // if input log file not set, use standard log file
    if (inputLogFile == null)
        inputLogFile = logFile;
    // enable logging
    Logger.setLogfile(logFile);
    Logger.enableLogging(true);
    // run Ephyra on questions, evaluate answers if patterns available
    runAndEval();
}
Also used : Matcher(java.util.regex.Matcher) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar)

Example 8 with Calendar

use of java.util.Calendar in project buck by facebook.

the class EntryAccounting method getTime.

/**
   * @return The time of the entry in DOS format.
   */
public long getTime() {
    // Calendar objects aren't thread-safe, but they're quite expensive to create, so we'll re-use
    // them per thread.
    Calendar instance = CALENDAR.get();
    instance.setTimeInMillis(entry.getTime());
    int year = instance.get(Calendar.YEAR);
    // epoch (the 1st day of the 1st month)
    if (year < 1980) {
        return ZipConstants.DOS_FAKE_TIME;
    }
    return (year - 1980) << 25 | (instance.get(Calendar.MONTH) + 1) << 21 | instance.get(Calendar.DAY_OF_MONTH) << 16 | instance.get(Calendar.HOUR_OF_DAY) << 11 | instance.get(Calendar.MINUTE) << 5 | instance.get(Calendar.SECOND) >> 1;
}
Also used : Calendar(java.util.Calendar)

Example 9 with Calendar

use of java.util.Calendar in project jetty.project by eclipse.

the class SecureModeServlet method runLoggingChecks.

private void runLoggingChecks(ServletOutputStream out) throws Exception {
    out.println("    <h1>Checking File System</h1>");
    out.println("      <p>");
    String userDir = System.getProperty("user.dir");
    try {
        out.println("check ability to log<br/>");
        LOG.info("testing logging");
        out.println("status: <b>SUCCESS - expected</b><br/>");
    } catch (SecurityException e) {
        out.println("status: <b>FAILURE - unexpected</b><br/>");
        out.println("<table><tr><td>");
        e.printStackTrace(new PrintStream(out));
        out.println("</td></tr></table>");
    }
    try {
        Calendar c = new GregorianCalendar();
        String logFile = c.get(Calendar.YEAR) + "_" + c.get(Calendar.MONTH) + "_" + c.get(Calendar.DAY_OF_MONTH) + ".request.log";
        out.println("check ability to access log file directly<br/>");
        File jettyHomeFile = new File(userDir + File.separator + "logs" + File.separator + logFile);
        jettyHomeFile.canRead();
        out.println("status: <b>SUCCESS - unexpected</b><br/>");
    } catch (SecurityException e) {
        out.println("status: <b>FAILURE - expected</b><br/>");
    }
    out.println("      </p><br/><br/>");
}
Also used : PrintStream(java.io.PrintStream) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) File(java.io.File)

Example 10 with Calendar

use of java.util.Calendar in project elasticsearch by elastic.

the class DateMethodValueSource method getValues.

@Override
// ValueSource uses a rawtype
@SuppressWarnings("rawtypes")
public FunctionValues getValues(Map context, LeafReaderContext leaf) throws IOException {
    AtomicNumericFieldData leafData = (AtomicNumericFieldData) fieldData.load(leaf);
    final Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.ROOT);
    NumericDoubleValues docValues = multiValueMode.select(leafData.getDoubleValues(), 0d);
    return new DoubleDocValues(this) {

        @Override
        public double doubleVal(int docId) {
            long millis = (long) docValues.get(docId);
            calendar.setTimeInMillis(millis);
            return calendar.get(calendarType);
        }
    };
}
Also used : Calendar(java.util.Calendar) DoubleDocValues(org.apache.lucene.queries.function.docvalues.DoubleDocValues) NumericDoubleValues(org.elasticsearch.index.fielddata.NumericDoubleValues) AtomicNumericFieldData(org.elasticsearch.index.fielddata.AtomicNumericFieldData)

Aggregations

Calendar (java.util.Calendar)9441 Date (java.util.Date)2433 GregorianCalendar (java.util.GregorianCalendar)2129 Test (org.junit.Test)1734 SimpleDateFormat (java.text.SimpleDateFormat)889 ArrayList (java.util.ArrayList)476 ParseException (java.text.ParseException)352 HashMap (java.util.HashMap)270 TimeZone (java.util.TimeZone)270 IOException (java.io.IOException)235 DateFormat (java.text.DateFormat)224 Timestamp (java.sql.Timestamp)192 List (java.util.List)187 File (java.io.File)167 Map (java.util.Map)149 BigDecimal (java.math.BigDecimal)134 Locale (java.util.Locale)134 Test (org.testng.annotations.Test)118 Identity (org.olat.core.id.Identity)112 Date (java.sql.Date)110