List of usage examples for org.joda.time DateTimeZone forID
@FromString public static DateTimeZone forID(String id)
From source file:azkaban.trigger.builtin.BasicTimeChecker.java
License:Apache License
public static BasicTimeChecker createFromJson(HashMap<String, Object> obj) throws Exception { Map<String, Object> jsonObj = (HashMap<String, Object>) obj; if (!jsonObj.get("type").equals(type)) { throw new Exception("Cannot create checker of " + type + " from " + jsonObj.get("type")); }/*from w ww.j av a 2 s.c o m*/ Long firstCheckTime = Long.valueOf((String) jsonObj.get("firstCheckTime")); String timezoneId = (String) jsonObj.get("timezone"); long nextCheckTime = Long.valueOf((String) jsonObj.get("nextCheckTime")); DateTimeZone timezone = DateTimeZone.forID(timezoneId); boolean isRecurring = Boolean.valueOf((String) jsonObj.get("isRecurring")); boolean skipPastChecks = Boolean.valueOf((String) jsonObj.get("skipPastChecks")); ReadablePeriod period = Utils.parsePeriodString((String) jsonObj.get("period")); String id = (String) jsonObj.get("id"); BasicTimeChecker checker = new BasicTimeChecker(id, firstCheckTime, timezone, nextCheckTime, isRecurring, skipPastChecks, period); if (skipPastChecks) { checker.updateNextCheckTime(); } return checker; }
From source file:azkaban.webapp.AzkabanWebServer.java
License:Apache License
/** * Constructor//from ww w. j a va 2 s . c om */ public AzkabanWebServer(Server server, Props props) throws Exception { this.props = props; this.server = server; velocityEngine = configureVelocityEngine(props.getBoolean(VELOCITY_DEV_MODE_PARAM, false)); sessionCache = new SessionCache(props); userManager = loadUserManager(props); alerters = loadAlerters(props); executorManager = loadExecutorManager(props); projectManager = loadProjectManager(props); triggerManager = loadTriggerManager(props); loadBuiltinCheckersAndActions(); // load all trigger agents here scheduleManager = loadScheduleManager(triggerManager, props); String triggerPluginDir = props.getString("trigger.plugin.dir", "plugins/triggers"); loadPluginCheckersAndActions(triggerPluginDir); baseClassLoader = this.getClassLoader(); tempDir = new File(props.getString("azkaban.temp.dir", "temp")); // Setup time zone if (props.containsKey(DEFAULT_TIMEZONE_ID)) { String timezone = props.getString(DEFAULT_TIMEZONE_ID); System.setProperty("user.timezone", timezone); TimeZone.setDefault(TimeZone.getTimeZone(timezone)); DateTimeZone.setDefault(DateTimeZone.forID(timezone)); logger.info("Setting timezone to " + timezone); } configureMBeanServer(); }
From source file:ca.ualberta.cs.shoven_habittracker.MainActivity.java
License:Creative Commons License
public Integer setDateToday(TextView textView) { LocalDateTime now = new LocalDateTime(DateTimeZone.forID("Canada/Mountain")); textView.setText(now.toString("EEEE, MMMM dd, yyyy", Locale.CANADA)); return now.getDayOfWeek() % 7; }
From source file:ca.ualberta.physics.cssdp.domain.file.CachedFile.java
License:Apache License
public CachedFile(String filename, String md5, File cachedFile) { this.md5 = md5; this.localPath = cachedFile.getAbsolutePath(); this.size = cachedFile.length(); this.fileTimestamp = new LocalDateTime(cachedFile.lastModified()); this.lastAccessed = new LocalDateTime(DateTimeZone.forID("America/Edmonton")); this.filename = filename; }
From source file:ch.corten.aha.worldclock.WeatherWidget.java
License:Open Source License
public static void updateItemView(Context context, Cursor cursor, RemoteViews rv, DateFormat timeFormat) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); boolean customColors = prefs.getBoolean(context.getString(R.string.use_custom_colors_key), false); rv.setTextViewText(R.id.city_text, cursor.getString(cursor.getColumnIndex(Clocks.CITY))); String id = cursor.getString(cursor.getColumnIndex(Clocks.TIMEZONE_ID)); long now = DateTimeUtils.currentTimeMillis(); DateTimeZone tz = DateTimeZone.forID(id); if (SANS_JELLY_BEAN_MR1) { rv.setTextViewText(R.id.time_text, TimeZoneInfo.showTimeWithOptionalWeekDay(tz, now, timeFormat)); } else {// w w w . j av a 2 s . c o m TimeZone javaTimeZone = TimeZoneInfo.convertToJavaTimeZone(tz, now); RemoteViewUtil.setTextClockTimeZone(rv, R.id.time_text, javaTimeZone.getID()); rv.setTextViewText(R.id.weekday_text, TimeZoneInfo.showDifferentWeekday(tz, now)); } rv.setTextViewText(R.id.condition_text, cursor.getString(cursor.getColumnIndex(Clocks.WEATHER_CONDITION))); String temperature = BindHelper.getTemperature(context, cursor, false); rv.setTextViewText(R.id.temp_text, temperature); int condCode = cursor.getInt(cursor.getColumnIndex(Clocks.CONDITION_CODE)); double lat = cursor.getDouble(cursor.getColumnIndex(Clocks.LATITUDE)); double lon = cursor.getDouble(cursor.getColumnIndex(Clocks.LONGITUDE)); if (!customColors) { rv.setImageViewResource(R.id.condition_image, WeatherIcons.getIcon(condCode, lon, lat)); } if (customColors) { int color = prefs.getInt(context.getString(R.string.background_color_key), Color.BLACK); RemoteViewUtil.setBackgroundColor(rv, R.id.widget_item, color); int foreground = prefs.getInt(context.getString(R.string.foreground_color_key), Color.WHITE); rv.setTextColor(R.id.city_text, foreground); rv.setTextColor(R.id.time_text, foreground); rv.setTextColor(R.id.condition_text, foreground); rv.setTextColor(R.id.temp_text, foreground); if (!SANS_JELLY_BEAN_MR1) { rv.setTextColor(R.id.weekday_text, foreground); } int res = WeatherIcons.getIcon(condCode, lon, lat); if (foreground != Color.WHITE) { Drawable drawable = context.getResources().getDrawable(res); Bitmap bmp = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Config.ARGB_8888); drawable.setColorFilter(foreground, Mode.MULTIPLY); Canvas canvas = new Canvas(bmp); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); drawable.setColorFilter(null); rv.setImageViewBitmap(R.id.condition_image, bmp); } else { rv.setImageViewResource(R.id.condition_image, WeatherIcons.getIcon(condCode, lon, lat)); } } else { RemoteViewUtil.setBackground(rv, R.id.widget_item, R.drawable.appwidget_dark_bg); int defaultColor = 0xffbebebe; rv.setTextColor(R.id.city_text, Color.WHITE); rv.setTextColor(R.id.time_text, defaultColor); rv.setTextColor(R.id.condition_text, defaultColor); rv.setTextColor(R.id.temp_text, Color.WHITE); if (!SANS_JELLY_BEAN_MR1) { rv.setTextColor(R.id.weekday_text, defaultColor); } } }
From source file:ch.corten.aha.worldclock.WorldClockWidgetProvider.java
License:Open Source License
private static void updateViews(Context context, RemoteViews views) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); boolean autoSort = prefs.getBoolean(context.getString(R.string.auto_sort_clocks_key), true); Cursor cursor = Clocks.widgetList(context, PROJECTION, autoSort); try {//w w w . ja v a2s .c o m int n = 0; DateFormat df = android.text.format.DateFormat.getTimeFormat(context); long now = DateTimeUtils.currentTimeMillis(); final int maxEntries = context.getResources().getInteger(R.integer.worldclock_widget_max_entries); while (cursor.moveToNext() && n < CITY_IDS.length && n < maxEntries) { String id = cursor.getString(cursor.getColumnIndex(Clocks.TIMEZONE_ID)); String city = cursor.getString(cursor.getColumnIndex(Clocks.CITY)); views.setTextViewText(CITY_IDS[n], city); DateTimeZone tz = DateTimeZone.forID(id); if (SANS_JELLY_BEAN_MR1) { views.setTextViewText(TIME_IDS[n], TimeZoneInfo.formatDate(df, tz, now)); } else { TimeZone javaTimeZone = TimeZoneInfo.convertToJavaTimeZone(tz, now); views.setViewVisibility(TIME_IDS[n], View.VISIBLE); RemoteViewUtil.setTextClockTimeZone(views, TIME_IDS[n], javaTimeZone.getID()); } n++; } int showEmptyText = (n == 0) ? View.VISIBLE : View.INVISIBLE; views.setViewVisibility(R.id.empty_text, showEmptyText); for (; n < CITY_IDS.length; n++) { views.setTextViewText(CITY_IDS[n], ""); if (SANS_JELLY_BEAN_MR1) { views.setTextViewText(TIME_IDS[n], ""); } else { views.setViewVisibility(TIME_IDS[n], View.INVISIBLE); } } boolean customColors = prefs.getBoolean(context.getString(R.string.use_custom_colors_key), false); int textColor = Color.WHITE; if (customColors) { int color = prefs.getInt(context.getString(R.string.background_color_key), Color.BLACK); RemoteViewUtil.setBackgroundColor(views, R.id.app_widget, color); textColor = prefs.getInt(context.getString(R.string.foreground_color_key), Color.WHITE); } else { RemoteViewUtil.setBackground(views, R.id.app_widget, R.drawable.appwidget_dark_bg); } for (int i = 0; i < CITY_IDS.length; i++) { views.setTextColor(CITY_IDS[i], textColor); views.setTextColor(TIME_IDS[i], textColor); } } finally { if (cursor != null) { cursor.close(); } } }
From source file:ch.emad.business.schuetu.BusinessImpl.java
License:Apache License
public void initZeilen(final boolean sonntag) { DateTime start;/*from w w w . j a va 2s.com*/ List<SpielZeile> zeilen; BusinessImpl.LOG.info("date: starttag -->" + this.getSpielEinstellungen().getStarttag()); final DateTime start2 = new DateTime(this.getSpielEinstellungen().getStart(), DateTimeZone.forID("Europe/Zurich")); BusinessImpl.LOG.info("date: starttag Europe/Zurich -->" + start2); if (!sonntag) { start = new DateTime(start2); zeilen = createZeilen(start, false); } else { start = new DateTime(start2); start = start.plusDays(1); zeilen = createZeilen(start, true); } BusinessImpl.LOG.info("-->" + zeilen); this.spielzeilenRepo.save(zeilen); }
From source file:ching.icecreaming.action.ResourceDescriptors.java
License:Open Source License
@Action(value = "resource-descriptors", results = { @Result(name = "success", location = "json.jsp") }) public String execute() throws Exception { int int1 = 401, int0 = 0; String string1 = null;//w w w. j a v a 2 s. co m URL url1 = null; URI uri1 = null; HttpGet httpGet1 = null; HttpResponse httpResponse1 = null; HttpEntity httpEntity1 = null; HttpPost httpPost1 = null; HttpHost httpHost1 = null; DefaultHttpClient httpClient1 = null; File file1 = null; InputStream inputStream1 = null; OutputStream outputStream1 = null; BeanComparator beanComparator1 = null; List<Map<String, Object>> list1 = null, list2 = null; Map<String, Object> map1 = null; Object object1 = null; int toIndex = rows * page; int fromIndex = toIndex - rows; GridModel1 jsonObject1 = null; Gson gson = null; Long long1 = -1L; java.util.Date date1 = null; URIBuilder uriBuilder1 = null; Node node1 = null; Element element1 = null; NodeList nodeList1 = null; Document document1 = null; DocumentBuilder documentBuilder1 = null; DocumentBuilderFactory documentBuilderFactory1 = null; org.joda.time.DateTime dateTime1 = null, dateTime2 = null; try { if (StringUtils.isNotEmpty(sid) && StringUtils.isNotEmpty(uid) && StringUtils.isNotEmpty(pid)) { sid = new String(Base64.decodeBase64(sid.getBytes())); uid = new String(Base64.decodeBase64(uid.getBytes())); pid = new String(Base64.decodeBase64(pid.getBytes())); httpClient1 = new DefaultHttpClient(); url1 = new URL(sid); uriBuilder1 = new URIBuilder(sid); uriBuilder1.setParameter("j_username", uid); uriBuilder1.setParameter("j_password", pid); uriBuilder1.setPath(url1.getPath() + "/rest/resources" + urlString); uriBuilder1.setUserInfo(uid, pid); uri1 = uriBuilder1.build(); httpGet1 = new HttpGet(uri1); httpResponse1 = httpClient1.execute(httpGet1); int1 = httpResponse1.getStatusLine().getStatusCode(); if (int1 == HttpStatus.SC_OK) { httpEntity1 = httpResponse1.getEntity(); inputStream1 = httpResponse1.getEntity().getContent(); if (inputStream1 != null) { documentBuilderFactory1 = DocumentBuilderFactory.newInstance(); documentBuilder1 = documentBuilderFactory1.newDocumentBuilder(); document1 = documentBuilder1.parse(inputStream1); document1.getDocumentElement().normalize(); nodeList1 = document1.getElementsByTagName("resourceDescriptor"); int1 = nodeList1.getLength(); list1 = new ArrayList<Map<String, Object>>(); for (int0 = 0; int0 < int1; int0++) { node1 = nodeList1.item(int0); if (node1.getNodeType() == Node.ELEMENT_NODE) { element1 = (Element) node1; map1 = new HashMap<String, Object>(); map1.put("wsType", element1.getAttribute("wsType")); map1.put("uriString", element1.getAttribute("uriString")); string1 = getTagValue("label", element1); map1.put("label1", StringUtils.defaultString(string1)); string1 = getTagValue("description", element1); map1.put("description", StringUtils.defaultString(string1)); string1 = getTagValue("creationDate", element1); long1 = (string1 == null) ? -1L : NumberUtils.toLong(StringUtils.trim(string1), -1L); if (long1 > 0) { if (StringUtils.isNotBlank(timeZone1)) { dateTime1 = new org.joda.time.DateTime(long1); dateTime2 = dateTime1.withZone(DateTimeZone.forID(timeZone1)); date1 = dateTime2.toLocalDateTime().toDate(); } else { date1 = new java.util.Date(long1); } } else { date1 = null; } map1.put("creationDate", date1); map1.put("type1", getText(element1.getAttribute("wsType"))); list1.add(map1); } } } EntityUtils.consume(httpEntity1); } } } catch (UnsupportedEncodingException | URISyntaxException | ParserConfigurationException | SAXException exception1) { exception1.printStackTrace(); return ERROR; } catch (org.apache.http.conn.HttpHostConnectException | java.net.NoRouteToHostException | java.net.MalformedURLException | java.net.UnknownHostException exception1) { exception1.printStackTrace(); return ERROR; } catch (IOException exception1) { httpGet1.abort(); exception1.printStackTrace(); return ERROR; } finally { if (httpClient1 != null) httpClient1.getConnectionManager().shutdown(); if (list1 != null) { records = list1.size(); if (list1.size() > 0) { if (StringUtils.isNotEmpty(sidx)) { if (StringUtils.equals(sord, "desc")) { beanComparator1 = new BeanComparator(sidx, new ReverseComparator(new ComparableComparator())); } else { beanComparator1 = new BeanComparator(sidx); } Collections.sort(list1, beanComparator1); } if (StringUtils.isNotBlank(searchField) && StringUtils.isNotEmpty(searchOper)) { Iterator iterator1 = list1.iterator(); while (iterator1.hasNext()) { map1 = (Map<String, Object>) iterator1.next(); for (Map.Entry<String, Object> entry1 : map1.entrySet()) { if (StringUtils.equals(entry1.getKey(), searchField)) { object1 = entry1.getValue(); if (searchFilter(searchField, searchOper, searchString, object1)) iterator1.remove(); break; } } } records = list1.size(); } if (toIndex > records) toIndex = records; if (fromIndex > toIndex) { fromIndex = toIndex - rows; if (fromIndex < 0) fromIndex = 0; } if (list1.size() > 0 && fromIndex >= 0 && toIndex <= list1.size() && fromIndex <= toIndex) list2 = list1.subList(fromIndex, toIndex); } total = (int) Math.ceil((double) records / (double) rows); if (page > total) page = total; jsonObject1 = new GridModel1(rows, page, sord, sidx, searchField, searchString, searchOper, total, records, id, list2); gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss.SSS").create(); jsonData = gson.toJson(jsonObject1); } IOUtils.closeQuietly(inputStream1); } return SUCCESS; }
From source file:cmg.org.monitor.app.schedule.MailServiceScheduler.java
License:Open Source License
/** * Do schedule.//from www . j av a2 s. c o m */ public void doSchedule() { // BEGIN LOG UtilityDAO utilDAO = new UtilityDaoImpl(); long start = System.currentTimeMillis(); logger.log(Level.INFO, MonitorUtil.parseTime(start, true) + " -> START: Scheduled send alert mail ..."); String currentZone = utilDAO.getCurrentTimeZone(); DateTime dtStart = new DateTime(start); dtStart = dtStart.withZone(DateTimeZone.forID(currentZone)); // BEGIN LOG String alertName = MonitorConstant.ALERTSTORE_DEFAULT_NAME + ": " + dtStart.toString(DateTimeFormat.forPattern(MonitorConstant.SYSTEM_DATE_FORMAT)); SystemAccountDAO accountDao = new SystemAccountDaoImpl(); SystemDAO sysDAO = new SystemDaoImpl(); AlertDao alertDAO = new AlertDaoImpl(); ArrayList<SystemMonitor> systems = sysDAO.listSystemsFromMemcache(false); MailMonitorDAO mailDAO = new MailMonitorDaoImpl(); SystemGroupDAO groupDao = new SystemGroupDaoImpl(); if (systems != null && systems.size() > 0) { ArrayList<UserMonitor> listUsers = utilDAO.listAllUsers(); if (listUsers != null && listUsers.size() > 0) { for (UserMonitor user : listUsers) { for (SystemMonitor sys : systems) { try { SystemGroup gr = groupDao.getByName(sys.getGroupEmail()); if (gr != null) { if (user.checkGroup(gr.getId())) { user.addSystem(sys); } } } catch (Exception e) { logger.log(Level.WARNING, "Error: " + e.getMessage()); } } } for (UserMonitor user : listUsers) { if (user.getSystems() != null && user.getSystems().size() > 0) { for (Object tempSys : user.getSystems()) { AlertStoreMonitor alertstore = alertDAO.getLastestAlertStore((SystemMonitor) tempSys); if (alertstore != null) { alertstore.setName(alertName); alertstore.setTimeStamp(new Date(start)); NotifyMonitor notify = null; try { notify = sysDAO.getNotifyOption(((SystemMonitor) tempSys).getCode()); } catch (Exception e) { } if (notify == null) { notify = new NotifyMonitor(); } alertstore.fixAlertList(notify); if (alertstore.getAlerts().size() > 0) { user.addAlertStore(alertstore); } } } } } } List<GoogleAccount> googleAccs = null; try { googleAccs = accountDao.listAllGoogleAccount(); } catch (Exception e1) { logger.log(Level.WARNING, "Error: " + e1.getMessage()); } if (listUsers != null && listUsers.size() > 0 && googleAccs != null && googleAccs.size() > 0) { for (UserMonitor user : listUsers) { if (user.getUser().getDomain().equalsIgnoreCase(SystemUser.THIRD_PARTY_USER)) { if (user.getStores() != null && user.getStores().size() > 0) { MailConfigMonitor config = mailDAO.getMailConfig(user.getId()); MailService mailService = new MailService(); try { String content = mailService.parseContent(user.getStores(), config); MailAsync mailUtil = new MailAsync(new String[] { user.getId() }, alertName, content); mailUtil.run(); logger.log(Level.INFO, "send mail" + content); } catch (Exception e) { logger.log(Level.INFO, "Can not send mail" + e.getMessage()); } } } } for (GoogleAccount gAcc : googleAccs) { MailService mailService = new MailService(gAcc); for (UserMonitor user : listUsers) { if (user.getUser().getDomain().equalsIgnoreCase(gAcc.getDomain())) { if (user.getStores() != null && user.getStores().size() > 0) { MailConfigMonitor config = mailDAO.getMailConfig(user.getId()); try { String content = mailService.parseContent(user.getStores(), config); mailService.sendMail(alertName, content, config); logger.log(Level.INFO, "send mail" + content); } catch (Exception e) { logger.log(Level.INFO, "Can not send mail" + e.getMessage()); } } } } } for (SystemMonitor sys : systems) { AlertStoreMonitor store = alertDAO.getLastestAlertStore(sys); alertDAO.putAlertStore(store); alertDAO.clearTempStore(sys); } } for (SystemMonitor sys : systems) { AlertStoreMonitor asm = alertDAO.getLastestAlertStore(sys); if (asm == null) { asm = new AlertStoreMonitor(); } asm.setCpuUsage(sys.getLastestCpuUsage()); asm.setMemUsage(sys.getLastestMemoryUsage()); asm.setSysId(sys.getId()); asm.setName(alertName); asm.setTimeStamp(new Date(start)); alertDAO.putAlertStore(asm); alertDAO.clearTempStore(sys); } } else { logger.log(Level.INFO, "NO SYSTEM FOUND"); } /* * mailDAO.getMailConfig(maiId); mailService.sendMail(subject, content, * mailConfig); */ // END LOG long end = System.currentTimeMillis(); long time = end - start; logger.log(Level.INFO, MonitorUtil.parseTime(end, true) + " -> END: Scheduled send alert mail. Time executed: " + time + " ms"); // END LOG }
From source file:cmg.org.monitor.ext.util.DateTimeUtils.java
License:Open Source License
public static Date convertDateWithZone(Date input) { if (currentZone == null) { Object obj = MonitorMemcache.get(Key.create(Key.CURRENT_ZONE)); if (obj != null && obj instanceof String) { currentZone = (String) obj; } else {// w w w. ja v a 2 s . c om currentZone = MonitorConstant.DEFAULT_SYSTEM_TIME_ZONE; } } DateTime temp = new DateTime(input); return temp.withZone(DateTimeZone.forID(currentZone)).toDate(); }