Search in sources :

Example 56 with DateFormat

use of java.text.DateFormat in project hudson-2.x by hudson.

the class Run method doBuildTimestamp.

/**
     * Returns the build time stamp in the body.
     */
public void doBuildTimestamp(StaplerRequest req, StaplerResponse rsp, @QueryParameter String format) throws IOException {
    rsp.setContentType("text/plain");
    rsp.setCharacterEncoding("US-ASCII");
    rsp.setStatus(HttpServletResponse.SC_OK);
    DateFormat df = format == null ? DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Locale.ENGLISH) : new SimpleDateFormat(format, req.getLocale());
    rsp.getWriter().print(df.format(getTime()));
}
Also used : DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) SimpleDateFormat(java.text.SimpleDateFormat)

Example 57 with DateFormat

use of java.text.DateFormat in project pinot by linkedin.

the class SegmentMetadataImpl method toJson.

/**
   * Converts segment metadata to json
   * @param columnFilter list only  the columns in the set. Lists all the columns if
   *                     the parameter value is null
   * @return json representation of segment metadata
   */
public JSONObject toJson(@Nullable Set<String> columnFilter) throws JSONException {
    JSONObject rootMeta = new JSONObject();
    try {
        rootMeta.put("segmentName", _segmentName);
        rootMeta.put("schemaName", _schema != null ? _schema.getSchemaName() : JSONObject.NULL);
        rootMeta.put("crc", _crc);
        rootMeta.put("creationTimeMillis", _creationTime);
        TimeZone timeZone = TimeZone.getTimeZone("UTC");
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss:SSS' UTC'");
        dateFormat.setTimeZone(timeZone);
        String creationTimeStr = _creationTime != Long.MIN_VALUE ? dateFormat.format(new Date(_creationTime)) : "";
        rootMeta.put("creationTimeReadable", creationTimeStr);
        rootMeta.put("timeGranularitySec", _timeGranularity != null ? _timeGranularity.getStandardSeconds() : null);
        if (_timeInterval == null) {
            rootMeta.put("startTimeMillis", (String) null);
            rootMeta.put("startTimeReadable", "null");
            rootMeta.put("endTimeMillis", (String) null);
            rootMeta.put("endTimeReadable", "null");
        } else {
            rootMeta.put("startTimeMillis", _timeInterval.getStartMillis());
            rootMeta.put("startTimeReadable", _timeInterval.getStart().toString());
            rootMeta.put("endTimeMillis", _timeInterval.getEndMillis());
            rootMeta.put("endTimeReadable", _timeInterval.getEnd().toString());
        }
        rootMeta.put("pushTimeMillis", _pushTime);
        String pushTimeStr = _pushTime != Long.MIN_VALUE ? dateFormat.format(new Date(_pushTime)) : "";
        rootMeta.put("pushTimeReadable", pushTimeStr);
        rootMeta.put("refreshTimeMillis", _refreshTime);
        String refreshTimeStr = _refreshTime != Long.MIN_VALUE ? dateFormat.format(new Date(_refreshTime)) : "";
        rootMeta.put("refreshTimeReadable", refreshTimeStr);
        rootMeta.put("segmentVersion", _segmentVersion.toString());
        rootMeta.put("hasStarTree", hasStarTree());
        rootMeta.put("creatorName", _creatorName == null ? JSONObject.NULL : _creatorName);
        rootMeta.put("paddingCharacter", String.valueOf(_paddingCharacter));
        rootMeta.put("hllLog2m", _hllLog2m);
        JSONArray columnsJson = new JSONArray();
        ObjectMapper mapper = new ObjectMapper();
        for (String column : _allColumns) {
            if (columnFilter != null && !columnFilter.contains(column)) {
                continue;
            }
            ColumnMetadata columnMetadata = _columnMetadataMap.get(column);
            JSONObject columnJson = new JSONObject(mapper.writeValueAsString(columnMetadata));
            columnsJson.put(columnJson);
        }
        rootMeta.put("columns", columnsJson);
        return rootMeta;
    } catch (Exception e) {
        LOGGER.error("Failed to convert field to json for segment: {}", _segmentName, e);
        throw new RuntimeException("Failed to convert segment metadata to json", e);
    }
}
Also used : TimeZone(java.util.TimeZone) JSONObject(org.json.JSONObject) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) JSONArray(org.json.JSONArray) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) JSONException(org.json.JSONException) IOException(java.io.IOException) ConfigurationException(org.apache.commons.configuration.ConfigurationException)

Example 58 with DateFormat

use of java.text.DateFormat in project head by mifos.

the class DateTag method getUserFormat.

String getUserFormat(Locale locale) {
    // the following line will be removed when date is localized
    locale = Locale.UK;
    DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale);
    return ((SimpleDateFormat) df).toPattern();
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat)

Example 59 with DateFormat

use of java.text.DateFormat in project head by mifos.

the class LocalizationConverter method getDateSeparator.

public String getDateSeparator(Locale locale, int dateFormat) {
    String separator = "";
    DateFormat format = DateFormat.getDateInstance(dateFormat, locale);
    String now = format.format(new DateTimeService().getCurrentJavaDateTime());
    char[] chArray = now.toCharArray();
    for (char element : chArray) {
        if (Character.isDigit(element) == false) {
            separator = String.valueOf(element);
            break;
        }
    }
    return separator;
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat)

Example 60 with DateFormat

use of java.text.DateFormat in project head by mifos.

the class HomePageController method loadLoanOfficerCustomersHierarchyForSelectedDay.

private void loadLoanOfficerCustomersHierarchyForSelectedDay(Short userId, ModelAndView modelAndView, CustomerSearchFormBean customerSearchFormBean) throws MifosException {
    CustomerHierarchyDto hierarchy;
    List<String> nearestDates = new ArrayList<String>();
    DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy", personnelServiceFacade.getUserPreferredLocale());
    Date selectedDate = new LocalDate().toDateMidnight().toDate();
    DateTime nextDate = new DateTime();
    for (int i = 0; i < 7; i++) {
        nearestDates.add(formatter.format(nextDate.toDate()));
        nextDate = nextDate.plusDays(1);
    }
    if (customerSearchFormBean.getSelectedDateOption() != null) {
        try {
            selectedDate = formatter.parse(customerSearchFormBean.getSelectedDateOption());
        } catch (ParseException e) {
            throw new MifosException(e);
        }
    }
    hierarchy = personnelServiceFacade.getLoanOfficerCustomersHierarchyForDay(userId, new DateTime(selectedDate));
    modelAndView.addObject("nearestDates", nearestDates);
    modelAndView.addObject("hierarchy", hierarchy);
}
Also used : MifosException(org.mifos.core.MifosException) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) CustomerHierarchyDto(org.mifos.dto.domain.CustomerHierarchyDto) ArrayList(java.util.ArrayList) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) LocalDate(org.joda.time.LocalDate) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime)

Aggregations

DateFormat (java.text.DateFormat)763 SimpleDateFormat (java.text.SimpleDateFormat)593 Date (java.util.Date)387 ParseException (java.text.ParseException)142 Test (org.junit.Test)86 Calendar (java.util.Calendar)85 ArrayList (java.util.ArrayList)62 IOException (java.io.IOException)47 File (java.io.File)35 HashMap (java.util.HashMap)32 List (java.util.List)29 GregorianCalendar (java.util.GregorianCalendar)25 TimeZone (java.util.TimeZone)25 Locale (java.util.Locale)22 Timestamp (java.sql.Timestamp)19 Map (java.util.Map)16 InputStream (java.io.InputStream)15 LocalDate (java.time.LocalDate)10 Matcher (java.util.regex.Matcher)10 Position (org.traccar.model.Position)10