List of usage examples for java.util TimeZone inDaylightTime
public abstract boolean inDaylightTime(Date date);
From source file:com.mi.xserv.XservBase.java
protected int getTimeZoneDst() { // Daylight savings Date today = new Date(); TimeZone timezone = TimeZone.getDefault(); boolean isDST = timezone.inDaylightTime(today); return isDST ? 1 : 0; }
From source file:com.onesignal.OneSignal.java
private static int getTimeZoneOffset() { TimeZone timezone = Calendar.getInstance().getTimeZone(); int offset = timezone.getRawOffset(); if (timezone.inDaylightTime(new Date())) offset = offset + timezone.getDSTSavings(); return offset / 1000; }
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. *//* w ww .jav a 2s. c om*/ 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:com.github.hipchat.api.Room.java
public List<HistoryMessage> getHistory(Date date) { HipChat hc = getOrigin();/* w ww .java2 s . c o 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:com.mirth.connect.client.ui.StatusBar.java
private String convertLocalToServerTime() { TimeZone localTimeZone = TimeZone.getTimeZone(this.localTimeZone); TimeZone serverTimeZone = TimeZone.getTimeZone(this.serverTimeZone); Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.MILLISECOND, (int) timeOffset); calendar.add(Calendar.MILLISECOND, localTimeZone.getRawOffset() * -1); if (localTimeZone.inDaylightTime(calendar.getTime())) { calendar.add(Calendar.MILLISECOND, localTimeZone.getDSTSavings() * -1); }/*from w w w .ja va2 s . c o m*/ calendar.add(Calendar.MILLISECOND, serverTimeZone.getRawOffset()); if (serverTimeZone.inDaylightTime(calendar.getTime())) { calendar.add(Calendar.MILLISECOND, serverTimeZone.getDSTSavings()); } return new SimpleDateFormat("h:mm a").format(calendar.getTime()); }
From source file:com.exadel.flamingo.flex.messaging.amf.io.AMF0Deserializer.java
/** * Reads date//w ww . j ava 2 s . co m * * @return * @throws IOException */ protected Date readDate() throws IOException { long ms = (long) inputStream.readDouble(); // Date in millis from 01/01/1970 // here we have to read in the raw // timezone offset (which comes in minutes, but incorrectly signed), // make it millis, and fix the sign. int timeoffset = inputStream.readShort() * 60000 * -1; // now we have millis TimeZone serverTimeZone = TimeZone.getDefault(); // now we subtract the current timezone offset and add the one that was passed // in (which is of the Flash client), which gives us the appropriate ms (i think) // -alon Calendar sent = new GregorianCalendar(); sent.setTime((new Date(ms - serverTimeZone.getRawOffset() + timeoffset))); TimeZone sentTimeZone = sent.getTimeZone(); // we have to handle daylight savings ms as well if (sentTimeZone.inDaylightTime(sent.getTime())) { // // Implementation note: we are trying to maintain compatibility // with J2SE 1.3.1 // // As such, we can't use java.util.Calendar.getDSTSavings() here // sent.setTime(new java.util.Date(sent.getTime().getTime() - 3600000)); } return sent.getTime(); }
From source file:org.openbravo.advpaymentmngt.utility.FIN_Utility.java
/** * Returns the amount of days between two given dates *///from w w w . j av a 2s. co m public static Long getDaysBetween(Date beginDate, Date endDate) { final TimeZone tz = TimeZone.getDefault(); final long nowDstOffset = (tz.inDaylightTime(beginDate)) ? tz.getDSTSavings() : 0L; final long dateDstOffset = (tz.inDaylightTime(endDate)) ? tz.getDSTSavings() : 0L; return (endDate.getTime() + dateDstOffset - beginDate.getTime() - nowDstOffset) / DateUtils.MILLIS_PER_DAY; }
From source file:morphy.user.SocketChannelUserSession.java
public void send(String message) { try {//from w w w . j a v a 2 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 getIsDayLightSavingsTime(JSONArray options) throws GlobalizationError { JSONObject obj = new JSONObject(); boolean dst = false; try {//from w ww. j a v a2s. c o m Date date = new Date((Long) options.getJSONObject(0).get(DATE)); //TimeZone tz = Calendar.getInstance(Locale.getDefault()).getTimeZone(); TimeZone tz = TimeZone.getTimeZone(Time.getCurrentTimezone()); dst = tz.inDaylightTime(date); //get daylight savings data from date object and user timezone settings return obj.put("dst", dst); } catch (Exception ge) { throw new GlobalizationError(GlobalizationError.UNKNOWN_ERROR); } }
From source file:org.apache.cordova.core.Globalization.java
private JSONObject getDatePattern(JSONArray options) throws GlobalizationError { JSONObject obj = new JSONObject(); try {// w ww . ja v a 2 s. 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) 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); } }