List of usage examples for org.joda.time DateTime withZone
public DateTime withZone(DateTimeZone newZone)
From source file:org.vaadin.spring.samples.mvp.util.SSTimeUtil.java
License:Apache License
/** * Determines the hour label corresponding to a org.joda.time.DateTime * * @param dateTime//w w w . j av a 2 s. com * org.joda.time.DateTime (typically a whole hour) * @return an hour label where 01 represents 1:00AM and 24 represents * 12:00AM of the following day */ public static String dateTimeToHourLabel(final DateTime dateTime) { String hour = null; if (dateTime != null) { hour = hourFormat.print(dateTime.withZone(marketTimeZone)); final String tz = timeZoneOffsetFormat.print(dateTime); if (hour != null) { // midnight is the 24th hour! if (hour.equals("00")) { hour = "24"; } if (hour.equals("01")) { final DateTime priorHourAsDate = dateTime.minusHours(1); final String priorTz = timeZoneOffsetFormat.print(priorHourAsDate); if (!tz.equals(priorTz)) { hour = "02"; } } if (isExtraHourForHourEnding(dateTime)) { hour = "02*"; } } } return hour; }
From source file:org.vaadin.spring.samples.mvp.util.SSTimeUtil.java
License:Apache License
/** * Converts a a java.util.Date in any time zone to an ISO8601 no-millis * String instance in Market time zone//from w w w. j a v a 2 s . c o m * * @param date * a Date instance * @return an ISO8601 no-millis String instance in "Market time" */ public static String dateToIsoNoMillis(final Date date) { DateTime dt = new DateTime(date); dt = dt.withZone(marketTimeZone); return dateTimeToIsoNoMillis(dt); }
From source file:org.vaadin.spring.samples.mvp.util.SSTimeUtil.java
License:Apache License
/** * Return the starting day accounting for Hour 00:00:00 being the day after. * * @param isoHour/* www. j a v a 2s. c o m*/ * an iso String * @return an iso String */ public static String isoHourEndingToIsoDay(String isoHour) { DateTime dt = isoToDateTime(isoHour); dt = dt.withZone(SSTimeUtil.getMarketTimeZone()); if (dt.getHourOfDay() == 0) { dt = dt.minusDays(1); } return dateTimeToIsoDay(dt); }
From source file:org.vaadin.spring.samples.mvp.util.SSTimeUtil.java
License:Apache License
/** * Accepts any org.joda.time.DateTime, converts to Market time zone resets * hour minutes and seconds to midnight, * * @param dateTime/* w w w. j a v a 2 s. c o m*/ * a Date instance * @return an ISO8601 formatted String without millis */ public static String dateTimeToIsoDay(final DateTime dateTime) { final DateTime dt = dateTime.withZone(marketTimeZone).withMillisOfDay(0); return isoFormat.print(dt); }
From source file:org.vaadin.spring.samples.mvp.util.SSTimeUtil.java
License:Apache License
/** * Converts a java.util.Date to an org.joda.time.DateTime date with the * market timezone/* www.java 2s. com*/ * * @param date * @return */ protected static DateTime dateToMarketDateTime(final Date date) { final DateTime dateTime = new DateTime(date); return dateTime.withZone(marketTimeZone); }
From source file:org.vaadin.spring.samples.mvp.util.SSTimeUtil.java
License:Apache License
/** * Return the starting day accounting for Hour 00:00:00 being the day after. * The date is coerced into the market time zone before computing the hour * When hour 00 is detected the day is decremented. The returned date has a * time of 00:00:00 in the market time zone. * * @param dt//from w w w . j av a 2 s . co m * an org.joda.time.DateTime * @return an org.joda.time.DateTime expressing an operating day */ public static DateTime getOperatingDay(DateTime dt) { dt = dt.withZone(SSTimeUtil.getMarketTimeZone()); if (dt.getHourOfDay() == 0) { dt = dt.minusDays(1); } return dt.withMillisOfDay(0); }
From source file:org.xmlcml.euclid.JodaDate.java
License:Apache License
public static DateTime parseDate(String date, String format) { DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(format); if (format.endsWith("Z")) { } else {/*from www . jav a 2 s . co m*/ dateTimeFormatter = dateTimeFormatter.withZone(DateTimeZone.forID("UTC")); } DateTime dateTime = dateTimeFormatter.parseDateTime(date); return dateTime.withZone(DateTimeZone.forID("UTC")); }
From source file:rapture.event.generator.EventGenerator.java
License:Open Source License
private static void generatePeriodic(List<String> ret, DateTime dt, boolean periodic) { // We guarantee that each call to this function, cal will be advanced a // minute at least int dayOfWeek = dt.getDayOfWeek(); if (periodic) { checkAdd(dayOfWeek, dt.getMinuteOfHour(), minuteChecks, "minutes", "/time", ret); if (dt.getMinuteOfHour() == 0) { checkAdd(dayOfWeek, dt.getHourOfDay(), hourChecks, "hours", "/time", ret); if (dt.getHourOfDay() == 0) { ret.add("/time/days" + dt.getDayOfMonth()); if (dt.getDayOfMonth() == 1) { ret.add("/time/months" + dt.getMonthOfYear()); }/* ww w . j a v a 2 s . c om*/ } } } // We construct, for each supported timezone, // timezone/daily/[timezone]/hour/minute // timezone/weekend/ (if a weekend) // timezone/weekeday/ (if a weekday) // timezone/day // So initially create the end point for each timezone, then push it out // We assume dt is in UT (but does this matter?) for (Map.Entry<String, DateTimeZone> zoneEntry : timeZones.entrySet()) { DateTime dtLocal = dt.withZone(zoneEntry.getValue()); String convertedZone = getConvertedTimeZone(zoneEntry.getKey()); int localDow = dtLocal.getDayOfWeek(); String endField = hmFormat.print(dtLocal); ret.add(String.format("/timezone/daily/%s/%s", convertedZone, endField)); ret.add(String.format("/timezone/%s/%s/%s", isWeekend(localDow) ? "weekend" : "weekday", convertedZone, endField)); ret.add(String.format("/timezone/%s/%s/%s", getDOWName(localDow), convertedZone, endField)); } }
From source file:rapture.kernel.schedule.ScheduleManager.java
License:Open Source License
/** * The definition of the RaptureJob has changed, so make sure it's still scheduled to run at the right time (upcoming job schedule etc) * <p>// w w w. j a v a2 s . co m * Need to watch out of the upcoming job exec is not WAITING though. * * @param job * @param passedParams */ public static void handleJobChanged(RaptureJob job, boolean withAdvance, Map<String, String> passedParams, RaptureJobExec jobExec) { // 1. Compute next execution time given a the cron spec for this job // 2. Store that in a RaptureJobExec, with the counter set to the job, // name from the job // 3. Status is WAITING // 4. Store job (warn if jobexec already exists and is not WAITING) logger.info("Job " + job.getJobURI() + " has changed, processing results"); if (job.getActivated()) { CronParser parser = MultiCronParser.create(job.getCronSpec()); DateTime dt = new DateTime(); DateTime cal = dt.withZone(DateTimeZone.forID(job.getTimeZone())); logger.info("cal is " + cal.toString()); DateTime nextRunDate = parser.nextRunDate(cal); RaptureJobExec exec = new RaptureJobExec(); exec.setJobType(job.getJobType()); exec.setJobURI(job.getAddressURI().toString()); if (nextRunDate != null) { logger.info("Updated next run date for the job is " + nextRunDate.toString("dd MMM yyyy HH:mm:ss_SSS z")); exec.setExecTime(nextRunDate.getMillis()); exec.setStatus(JobExecStatus.WAITING); } else { logger.info("Job is finished for good. No more future runs."); if (jobExec != null) { exec.setExecTime(jobExec.getExecTime()); } exec.setStatus(JobExecStatus.FINISHED); } if (passedParams != null) { exec.setPassedParams(passedParams); } String user = ContextFactory.getKernelUser().getUser(); String comment = "Job changed"; RaptureJobExecStorage.add(exec, user, comment); updateUpcoming(exec, user, comment); } else { logger.info("Job " + job.getJobURI() + " is not activated, no execution will be created, clearing current execution"); String user = ContextFactory.getKernelUser().getUser(); UpcomingJobExecStorage.deleteByFields(job.getJobURI(), user, "job changed, not active"); } }