List of usage examples for java.util TimeZone getDisplayName
public final String getDisplayName(boolean daylight, int style)
From source file:com.github.hipchat.api.Room.java
public List<HistoryMessage> getHistory(Date date) { HipChat hc = getOrigin();//from w ww .j a v a2 s . co m Calendar c = Calendar.getInstance(); String dateString = null; String tzString = null; if (date != null) { c.setTime(date); TimeZone tz = c.getTimeZone(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); dateString = sdf.format(date); tzString = tz.getDisplayName(tz.inDaylightTime(date), TimeZone.SHORT); } else { Date tDate = new Date(); c.setTime(tDate); TimeZone tz = c.getTimeZone(); dateString = "recent"; tzString = tz.getDisplayName(tz.inDaylightTime(tDate), TimeZone.SHORT); } String query = String.format(HipChatConstants.ROOMS_HISTORY_QUERY_FORMAT, getId(), dateString, tzString, HipChatConstants.JSON_FORMAT, hc.getAuthToken()); OutputStream output = null; InputStream input = null; HttpURLConnection connection = null; List<HistoryMessage> messages = null; try { URL requestUrl = new URL(HipChatConstants.API_BASE + HipChatConstants.ROOMS_HISTORY + query); connection = (HttpURLConnection) requestUrl.openConnection(); connection.setDoInput(true); input = connection.getInputStream(); messages = MessageParser.parseRoomHistory(this, input); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(output); connection.disconnect(); } return messages; }
From source file:org.alfresco.repo.web.scripts.calendar.CalendarEntryGet.java
/** * This method replicates the pre-existing behaviour for recurring events. * Rather than try to render the text for them on the client, we instead * statically render the description text here on the server. * When we properly support recurring events in the client (and not just * for SharePoint ones), this can be replaced. *///from w w w.ja v a 2 s. c o m protected String buildRecurrenceString(CalendarEntry event) { // If there's no recurrence rules, then there's nothing to do String recurrence = event.getRecurrenceRule(); if (recurrence == null || recurrence.trim().length() == 0) { return null; } // Get our days of the week, in the current locale, for each outlook two letter code Map<String, String> days = CalendarRecurrenceHelper.buildLocalRecurrenceDaysOfTheWeek(I18NUtil.getLocale()); // Get our weeks names, in the current locale Map<Integer, String> weeks = CalendarRecurrenceHelper.buildLocalRecurrenceWeekNames(I18NUtil.getLocale()); // Turn the string into a useful map Map<String, String> params = CalendarRecurrenceHelper.extractRecurrenceRule(event); // To hold our result StringBuffer text = new StringBuffer(); // Handle the different frequencies if (params.containsKey("FREQ")) { String freq = params.get("FREQ"); String interval = params.get("INTERVAL"); if (interval == null) { interval = "1"; } if ("WEEKLY".equals(freq)) { if ("1".equals(interval)) { text.append("Occurs each week on "); } else { text.append("Occurs every " + interval + " weeks on "); } for (String day : params.get("BYDAY").split(",")) { text.append(days.get(day)); text.append(", "); } } else if ("DAILY".equals(freq)) { if ("1".equals(interval)) { text.append("Occurs every day "); } else { text.append("Occurs every " + interval + " days "); } } else if ("MONTHLY".equals(freq)) { if (params.get("BYMONTHDAY") != null) { text.append("Occurs day " + params.get("BYMONTHDAY")); } else if (params.get("BYSETPOS") != null) { text.append("Occurs the "); text.append(weeks.get((Integer.parseInt(params.get("BYSETPOS")))) + " "); buildParams(params, text, days); } text.append(" of every " + interval + " month(s) "); } else if ("YEARLY".equals(freq)) { if (params.get("BYMONTHDAY") != null) { text.append("Occurs every " + params.get("BYMONTHDAY")); text.append("." + params.get("BYMONTH") + " "); } else { text.append("Occurs the "); text.append(weeks.get((Integer.parseInt(params.get("BYSETPOS")))) + " "); buildParams(params, text, days); text.append(" of " + params.get("BYMONTH") + " month "); } } else { logger.warn("Unsupported recurrence frequency " + freq); } } // And the rest DateFormat dFormat = SimpleDateFormat.getDateInstance(SimpleDateFormat.MEDIUM, I18NUtil.getLocale()); DateFormat tFormat = SimpleDateFormat.getTimeInstance(SimpleDateFormat.SHORT, I18NUtil.getLocale()); text.append("effective " + dFormat.format(event.getStart())); if (params.containsKey("COUNT")) { // Nothing to do, is already handled in the recurrence date } if (event.getLastRecurrence() != null) { text.append(" until " + dFormat.format(event.getLastRecurrence())); } text.append(" from " + tFormat.format(event.getStart())); text.append(" to " + tFormat.format(event.getEnd())); // Add timezone in which recurrence rule was parsed TimeZone timeZone = TimeZone.getDefault(); boolean daylight = timeZone.inDaylightTime(new Date()); String tzDisplayName = timeZone.getDisplayName(daylight, TimeZone.SHORT); text.append(" (" + tzDisplayName + ")"); // All done return text.toString(); }
From source file:org.apache.oozie.servlet.BaseAdminServlet.java
@SuppressWarnings({ "unchecked", "rawtypes" }) private JSONArray availableTimeZonesToJsonArray() { JSONArray array = new JSONArray(); for (String tzId : TimeZone.getAvailableIDs()) { // skip id's that are like "Etc/GMT+01:00" because their display names are like "GMT-01:00", which is confusing if (!tzId.startsWith("Etc/GMT")) { JSONObject json = new JSONObject(); TimeZone tZone = TimeZone.getTimeZone(tzId); json.put(JsonTags.TIME_ZOME_DISPLAY_NAME, tZone.getDisplayName(false, TimeZone.SHORT) + " (" + tzId + ")"); json.put(JsonTags.TIME_ZONE_ID, tzId); array.add(json);//from w w w . jav a2s . com } } // The combo box this populates cannot be edited, so the user can't type in GMT offsets (like in the CLI), so we'll add // in some hourly offsets here (though the user will not be able to use other offsets without editing the cookie manually // and they are not in order) array.addAll(GMTOffsetTimeZones); return array; }
From source file:morphy.user.SocketChannelUserSession.java
public void send(String message) { try {/*w ww . j a v a2 s . com*/ /* this logic block should be commented out to get rid of multiple-login implementation. */ if (multipleLoginsParent != null) { List<SocketChannelUserSession> list = multipleLoginsParent.multipleLogins; multipleLoginsParent.multipleLogins = null; multipleLoginsParent.send(message); multipleLoginsParent.multipleLogins = list; } else { if (multipleLogins != null) { for (SocketChannelUserSession sess : multipleLogins) { if (sess != null) sess.send(message); } } } if (isConnected()) { String prompt = "fics% "; HashMap<String, String> map = getUser().getUserVars().getVariables(); if (map.containsKey("prompt") && map.containsKey("ptime") && map.containsKey("tzone")) { prompt = map.get("prompt"); boolean useptime = map.get("ptime").equals("1"); if (useptime) { Date d = new Date(); java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("HH:mm"); String tzone = getUser().getUserVars().getVariables().get("tzone").toUpperCase(); TimeZone tz = TimeZone.getDefault(); if (tzone.equals("SERVER")) tzone = tz.getDisplayName(tz.inDaylightTime(d), TimeZone.SHORT); sdf.setTimeZone(TimeZoneUtils.getTimeZone(tzone)); prompt = sdf.format(d) + "_" + prompt; } } ByteBuffer buffer = BufferUtils.createBuffer( SocketConnectionService.getInstance().formatMessage(this, message + "\n" + prompt + " ")); System.out.println((message + "\n\r" + prompt + " ").replace("\n", "\\n").replace("\r", "\\r")); try { channel.write(buffer); } catch (java.io.IOException e) { Morphy.getInstance().onError("IOException while trying to write to channel.", e); } } else { if (LOG.isInfoEnabled()) { LOG.info("Tried to send message to a logged off user " + user.getUserName() + " " + message); } disconnect(); } } catch (Throwable t) { if (LOG.isErrorEnabled()) LOG.error("Error sending message to user " + user.getUserName() + " " + message, t); disconnect(); } }
From source file:org.apache.cordova.core.Globalization.java
private JSONObject getDatePattern(JSONArray options) throws GlobalizationError { JSONObject obj = new JSONObject(); try {//from w w w . j a v a 2 s. c o m SimpleDateFormat fmtDate = (SimpleDateFormat) android.text.format.DateFormat .getDateFormat(this.cordova.getActivity()); //default user preference for date SimpleDateFormat fmtTime = (SimpleDateFormat) android.text.format.DateFormat .getTimeFormat(this.cordova.getActivity()); //default user preference for time String fmt = fmtDate.toLocalizedPattern() + " " + fmtTime.toLocalizedPattern(); //default SHORT date/time format. ex. dd/MM/yyyy h:mm a //get Date value + options (if available) if (options.getJSONObject(0).has(OPTIONS)) { //options were included JSONObject innerOptions = options.getJSONObject(0).getJSONObject(OPTIONS); //get formatLength option if (!innerOptions.isNull(FORMATLENGTH)) { String fmtOpt = innerOptions.getString(FORMATLENGTH); if (fmtOpt.equalsIgnoreCase(MEDIUM)) {//medium fmtDate = (SimpleDateFormat) android.text.format.DateFormat .getMediumDateFormat(this.cordova.getActivity()); } else if (fmtOpt.equalsIgnoreCase(LONG) || fmtOpt.equalsIgnoreCase(FULL)) { //long/full fmtDate = (SimpleDateFormat) android.text.format.DateFormat .getLongDateFormat(this.cordova.getActivity()); } } //return pattern type fmt = fmtDate.toLocalizedPattern() + " " + fmtTime.toLocalizedPattern(); if (!innerOptions.isNull(SELECTOR)) { String selOpt = innerOptions.getString(SELECTOR); if (selOpt.equalsIgnoreCase(DATE)) { fmt = fmtDate.toLocalizedPattern(); } else if (selOpt.equalsIgnoreCase(TIME)) { fmt = fmtTime.toLocalizedPattern(); } } } //TimeZone from users device //TimeZone tz = Calendar.getInstance(Locale.getDefault()).getTimeZone(); //substitute method TimeZone tz = TimeZone.getTimeZone(Time.getCurrentTimezone()); obj.put("pattern", fmt); obj.put("timezone", tz.getDisplayName(tz.inDaylightTime(Calendar.getInstance().getTime()), TimeZone.SHORT)); obj.put("utc_offset", tz.getRawOffset() / 1000); obj.put("dst_offset", tz.getDSTSavings() / 1000); return obj; } catch (Exception ge) { throw new GlobalizationError(GlobalizationError.PATTERN_ERROR); } }
From source file:org.apache.cordova.Globalization.java
private JSONObject getDatePattern(JSONArray options) throws GlobalizationError { JSONObject obj = new JSONObject(); try {//from ww w. ja v a 2s .co m SimpleDateFormat fmtDate = (SimpleDateFormat) android.text.format.DateFormat .getDateFormat(this.cordova.getActivity()); //default user preference for date SimpleDateFormat fmtTime = (SimpleDateFormat) android.text.format.DateFormat .getTimeFormat(this.cordova.getActivity()); //default user preference for time String fmt = fmtDate.toLocalizedPattern() + " " + fmtTime.toLocalizedPattern(); //default SHORT date/time format. ex. dd/MM/yyyy h:mm a //get Date value + options (if available) boolean test = options.getJSONObject(0).has(OPTIONS); if (options.getJSONObject(0).has(OPTIONS)) { //options were included JSONObject innerOptions = options.getJSONObject(0).getJSONObject(OPTIONS); //get formatLength option if (!innerOptions.isNull(FORMATLENGTH)) { String fmtOpt = innerOptions.getString(FORMATLENGTH); if (fmtOpt.equalsIgnoreCase(MEDIUM)) {//medium fmtDate = (SimpleDateFormat) android.text.format.DateFormat .getMediumDateFormat(this.cordova.getActivity()); } else if (fmtOpt.equalsIgnoreCase(LONG) || fmtOpt.equalsIgnoreCase(FULL)) { //long/full fmtDate = (SimpleDateFormat) android.text.format.DateFormat .getLongDateFormat(this.cordova.getActivity()); } } //return pattern type fmt = fmtDate.toLocalizedPattern() + " " + fmtTime.toLocalizedPattern(); if (!innerOptions.isNull(SELECTOR)) { String selOpt = innerOptions.getString(SELECTOR); if (selOpt.equalsIgnoreCase(DATE)) { fmt = fmtDate.toLocalizedPattern(); } else if (selOpt.equalsIgnoreCase(TIME)) { fmt = fmtTime.toLocalizedPattern(); } } } //TimeZone from users device //TimeZone tz = Calendar.getInstance(Locale.getDefault()).getTimeZone(); //substitute method TimeZone tz = TimeZone.getTimeZone(Time.getCurrentTimezone()); obj.put("pattern", fmt); obj.put("timezone", tz.getDisplayName(tz.inDaylightTime(Calendar.getInstance().getTime()), TimeZone.SHORT)); obj.put("utc_offset", tz.getRawOffset() / 1000); obj.put("dst_offset", tz.getDSTSavings() / 1000); return obj; } catch (Exception ge) { throw new GlobalizationError(GlobalizationError.PATTERN_ERROR); } }
From source file:org.apache.oozie.cli.OozieCLI.java
private void printAvailableTimeZones() { System.out.println("The format is \"SHORT_NAME (ID)\"\nGive the ID to the -timezone argument"); System.out.println("GMT offsets can also be used (e.g. GMT-07:00, GMT-0700, GMT+05:30, GMT+0530)"); System.out.println("Available Time Zones:"); for (String tzId : TimeZone.getAvailableIDs()) { // skip id's that are like "Etc/GMT+01:00" because their display names are like "GMT-01:00", which is confusing if (!tzId.startsWith("Etc/GMT")) { TimeZone tZone = TimeZone.getTimeZone(tzId); System.out.println(" " + tZone.getDisplayName(false, TimeZone.SHORT) + " (" + tzId + ")"); }// w ww . ja va 2 s . c o m } }
From source file:org.sakaiproject.portal.charon.SkinnableCharonPortal.java
public void includeBottom(PortalRenderContext rcontext) { if (rcontext.uses(INCLUDE_BOTTOM)) { String thisUser = SessionManager.getCurrentSessionUserId(); //Get user preferences PreferencesService preferencesService = (PreferencesService) ComponentManager .get(PreferencesService.class); Preferences prefs = preferencesService.getPreferences(thisUser); boolean showServerTime = ServerConfigurationService.getBoolean("portal.show.time", true); if (showServerTime) { rcontext.put("showServerTime", "true"); Calendar now = Calendar.getInstance(); Date nowDate = new Date(now.getTimeInMillis()); //first set server date and time TimeZone serverTz = TimeZone.getDefault(); now.setTimeZone(serverTz);//from w ww .j a v a2 s . com rcontext.put("serverTzDisplay", serverTz.getDisplayName(serverTz.inDaylightTime(nowDate), TimeZone.SHORT)); rcontext.put("serverTzGMTOffset", String.valueOf( now.getTimeInMillis() + now.get(Calendar.ZONE_OFFSET) + now.get(Calendar.DST_OFFSET))); //provide the user's preferred timezone information if it is different //Get the Properties object that holds user's TimeZone preferences ResourceProperties tzprops = prefs.getProperties(TimeService.APPLICATION_ID); //Get the ID of the timezone using the timezone key. //Default to 'localTimeZone' (server timezone?) String preferredTzId = (String) tzprops.get(TimeService.TIMEZONE_KEY); if (preferredTzId != null && !preferredTzId.equals(serverTz.getID())) { TimeZone preferredTz = TimeZone.getTimeZone(preferredTzId); now.setTimeZone(preferredTz); rcontext.put("showPreferredTzTime", "true"); //now set up the portal information rcontext.put("preferredTzDisplay", preferredTz.getDisplayName(preferredTz.inDaylightTime(nowDate), TimeZone.SHORT)); rcontext.put("preferredTzGMTOffset", String.valueOf( now.getTimeInMillis() + now.get(Calendar.ZONE_OFFSET) + now.get(Calendar.DST_OFFSET))); } else { rcontext.put("showPreferredTzTime", "false"); } } rcontext.put("pagepopup", false); String copyright = ServerConfigurationService.getString("bottom.copyrighttext"); /** * Replace keyword in copyright message from sakai.properties * with the server's current year to auto-update of Copyright end date */ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy"); String currentServerYear = simpleDateFormat.format(new Date()); copyright = copyright.replaceAll(SERVER_COPYRIGHT_CURRENT_YEAR_KEYWORD, currentServerYear); String service = ServerConfigurationService.getString("ui.service", "Sakai"); String serviceVersion = ServerConfigurationService.getString("version.service", "?"); String sakaiVersion = ServerConfigurationService.getString("version.sakai", "?"); String server = ServerConfigurationService.getServerId(); String[] bottomNav = ServerConfigurationService.getStrings("bottomnav"); String[] poweredByUrl = ServerConfigurationService.getStrings("powered.url"); String[] poweredByImage = ServerConfigurationService.getStrings("powered.img"); String[] poweredByAltText = ServerConfigurationService.getStrings("powered.alt"); { List<Object> l = new ArrayList<Object>(); if ((bottomNav != null) && (bottomNav.length > 0)) { for (int i = 0; i < bottomNav.length; i++) { l.add(bottomNav[i]); } } rcontext.put("bottomNav", l); } boolean neoChatAvailable = ServerConfigurationService.getBoolean("portal.neochat", true) && chatHelper.checkChatPermitted(thisUser); rcontext.put("neoChat", neoChatAvailable); rcontext.put("portalChatPollInterval", ServerConfigurationService.getInt("portal.chat.pollInterval", 5000)); rcontext.put("neoAvatar", ServerConfigurationService.getBoolean("portal.neoavatar", true)); rcontext.put("neoChatVideo", ServerConfigurationService.getBoolean("portal.chat.video", true)); rcontext.put("portalVideoChatTimeout", ServerConfigurationService.getInt("portal.chat.video.timeout", 25)); if (sakaiTutorialEnabled && thisUser != null) { if (!("1".equals(prefs.getProperties().getProperty("sakaiTutorialFlag")))) { rcontext.put("tutorial", true); //now save this in the user's prefefences so we don't show it again PreferencesEdit preferences = null; SecurityAdvisor secAdv = null; try { secAdv = new SecurityAdvisor() { @Override public SecurityAdvice isAllowed(String userId, String function, String reference) { if ("prefs.add".equals(function) || "prefs.upd".equals(function)) { return SecurityAdvice.ALLOWED; } return null; } }; securityService.pushAdvisor(secAdv); try { preferences = preferencesService.edit(thisUser); } catch (IdUnusedException ex1) { try { preferences = preferencesService.add(thisUser); } catch (IdUsedException ex2) { M_log.error(ex2); } catch (PermissionException ex3) { M_log.error(ex3); } } if (preferences != null) { ResourcePropertiesEdit props = preferences.getPropertiesEdit(); props.addProperty("sakaiTutorialFlag", "1"); preferencesService.commit(preferences); } } catch (Exception e1) { M_log.error(e1); } finally { if (secAdv != null) { securityService.popAdvisor(secAdv); } } } } // rcontext.put("bottomNavSitNewWindow", // Web.escapeHtml(rb.getString("site_newwindow"))); if ((poweredByUrl != null) && (poweredByImage != null) && (poweredByAltText != null) && (poweredByUrl.length == poweredByImage.length) && (poweredByUrl.length == poweredByAltText.length)) { { List<Object> l = new ArrayList<Object>(); for (int i = 0; i < poweredByUrl.length; i++) { Map<String, Object> m = new HashMap<String, Object>(); m.put("poweredByUrl", poweredByUrl[i]); m.put("poweredByImage", poweredByImage[i]); m.put("poweredByAltText", poweredByAltText[i]); l.add(m); } rcontext.put("bottomNavPoweredBy", l); } } else { List<Object> l = new ArrayList<Object>(); Map<String, Object> m = new HashMap<String, Object>(); m.put("poweredByUrl", "http://sakaiproject.org"); m.put("poweredByImage", "/library/image/sakai_powered.gif"); m.put("poweredByAltText", "Powered by Sakai"); l.add(m); rcontext.put("bottomNavPoweredBy", l); } rcontext.put("bottomNavService", service); rcontext.put("bottomNavCopyright", copyright); rcontext.put("bottomNavServiceVersion", serviceVersion); rcontext.put("bottomNavSakaiVersion", sakaiVersion); rcontext.put("bottomNavServer", server); // SAK-25931 - Do not remove this from session here - removal is done by /direct Session s = SessionManager.getCurrentSession(); String userWarning = (String) s.getAttribute("userWarning"); rcontext.put("userWarning", new Boolean(StringUtils.isNotEmpty(userWarning))); if (ServerConfigurationService.getBoolean("pasystem.enabled", false)) { PASystem paSystem = (PASystem) ComponentManager.get(PASystem.class); rcontext.put("paSystemEnabled", true); rcontext.put("paSystem", paSystem); } } }
From source file:com.mozilla.SUTAgentAndroid.service.DoCommand.java
public String GetTimeZone() { String sRet = ""; TimeZone tz; tz = TimeZone.getDefault();/* w ww . ja va2 s .c o m*/ Date now = new Date(); sRet = tz.getDisplayName(tz.inDaylightTime(now), TimeZone.LONG); return (sRet); }
From source file:com.mozilla.SUTAgentAndroid.service.DoCommand.java
public String SetTimeZone(String sTimeZone) { String sRet = "Unable to set timezone to " + sTimeZone; TimeZone tz = null; AlarmManager amgr = null;/*ww w . j a v a2 s. c o m*/ if ((sTimeZone.length() > 0) && (sTimeZone.startsWith("GMT"))) { amgr = (AlarmManager) contextWrapper.getSystemService(Context.ALARM_SERVICE); if (amgr != null) amgr.setTimeZone(sTimeZone); } else { String[] zoneNames = TimeZone.getAvailableIDs(); int nNumMatches = zoneNames.length; int lcv = 0; for (lcv = 0; lcv < nNumMatches; lcv++) { if (zoneNames[lcv].equalsIgnoreCase(sTimeZone)) break; } if (lcv < nNumMatches) { amgr = (AlarmManager) contextWrapper.getSystemService(Context.ALARM_SERVICE); if (amgr != null) amgr.setTimeZone(zoneNames[lcv]); } } if (amgr != null) { tz = TimeZone.getDefault(); Date now = new Date(); sRet = tz.getDisplayName(tz.inDaylightTime(now), TimeZone.LONG); } return (sRet); }