List of usage examples for org.joda.time DateTimeZone forID
@FromString public static DateTimeZone forID(String id)
From source file:com.ecofactor.qa.automation.util.CustomReport.java
License:Open Source License
/** * Writes the scenario summary for the results of a given state for a single test. * @param description the description//from w w w . j av a 2 s .c o m * @param classResults the class results * @param cssClassPrefix the css class prefix * @param startingScenarioIndex the starting scenario index * @return the int */ private int writeScenarioSummary(String description, List<ClassResult> classResults, String cssClassPrefix, int startingScenarioIndex) { int scenarioCount = 0; if (!classResults.isEmpty()) { String backgroundColor = ""; if (cssClassPrefix.contains("failed")) { backgroundColor = "#fc2203"; } else if (cssClassPrefix.contains("passed")) { backgroundColor = "#11ca0d"; } else if (cssClassPrefix.contains("skipped")) { backgroundColor = "#fbf537"; } int scenarioIndex = startingScenarioIndex; // int classIndex = 0; for (ClassResult classResult : classResults) { String cssClass = ""; buffer.setLength(0); int scenariosPerClass = 0; int methodIndex = 0; for (MethodResult methodResult : classResult.getMethodResults()) { List<ITestResult> results = methodResult.getResults(); int resultsCount = results.size(); assert resultsCount > 0; ITestResult firstResult = results.get(0); String methodName = Utils.escapeHtml(firstResult.getMethod().getMethodName()); long start = firstResult.getStartMillis(); DateTimeZone zone = DateTimeZone.forID("America/Los_Angeles"); String startTime = DateUtil.formatToZone(start, zone, DateUtil.MM_DD_YY); long duration = firstResult.getEndMillis() - start; long seconds = TimeUnit.MILLISECONDS.toSeconds(duration); // The first method per class shares a row with the class // header if (methodIndex > 0) { buffer.append("<tr style=\"").append(cssClass.toLowerCase()).append("\">"); } scenarioIndex++; // Write the remaining scenarios for the method for (int i = 1; i < resultsCount; i++) { firstResult = results.get(i); start = firstResult.getStartMillis(); zone = DateTimeZone.forID("America/Los_Angeles"); startTime = DateUtil.formatToZone(start, zone, DateUtil.MM_DD_YY); scenarioIndex++; } scenariosPerClass += resultsCount; methodIndex++; } } scenarioCount = scenarioIndex - startingScenarioIndex; } return scenarioCount; }
From source file:com.ecofactor.qa.automation.util.DateUtil.java
License:Open Source License
/** * Gets the local calendar.// www. j av a 2 s. c o m * @param timeZone the time zone * @return the local calendar * @throws ParseException the parse exception */ public static Calendar getLocalCalendar(final String timeZone) throws ParseException { DateTime dateTime = new DateTime(DateTimeZone.forID(timeZone)); Calendar tzCalendar = dateTime.toCalendar(Locale.ENGLISH); return tzCalendar; }
From source file:com.ecofactor.qa.automation.util.DateUtil.java
License:Open Source License
/** * Gets the uTC time from local./*from w w w. j a v a2 s.c om*/ * @param localTimeInMillis the local time in millis * @param timeZone the time zone * @return the uTC time from local */ public static long getUTCTimeFromLocal(long localTimeInMillis, String timeZone) { System.out.println("Time Zone 2 = " + timeZone); long utcTime = 0; DateTimeZone dateTimeZone = DateTimeZone.forID(timeZone); utcTime = dateTimeZone.convertLocalToUTC(localTimeInMillis, false); System.out.println(dateTimeZone); return utcTime; }
From source file:com.ecofactor.qa.automation.util.DateUtil.java
License:Open Source License
/** * Parses the to zone calendar.//from w w w. j a va 2 s .c o m * @param timestamp the timestamp * @param pattern the pattern * @param timeZone the time zone * @return the calendar */ public static Calendar parseToZoneCalendar(String timestamp, String pattern, String timeZone) { DateTimeFormatter fmt = DateTimeFormat.forPattern(pattern); fmt = fmt.withZoneUTC(); DateTime dt = fmt.parseDateTime(timestamp); dt = dt.toDateTime(DateTimeZone.forID(timeZone)); return dt.toCalendar(Locale.ENGLISH); }
From source file:com.ecofactor.qa.automation.util.DateUtil.java
License:Open Source License
/** * Gets the time zone diff./*ww w. j av a 2 s . com*/ * @param timeZone the time zone * @return the time zone diff */ public static String getTimeZoneDiff(String timeZone) { DateTime startDate = new DateTime(DateTimeZone.forID(timeZone)); DateTimeFormatter fmt = DateTimeFormat.forPattern(DATE_FMT_FULL_TZ); String timeval = fmt.print(startDate); int lastIndexOfSpace = timeval.lastIndexOf(" "); timeval = timeval.substring(lastIndexOfSpace + 1, timeval.length()); return timeval; }
From source file:com.edlogics.ElrcApplication.java
License:Open Source License
/** * Bean to hold the system maintenance date time. Defaults to a far future date time. * * @return/*w ww.j a v a2 s. co m*/ */ @Bean public MutableDateTime maintenanceDateTime() { MutableDateTime farFuture = MutableDateTime.now(DateTimeZone.forID(elrcTimezone)); // Set to year 9999 to make easy to check for far future value // There is no easy way to do a max Date with Joda time so this is the workaround farFuture.setYear(9999); return farFuture; }
From source file:com.edlogics.ElrcApplication.java
License:Open Source License
/** * If the application is currently in maintenance as specified by the maintenance date time being set. * * @return Is the current date time > maintenance date time? *///from w w w. ja va 2 s. co m @Bean @Scope(WebApplicationContext.SCOPE_REQUEST) public boolean inMaintenance() { DateTime currentDateTime = DateTime.now(DateTimeZone.forID(elrcTimezone)); return (currentDateTime.getMillis() - maintenanceDateTime().getMillis()) > 0; }
From source file:com.enitalk.configs.DateCache.java
@Bean(name = "skipCache") public LoadingCache<String, ConcurrentSkipListSet<DateTime>> datesMap() { CacheBuilder<Object, Object> ccc = CacheBuilder.newBuilder(); ccc.expireAfterWrite(2, TimeUnit.MINUTES); LoadingCache<String, ConcurrentSkipListSet<DateTime>> cache = ccc .build(new CacheLoader<String, ConcurrentSkipListSet<DateTime>>() { @Override/* ww w.j ava2s. c o m*/ public ConcurrentSkipListSet<DateTime> load(String key) throws Exception { try { HashMap teachers = mongo.findOne(Query.query(Criteria.where("i").is(key)), HashMap.class, "teachers"); ObjectNode teacherJson = jackson.convertValue(teachers, ObjectNode.class); String timeZone = teacherJson.at("/calendar/timeZone").asText(); NavigableSet<DateTime> set = days(teacherJson.path("schedule"), timeZone, teacherJson); DateTimeZone dzz = DateTimeZone.forID(timeZone); DateTimeFormatter df = ISODateTimeFormat.dateTimeNoMillis().withZone(dzz); byte[] events = calendar.busyEvents(jackson.createObjectNode().put("id", key)); JsonNode evs = jackson.readTree(events); Iterator<JsonNode> its = evs.iterator(); TreeSet<DateTime> dates = new TreeSet<>(); while (its.hasNext()) { String date = its.next().asText(); DateTime av = df.parseDateTime(date).toDateTime(DateTimeZone.UTC); dates.add(av); } set.removeAll(dates); logger.info("Dates for i {} {}", key, set); return new ConcurrentSkipListSet<>(set); } catch (Exception e) { logger.error(ExceptionUtils.getFullStackTrace(e)); } return null; } }); return cache; }
From source file:com.enitalk.configs.DateCache.java
public NavigableSet<DateTime> days(JsonNode tree, String tz, JsonNode teacherNode) { ConcurrentSkipListSet<DateTime> dates = new ConcurrentSkipListSet<>(); Iterator<JsonNode> els = tree.elements(); DateTimeZone dz = DateTimeZone.forID(tz); DateTimeFormatter hour = DateTimeFormat.forPattern("HH:mm").withZone(dz); DateTime today = DateTime.now().millisOfDay().setCopy(0); while (els.hasNext()) { JsonNode el = els.next();//w w w . j av a 2 s . co m String day = el.path("day").asText(); boolean plus = today.getDayOfWeek() > days.get(day); if (el.has("start") && el.has("end")) { DateTime start = hour.parseDateTime(el.path("start").asText()).dayOfMonth() .setCopy(today.getDayOfMonth()).monthOfYear().setCopy(today.getMonthOfYear()).year() .setCopy(today.getYear()).withDayOfWeek(days.get(day)).plusWeeks(plus ? 1 : 0); DateTime end = hour.parseDateTime(el.path("end").asText()).dayOfMonth() .setCopy(today.getDayOfMonth()).monthOfYear().setCopy(today.getMonthOfYear()).year() .setCopy(today.getYear()).withDayOfWeek(days.get(day)).plusWeeks(plus ? 1 : 0); Hours hours = Hours.hoursBetween(start, end); int hh = hours.getHours() + 1; while (hh-- > 0) { dates.add(start.plusHours(hh).toDateTime(DateTimeZone.UTC)); } } else { List<String> datesAv = jackson.convertValue(el.path("times"), List.class); logger.info("Array of dates {} {}", datesAv, day); datesAv.forEach((String dd) -> { DateTime date = hour.parseDateTime(dd).dayOfMonth().setCopy(today.getDayOfMonth()).monthOfYear() .setCopy(today.getMonthOfYear()).year().setCopy(today.getYear()) .withDayOfWeek(days.get(day)).plusWeeks(plus ? 1 : 0); dates.add(date.toDateTime(DateTimeZone.UTC)); }); } } final TreeSet<DateTime> addWeek = new TreeSet<>(); for (int i = 1; i < 2; i++) { for (DateTime e : dates) { addWeek.add(e.plusWeeks(i)); } } dates.addAll(addWeek); DateTime nowUtc = DateTime.now().toDateTime(DateTimeZone.UTC); nowUtc = nowUtc.plusHours(teacherNode.path("notice").asInt(2)); NavigableSet<DateTime> ss = dates.tailSet(nowUtc, true); return ss; }
From source file:com.enitalk.controllers.bots.EniWordController.java
public void runEniword() { try {/*from w ww. java 2 s . co m*/ mongo.updateMulti(Query.query(Criteria.where("eniword.nextPing").exists(false)), new Update() .set("eniword.nextPing", new DateTime().minusSeconds(10).toDate()).set("eniword.points", 300), "leads"); Criteria d = Criteria.where("eniword.nextPing").lte(new Date()); Criteria cal = Criteria.where("calendar").exists(true); Criteria unsubscribed = Criteria.where("eniword.disabled").exists(false); Query q = Query.query(Criteria.where("eniword.points").gt(0).andOperator(d, cal, unsubscribed)); q.fields().exclude("_id").include("dest").include("eniword").include("calendar"); List<HashMap> acolates = mongo.find(q, HashMap.class, "leads"); ArrayNode leads = jackson.convertValue(acolates, ArrayNode.class); Iterator<JsonNode> els = leads.iterator(); while (els.hasNext()) { JsonNode el = els.next(); String tz = el.at("/calendar/timeZone").asText(); DateTime now = new DateTime(DateTimeZone.forID(tz)); if (now.hourOfDay().get() < 9 || now.getHourOfDay() > 20) { logger.info("Too late to bother {}", el); mongo.updateFirst(Query.query(Criteria.where("dest.sendTo").is(el.at("/dest/sendTo").asLong())), new Update().set("eniword.nextPing", new DateTime().plusHours(1).toDate()), "leads"); return; } mongo.updateFirst(Query.query(Criteria.where("dest.sendTo").is(el.at("/dest/sendTo").asLong())), new Update().set("eniword.nextPing", new DateTime().plusSeconds(60 * 40).toDate()), "leads"); rabbit.send("eniwords", MessageBuilder.withBody(jackson.writeValueAsBytes(el)).build()); } } catch (Exception e) { logger.error(ExceptionUtils.getFullStackTrace(e)); } }