Example usage for java.text DateFormat setTimeZone

List of usage examples for java.text DateFormat setTimeZone

Introduction

In this page you can find the example usage for java.text DateFormat setTimeZone.

Prototype

public void setTimeZone(TimeZone zone) 

Source Link

Document

Sets the time zone for the calendar of this DateFormat object.

Usage

From source file:org.apache.falcon.lifecycle.TableStorageFeedEvictorIT.java

public List<String> getExpectedEvictedInstances(List<String> candidatePartitions, Date date, String dateMask,
        String timeZone, StringBuilder instancePaths) {
    Collections.sort(candidatePartitions);
    instancePaths.append("instancePaths=");

    DateFormat dateFormat = new SimpleDateFormat(dateMask);
    dateFormat.setTimeZone(TimeZone.getTimeZone(timeZone));
    String startDate = dateFormat.format(date);

    List<String> expectedInstances = new ArrayList<String>();
    for (String candidatePartition : candidatePartitions) {
        if (candidatePartition.compareTo(startDate) < 0) {
            expectedInstances.add(candidatePartition);
            instancePaths.append("[").append(candidatePartition).append("; in],");
        }/*from w  w  w.  ja v a2  s  .  c om*/
    }

    return expectedInstances;
}

From source file:org.apache.falcon.lifecycle.TableStorageFeedEvictorIT.java

private void verifyMultiColDatedFSPartitionsAreDeleted(List<Map<String, String>> candidatePartitions, Date date,
        String timeZone) throws Exception {

    FileSystem fs = new Path(MULTI_COL_DATED_EXTERNAL_TABLE_LOCATION).getFileSystem(new Configuration());

    DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
    dateFormat.setTimeZone(TimeZone.getTimeZone(timeZone));
    String startDate = dateFormat.format(date);

    for (Map<String, String> partition : candidatePartitions) {
        String partDate = partition.get("year") + partition.get("month") + partition.get("day");
        final String path = MULTI_COL_DATED_EXTERNAL_TABLE_LOCATION + partition.get("year") + "/"
                + partition.get("month") + "/" + partition.get("day") + "/region=in";
        if (partDate.compareTo(startDate) < 0 && fs.exists(new Path(path))) {
            Assert.fail("Expecting " + path + " to be deleted");
        }/*from  ww w  .j av a2  s  .  c om*/
    }
}

From source file:org.apache.falcon.lifecycle.TableStorageFeedEvictorIT.java

private List<HCatPartition> getMultiColDatedFilteredPartitions(String tableName, String timeZone,
        Pair<Date, Date> range) throws HCatException {
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    dateFormat.setTimeZone(TimeZone.getTimeZone(timeZone));

    Calendar calendar = Calendar.getInstance();
    calendar.setTime(range.first);/*from ww  w .  ja v a 2  s .  com*/
    String[] dateCols = dateFormat.format(calendar.getTime()).split("-");
    // filter eg: "(year < '2014') or (year = '2014' and month < '02') or
    // (year = '2014' and month = '02' and day < '24')"
    String filter1 = "(year < '" + dateCols[0] + "')";
    String filter2 = "(year = '" + dateCols[0] + "' and month < '" + dateCols[1] + "')";
    String filter3 = "(year = '" + dateCols[0] + "' and month = '" + dateCols[1] + "' and day < '" + dateCols[2]
            + "')";
    String filter = filter1 + " or " + filter2 + " or " + filter3;
    return client.listPartitionsByFilter(DATABASE_NAME, tableName, filter);
}

From source file:org.apache.falcon.lifecycle.TableStorageFeedEvictorIT.java

public List<Map<String, String>> getMultiColDatedExpectedEvictedInstances(
        List<Map<String, String>> candidatePartitions, Date date, String timeZone, StringBuilder instancePaths)
        throws Exception {
    instancePaths.append("instancePaths=");

    DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
    dateFormat.setTimeZone(TimeZone.getTimeZone(timeZone));
    String startDate = dateFormat.format(date);

    List<Map<String, String>> expectedInstances = new ArrayList<Map<String, String>>();
    for (Map<String, String> partition : candidatePartitions) {
        String partDate = partition.get("year") + partition.get("month") + partition.get("day");
        if (partDate.compareTo(startDate) < 0) {
            expectedInstances.add(partition);
            instancePaths.append("[").append(partition.values().toString().replace(",", ";")).append("; in],");
        }/*from  w  ww. j  av  a  2 s .  c  om*/
    }

    return expectedInstances;
}

From source file:org.sakaiproject.assignment2.logic.impl.ExternalLogicImpl.java

public DateFormat getDateFormat(Integer optionalDateStyle, Integer optionalTimeStyle, Locale locale,
        boolean currentUserTimezone) {
    int dateStyle = optionalDateStyle != null ? optionalDateStyle : DateFormat.MEDIUM;
    int timeStyle = optionalTimeStyle != null ? optionalTimeStyle : DateFormat.SHORT;

    DateFormat df = DateFormat.getDateTimeInstance(dateStyle, timeStyle, locale);
    if (currentUserTimezone) {
        df.setTimeZone(timeService.getLocalTimeZone());
    }//from  w  w w . j  a  va  2  s  . c  om

    return df;
}

From source file:org.apache.directory.studio.connection.core.io.jndi.LdifSearchLogger.java

/**
 * Logs the given text to the search logger of the given connection.
 * //from  w  w w  .  ja  v a  2  s  .  c o  m
 * @param text the text to log
 * @param type the type, either SEARCH REQUEST or SEARCH RESULT
 * @param ex the naming exception if an error occurred, null otherwise
 * @param connection the connection
 */
private void log(String text, String type, NamingException ex, Connection connection) {
    String id = connection.getId();
    if (!loggers.containsKey(id)) {
        if (connection.getName() != null) {
            initSearchLogger(connection);
        }
    }

    if (loggers.containsKey(id)) {
        Logger logger = loggers.get(id);
        DateFormat df = new SimpleDateFormat(ConnectionCoreConstants.DATEFORMAT);
        df.setTimeZone(ConnectionCoreConstants.UTC_TIME_ZONE);

        if (ex != null) {
            logger.log(Level.ALL, LdifCommentLine.create("#!" + type + " ERROR") //$NON-NLS-1$//$NON-NLS-2$
                    .toFormattedString(LdifFormatParameters.DEFAULT));
        } else {
            logger.log(Level.ALL, LdifCommentLine.create("#!" + type + " OK") //$NON-NLS-1$//$NON-NLS-2$
                    .toFormattedString(LdifFormatParameters.DEFAULT));
        }

        logger.log(Level.ALL,
                LdifCommentLine
                        .create("#!CONNECTION ldap://" + connection.getHost() + ":" + connection.getPort()) //$NON-NLS-1$//$NON-NLS-2$
                        .toFormattedString(LdifFormatParameters.DEFAULT));
        logger.log(Level.ALL, LdifCommentLine.create("#!DATE " + df.format(new Date())) //$NON-NLS-1$
                .toFormattedString(LdifFormatParameters.DEFAULT));

        if (ex != null) {
            String errorComment = "#!ERROR " + ex.getMessage(); //$NON-NLS-1$
            errorComment = errorComment.replaceAll("\r", " "); //$NON-NLS-1$ //$NON-NLS-2$
            errorComment = errorComment.replaceAll("\n", " "); //$NON-NLS-1$ //$NON-NLS-2$
            LdifCommentLine errorCommentLine = LdifCommentLine.create(errorComment);
            logger.log(Level.ALL, errorCommentLine.toFormattedString(LdifFormatParameters.DEFAULT));
        }

        logger.log(Level.ALL, text);
    }
}

From source file:com.ternup.caddisfly.fragment.ResultFragment.java

public void postResult(final String url) {

    RequestParams params = new RequestParams();
    TimeZone tz = TimeZone.getTimeZone("UTC");
    final DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
    df.setTimeZone(tz);

    final ArrayList<String> filePaths = FileUtils.getFilePaths(getActivity(), folderName, "/small/",
            mLocationId);/*from   www.  ja  v a 2s. co m*/
    File myFile = new File(filePaths.get(0));
    String date = df.format(DateUtils.getDateFromFilename(myFile.getName()));

    params.put("date", date);
    String deviceId = Build.MANUFACTURER + " " + Build.MODEL;
    if (deviceId.length() > 32) {
        deviceId = deviceId.substring(1, 32);
    }
    params.put("deviceId", deviceId);
    params.put("type", String.valueOf(mTestTypeId + 1));

    if (wakeLock == null || !wakeLock.isHeld()) {
        PowerManager pm = (PowerManager) getActivity().getApplicationContext()
                .getSystemService(Context.POWER_SERVICE);
        wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP
                | PowerManager.ON_AFTER_RELEASE, "MyWakeLock");
        wakeLock.acquire();
    }

    WebClient.post("tests", params, new AsyncHttpResponseHandler() {
        @Override
        public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
            String response = responseBody == null ? null : new String(responseBody);
            try {
                JSONObject json = new JSONObject(response);
                final int newId = json.getInt("id");
                if (filePaths.size() > 0) {
                    count = 0;
                    totalCount = filePaths.size();
                    postItem(newId, filePaths);
                }

            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
            Log.d(Globals.DEBUG_TAG, "fail: " + error.getMessage());
            getActivity().runOnUiThread(new Runnable() {
                public void run() {
                    if (progressDialog != null) {
                        progressDialog.dismiss();
                    }

                    if (wakeLock != null && wakeLock.isHeld()) {
                        wakeLock.release();
                    }
                }
            });

        }
    });
}

From source file:org.apache.falcon.lifecycle.TableStorageFeedEvictorIT.java

public List<String> getCandidatePartitions(String retentionLimit, String dateMask, String timeZone, int limit)
        throws Exception {
    List<String> partitions = new ArrayList<String>();

    Pair<Date, Date> range = getDateRange(retentionLimit);

    DateFormat dateFormat = new SimpleDateFormat(dateMask);
    dateFormat.setTimeZone(TimeZone.getTimeZone(timeZone));

    String startDate = dateFormat.format(range.first);
    partitions.add(startDate);/*from  ww  w  .  j a v a  2s  . c o m*/

    Calendar calendar = Calendar.getInstance();
    calendar.setTime(range.first);
    for (int i = 1; i <= limit; i++) {
        calendar.add(Calendar.DAY_OF_MONTH, -(i + 1));
        partitions.add(dateFormat.format(calendar.getTime()));
    }

    calendar.setTime(range.second);
    for (int i = 1; i <= limit; i++) {
        calendar.add(Calendar.DAY_OF_MONTH, -(i + 1));
        partitions.add(dateFormat.format(calendar.getTime()));
    }

    return partitions;
}

From source file:gov.wa.wsdot.android.wsdot.ui.ferries.departures.FerriesRouteSchedulesDayDeparturesActivity.java

/**
 * Updates global array adapter with new day strings from schedule
 * @param schedule ferry schedule data//from w w w .  ja  v  a  2 s.  c  o m
 */
private void setDaySpinner(ArrayList<FerriesScheduleDateItem> schedule) {

    mDayOfWeekArrayAdapter.clear();

    DateFormat dateFormat = new SimpleDateFormat("EEEE");
    dateFormat.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));

    int numDates = schedule.size();
    for (int i = 0; i < numDates; i++) {
        if (!schedule.get(i).getFerriesTerminalItem().isEmpty()) {
            mDayOfWeekArrayAdapter.add(dateFormat.format(schedule.get(i).getDate()));
        }
    }

    mDaySpinner.setSelection(mDayIndex);

}

From source file:com.rogchen.common.xml.UtilDateTime.java

/**
 * Localized Timestamp to String conversion. To be used in tandem with
 * stringToTimeStamp().//from  w  w  w  .  ja v  a  2 s  .co  m
 */
public static String timeStampToString(Timestamp stamp, String dateTimeFormat, TimeZone tz, Locale locale) {
    DateFormat dateFormat = toDateTimeFormat(dateTimeFormat, tz, locale);
    dateFormat.setTimeZone(tz);
    return dateFormat.format(stamp);
}