List of usage examples for java.util TimeZone getDefault
public static TimeZone getDefault()
From source file:com.whizzosoftware.hobson.scheduler.ical.ICalTaskProviderTest.java
@Test public void testSunOffsetWithNoLatLong() throws Exception { TimeZone tz = TimeZone.getDefault(); // an event that runs every day at midnight String ical = "BEGIN:VCALENDAR\n" + "VERSION:2.0\n" + "BEGIN:VEVENT\n" + "UID:15dee4fe-a841-4cf6-8d7f-76c3ad5492b1\n" + "DTSTART:20140701T000000\n" + "RRULE:FREQ=DAILY\n" + "X-SUN-OFFSET:SS30\n" + "SUMMARY:My Task\n" + "COMMENT:[{'pluginId':'com.whizzosoftware.hobson.server-api','actionId':'log','name':'My Action','properties':{'message':'Test'}}]\n" + "END:VEVENT\n" + "END:VCALENDAR"; // start the scheduler after the task should have run MockScheduledTaskExecutor executor = new MockScheduledTaskExecutor(); MockActionManager actionManager = new MockActionManager(); ICalTaskProvider s = new ICalTaskProvider("pluginId", null, null, tz); s.setScheduleExecutor(executor);/* w ww.ja va 2s . c o m*/ s.setActionManager(actionManager); s.loadICSStream(new ByteArrayInputStream(ical.getBytes()), DateHelper.getTime(tz, 2014, 7, 1, 22, 0, 0)); assertEquals(1, s.getTasks().size()); ICalTask t = (ICalTask) s.getTasks().iterator().next(); assertTrue(t.getProperties().containsKey(ICalTask.PROP_ERROR)); }
From source file:com.trial.phonegap.plugin.calendar.CalendarAccessorGoogle.java
/** * Transforms a JSONObject object with information about an event in an event object * @param JsonEvent an JSONObject object with data about an event * @return an event object with te information within JSONObject object given by parameter * @throws JSONException//from w w w .ja v a2 s .com */ private Event jsonEventToEvent(JSONObject jsonEvent) throws JSONException { Event event = new Event(); if (!jsonEvent.isNull("id")) { event.setId(jsonEvent.getString("id")); } if (!jsonEvent.isNull("recurrence")) { Recurrence recurrence = new Recurrence(); recurrence.setRule(parseJsonRecurrenceRule(jsonEvent.getJSONObject("recurrence"))); if (!(jsonEvent.isNull("start")) && (!jsonEvent.isNull("end"))) { Dt dt = new Dt(); dt.setDate(DateUtils.stringCalendarDateToDateLocale(jsonEvent.getString("start"), "yyyy-MM-dd HH:mm:ss")); TimeZone tm = TimeZone.getDefault(); tm.setID(Locale.getDefault().getISO3Country()); dt.setTimeZone(tm.getDisplayName()); recurrence.setDtStart(dt); dt.setDate(DateUtils.stringCalendarDateToDateLocale(jsonEvent.getString("end"), "yyyy-MM-dd HH:mm:ss")); recurrence.setDtEnd(dt); } event.setRecurrence(recurrence); } if (!jsonEvent.isNull("description")) { event.setTitle(jsonEvent.getString("description")); } if (!jsonEvent.isNull("location")) { List<Where> whereList = new ArrayList<Where>(); Where where = new Where(); where.description = jsonEvent.getString("location"); whereList.add(where); event.setWhere(whereList); } if (jsonEvent.isNull("summary")) event.setSummary(jsonEvent.getString("summary")); if (jsonEvent.isNull("status")) event.setEventStatus(constantSelector(jsonEvent.getString("status"))); if (jsonEvent.isNull("transparency")) event.setTransparency(constantSelector(jsonEvent.getString("transparency"))); if (jsonEvent.isNull("recurrence")) { List<When> whenList = new ArrayList<When>(); When when = new When(); if (!jsonEvent.isNull("start")) when.startTime = new DateTime(DateUtils.stringCalendarDateToDateLocale(jsonEvent.getString("start"), "yyyy-MM-dd HH:mm:ss")); if (!jsonEvent.isNull("end")) when.endTime = new DateTime(DateUtils.stringCalendarDateToDateLocale(jsonEvent.getString("end"), "yyyy-MM-dd HH:mm:ss")); if (!jsonEvent.isNull("reminder")) when.reminders = parseJsonReminder(jsonEvent.getString("reminder")); whenList.add(when); event.setWhen(whenList); } return event; }
From source file:com.funambol.json.gui.GuiServlet.java
private String doList(HttpServletRequest request) throws Exception { String group = getRequestData(request, GROUP, false); String dataStoreTypeKey = group + "." + Definitions.DATASTORETYPE; if (group == null) { return doListAll(request); }// w ww . j a v a 2s. c o m if (request.getMethod().equalsIgnoreCase("post")) { String newDataStoreType = getRequestData(request, Definitions.DATASTORETYPE); if (newDataStoreType == null) newDataStoreType = ""; if (!newDataStoreType.equals("")) { ServletProperties.getProperties().setProperty(dataStoreTypeKey, newDataStoreType); ServletProperties.saveProperties(); } } String dataStoreType = ServletProperties.getProperties().getProperty(dataStoreTypeKey, ""); String result = HTMLManager.getHtmlHeaderFor("Listing group [" + group + "]: <br>", true); Repository rep = new Repository((String) request.getSession().getAttribute("username"), TimeZone.getDefault(), "UTF-8"); if (!rep.isEmpty(group)) { result += HTMLManager.openTag(Tag.FORM, NameValuePair.parseFromStrings("method", "get", "action", "./gui")); result += HTMLManager.addFormField(KEY, "", KEYID); result += HTMLManager.addFormField(GROUP, group); result += HTMLManager.addFormField(STEP, PREPARE); result += HTMLManager.addFormField(ACTION, "", ACTIONID); result += "<table><tr><td><b>Status</b></td><td><b>Update Time</b></td><td><b>Item key</b></td><td colspan=\"2\"><b>Operations</b></td></tr>"; Iterator<String> it = rep.getAllKeys(group, new Timestamp(0), new Timestamp(System.currentTimeMillis())) .iterator(); while (it.hasNext()) { String itemKey = it.next(); if (itemKey != null) { EntityWrapper item = rep.getItemForListing(group, itemKey); char status = '?'; long updateTime = -1; if (item != null) { status = item.getStatus(); updateTime = item.getLastUpdate().getTime(); } result += "<tr><td>[" + status + "]</td><td>" + long2String(updateTime) + "</td><td>" + HTMLManager.buildHRef(APPNAME, itemKey, NameValuePair.parseFromStrings(ACTION, VIEW, GROUP, group, KEY, itemKey)) + "</td><td> " + HTMLManager.buildHtmlTag(Tag.BUTTON, "Modify", NameValuePair.parseFromStrings("onclick", "doAction('" + ACTIONID + "','" + MODIFY + "','" + KEYID + "','" + itemKey + "');", "type", "submit")) + "</td><td> " + (('D' == status) ? "Marked as deleted" : HTMLManager .buildHtmlTag(Tag.BUTTON, "Delete", NameValuePair.parseFromStrings("onclick", "doAction('" + ACTIONID + "','" + DELETE + "','" + KEYID + "','" + itemKey + "');", "type", "submit"))) + "</td></tr>"; } } result += "</table>"; result += HTMLManager.closeTag(Tag.FORM); } else { result += "No items for the group [" + group + "]"; } result += "<p>"; result += HTMLManager.addAction("addForm", "Add element", ADD, NameValuePair.parseFromStrings(STEP, PREPARE, GROUP, group), ParentTag.BOTH) + "<br>"; result += HTMLManager.getHtmlForDatastoreType(group, dataStoreType); result += HTMLManager.closePage(buildCommonFooter(request)); return result; }
From source file:de.micromata.genome.gwiki.page.GWikiContext.java
/** * Gets the user date string./*from w w w . j a v a2 s .c o m*/ * * @param date the date * @return the user date string */ public String getUserDateString(Date date) { if (date == null) { return ""; } String tz = getWikiWeb().getAuthorization().getUserProp(this, GWikiUserAuthorization.USER_TZ); tz = StringUtils.defaultIfEmpty(tz, TimeZone.getDefault().getID()); String df = getWikiWeb().getAuthorization().getUserProp(this, GWikiUserAuthorization.USER_DATEFORMAT); df = StringUtils.defaultIfEmpty(df, TimeUtils.ISO_DATETIME); return TimeUtils.formatDate(date, df, tz); }
From source file:py.una.pol.karaku.util.ControllerHelper.java
private DateTimeConverter getConverter() { DateTimeConverter converter = new DateTimeConverter(); converter.setPattern(FormatProvider.DATE_FORMAT); converter.setTimeZone(TimeZone.getDefault()); return converter; }
From source file:com.duroty.application.mail.manager.MailManager.java
/** * DOCUMENT ME!/*from w w w. ja va2 s . c om*/ * * @param hsession DOCUMENT ME! * @param repositoryName DOCUMENT ME! * @param folderName DOCUMENT ME! * @param page DOCUMENT ME! * @param messagesByPage DOCUMENT ME! * @param order DOCUMENT ME! * @param orderType DOCUMENT ME! * * @return DOCUMENT ME! * * @throws MailException DOCUMENT ME! */ public Vector getMessages(Session hsession, String repositoryName, String folderName, int page, int messagesByPage, int order, String orderType) throws MailException { Vector messages = new Vector(); try { Users user = getUser(hsession, repositoryName); Locale locale = new Locale(user.getUseLanguage()); TimeZone timeZone = TimeZone.getDefault(); Date now = new Date(); Calendar calendar = Calendar.getInstance(timeZone, locale); calendar.setTime(now); SimpleDateFormat formatter1 = new SimpleDateFormat("MMM dd", locale); SimpleDateFormat formatter2 = new SimpleDateFormat("HH:mm:ss", locale); SimpleDateFormat formatter3 = new SimpleDateFormat("MM/yy", locale); Criteria crit = hsession.createCriteria(Message.class); crit.add(Restrictions.eq("users", user)); if (folderName.equals(this.folderAll) || folderName.equals(this.folderHidden)) { crit.add(Restrictions.not(Restrictions.in("mesBox", new String[] { this.folderTrash, this.folderSpam, this.folderChat, FOLDER_DELETE }))); } else if (folderName.equals(this.folderImportant)) { crit.add(Restrictions.eq("mesFlagged", new Boolean(true))); } else { crit.add(Restrictions.eq("mesBox", folderName)); } switch (order) { case ORDER_BY_IMPORTANT: if (orderType.equals("ASC")) { crit.addOrder(Order.asc("mesFlagged")); } else { crit.addOrder(Order.desc("mesFlagged")); } break; case ORDER_BY_ADDRESS: if (orderType.equals("ASC")) { crit.addOrder(Order.asc("mesFrom")); } else { crit.addOrder(Order.desc("mesFrom")); } break; case ORDER_BY_SIZE: if (orderType.equals("ASC")) { crit.addOrder(Order.asc("mesSize")); } else { crit.addOrder(Order.desc("mesSize")); } break; case ORDER_BY_SUBJECT: if (orderType.equals("ASC")) { crit.addOrder(Order.asc("mesSubject")); } else { crit.addOrder(Order.desc("mesSubject")); } break; case ORDER_BY_DATE: if (orderType.equals("ASC")) { crit.addOrder(Order.asc("mesDate")); } else { crit.addOrder(Order.desc("mesDate")); } break; case ORDER_BY_UNREAD: if (orderType.equals("ASC")) { crit.addOrder(Order.asc("mesRecent")); } else { crit.addOrder(Order.desc("mesRecent")); } break; default: crit.addOrder(Order.desc("mesDate")); break; } crit.setFirstResult(page * messagesByPage); crit.setMaxResults(messagesByPage); ScrollableResults scroll = crit.scroll(); while (scroll.next()) { Message message = (Message) scroll.get(0); MessageObj obj = new MessageObj(message.getMesName()); obj.setBox(message.getMesBox()); obj.setFrom(message.getMesFrom()); if ((message.getAttachments() != null) && (message.getAttachments().size() > 0)) { obj.setHasAttachment(true); } else { obj.setHasAttachment(false); } int size = message.getMesSize(); size /= 1024; if (size > 1024) { size /= 1024; obj.setSize(size + " MB"); } else { obj.setSize(((size > 0) ? (size + "") : "<1") + " kB"); } if (message.getMesBox().equals(folderSent)) { try { obj.setEmail(message.getMesTo()); } catch (Exception e) { obj.setEmail("unknown to"); } } else { obj.setEmail(message.getMesFrom()); } Date date = message.getMesDate(); if (date != null) { Calendar calendar2 = Calendar.getInstance(timeZone, locale); calendar2.setTime(date); if ((calendar.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR)) && (calendar.get(Calendar.MONTH) == calendar2.get(Calendar.MONTH)) && (calendar.get(Calendar.DATE) == calendar2.get(Calendar.DATE))) { obj.setDateStr(formatter2.format(calendar2.getTime())); } else if (calendar.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR)) { obj.setDateStr(formatter1.format(calendar2.getTime())); } else { obj.setDateStr(formatter3.format(calendar2.getTime())); } } obj.setDate(date); if (message.getLabMeses() != null) { Iterator it = message.getLabMeses().iterator(); StringBuffer label = new StringBuffer(); while (it.hasNext()) { if (label.length() > 0) { label.append(", "); } LabMes labMes = (LabMes) it.next(); label.append(labMes.getId().getLabel().getLabName()); } obj.setLabel(label.toString()); } try { if (StringUtils.isBlank(message.getMesSubject())) { obj.setSubject("(no subject)"); } else { obj.setSubject(message.getMesSubject()); } } catch (Exception ex) { obj.setSubject("(no subject)"); } if (message.isMesFlagged()) { obj.setFlagged(true); } else { obj.setFlagged(false); } if (message.isMesRecent()) { obj.setRecent(true); } else { obj.setRecent(false); } String priority = "normal"; if (MessageUtilities.isHighPriority(message.getMesHeaders())) { priority = "high"; } else if (MessageUtilities.isLowPriority(message.getMesHeaders())) { priority = "low"; } obj.setPriority(priority); messages.addElement(obj); } return messages; } catch (Exception e) { throw new MailException(e); } finally { GeneralOperations.closeHibernateSession(hsession); } }
From source file:com.appeligo.alerts.KeywordAlertChecker.java
/** * @param timeZone the user's timezone/*www.j av a 2 s. c o m*/ * @param startOfDay We're using the value of earliestSmsTime (user account setting) as a starting point, * so anything before this time is credited to the previous day) * @return 12am (midnight) using system time (not user time) because "Date" objects stored in SQL * come back in system time. */ private Date calculateDay(TimeZone timeZone, Time startOfDay) { Calendar cal = Calendar.getInstance(timeZone); Calendar start = Calendar.getInstance(); start.setTimeInMillis(startOfDay.getTime()); cal.add(Calendar.HOUR_OF_DAY, 0 - start.get(Calendar.HOUR_OF_DAY)); cal.add(Calendar.MINUTE, 0 - start.get(Calendar.MINUTE)); cal.add(Calendar.SECOND, 0 - start.get(Calendar.SECOND)); cal.clear(Calendar.MILLISECOND); cal.clear(Calendar.SECOND); cal.clear(Calendar.MINUTE); cal.clear(Calendar.HOUR_OF_DAY); cal.clear(Calendar.HOUR); cal.clear(Calendar.AM_PM); TimeZone systemTimeZone = TimeZone.getDefault(); long now = System.currentTimeMillis(); long difference = systemTimeZone.getOffset(now) - timeZone.getOffset(now); return new Date(cal.getTimeInMillis() - difference); }
From source file:ca.oson.json.gson.functional.DefaultTypeAdaptersTest.java
public void testDateSerializationInCollection() throws Exception { Type listOfDates = new TypeToken<List<Date>>() { }.getType();/*ww w . jav a 2 s .c om*/ TimeZone defaultTimeZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("UTC")); Locale defaultLocale = Locale.getDefault(); Locale.setDefault(Locale.US); try { //Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd").create(); List<Date> dates = Arrays.asList(new Date(0)); String json = oson.setDateFormat("yyyy-MM-dd").toJson(dates, listOfDates); assertEquals("[\"1970-01-01\"]", json); assertEquals(0L, oson.<List<Date>>fromJson("[\"1970-01-01\"]", listOfDates).get(0).getTime()); } finally { TimeZone.setDefault(defaultTimeZone); Locale.setDefault(defaultLocale); } }
From source file:de.micromata.genome.gwiki.page.GWikiContext.java
public TimeZone getUserTimeZone() { String tz = getWikiWeb().getAuthorization().getUserProp(this, GWikiUserAuthorization.USER_TZ); tz = StringUtils.defaultIfEmpty(tz, TimeZone.getDefault().getID()); TimeZone timeZone = TimeZone.getTimeZone(tz); return timeZone; }
From source file:net.sf.jasperreports.components.headertoolbar.json.HeaderToolbarElementJsonHandler.java
protected TimeZone getFilterTimeZone(JasperPrint jasperPrint, JRGenericPrintElement element) { String formatTimeZone = element.getPropertiesMap() .getProperty(HeaderToolbarElement.PROPERTY_FORMAT_TIME_ZONE); TimeZone timeZone;//from w w w . j a va 2 s.co m if (formatTimeZone != null) { timeZone = JRDataUtils.getTimeZone(formatTimeZone); } else if (jasperPrint.getTimeZoneId() != null) { timeZone = JRDataUtils.getTimeZone(jasperPrint.getTimeZoneId()); } else { timeZone = TimeZone.getDefault(); } return timeZone; }