List of usage examples for org.joda.time Seconds Seconds
private Seconds(int seconds)
From source file:aDeleteME.DeleteME.java
public static void main(String[] args) { Random random = new Random(); DateTime startTime = new DateTime(random.nextLong()).withMillisOfSecond(0); Minutes minimumPeriod = Minutes.TWO; int minimumPeriodInSeconds = minimumPeriod.toStandardSeconds().getSeconds(); int maximumPeriodInSeconds = Hours.ONE.toStandardSeconds().getSeconds(); Seconds randomPeriod = Seconds.seconds(random.nextInt(maximumPeriodInSeconds - minimumPeriodInSeconds)); DateTime endTime = startTime.plus(minimumPeriod).plus(randomPeriod); DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"); System.out.println(dateTimeFormatter.print(startTime)); System.out.println(dateTimeFormatter.print(endTime)); }
From source file:azkaban.app.jmx.JobScheduler.java
License:Apache License
public String scheduleWorkflow(String jobName, boolean ignoreDeps, int hour, int minutes, int seconds, String scheduledDate, boolean isRecurring, int period, String periodUnits) { String errorMsg = null;//from w ww . j a v a2s . com if (jobName == null || jobName.trim().length() == 0) { errorMsg = "You must select at least one job to run."; logger.error(errorMsg); return errorMsg; } JobDescriptor descriptor = jobManager.getJobDescriptor(jobName); if (descriptor == null) { errorMsg = "Job: '" + jobName + "' doesn't exist."; logger.error(errorMsg); return errorMsg; } DateTime day = null; DateTime time = null; try { if (scheduledDate == null || scheduledDate.trim().length() == 0) { day = new LocalDateTime().toDateTime(); time = day.withHourOfDay(hour).withMinuteOfHour(minutes).withSecondOfMinute(seconds); if (day.isAfter(time)) { time = time.plusDays(1); } } else { try { day = DateTimeFormat.forPattern("MM-dd-yyyy").parseDateTime(scheduledDate); } catch (IllegalArgumentException e) { logger.error(e); return "Invalid date: '" + scheduledDate + "', \"MM-dd-yyyy\" format is expected."; } time = day.withHourOfDay(hour).withMinuteOfHour(minutes).withSecondOfMinute(seconds); } } catch (IllegalFieldValueException e) { logger.error(e); return "Invalid schedule time (see logs): " + e.getMessage(); } ReadablePeriod thePeriod = null; if (isRecurring) { if ("d".equals(periodUnits)) { thePeriod = Days.days(period); } else if ("h".equals(periodUnits)) { thePeriod = Hours.hours(period); } else if ("m".equals(periodUnits)) { thePeriod = Minutes.minutes(period); } else if ("s".equals(periodUnits)) { thePeriod = Seconds.seconds(period); } else { errorMsg = "Unknown period unit: " + periodUnits; logger.error(errorMsg); return errorMsg; } } try { if (thePeriod == null) { scheduler.schedule(jobName, time, ignoreDeps); } else { scheduler.schedule(jobName, time, thePeriod, ignoreDeps); } return "Schedule Successful!"; } catch (Exception e) { logger.error(e); return "Schedule Failed (see logs): " + e.getMessage(); } }
From source file:azkaban.app.Scheduler.java
License:Apache License
private ReadablePeriod parsePeriodString(String jobname, String periodStr) { ReadablePeriod period;/*from ww w .j av a 2 s . co m*/ char periodUnit = periodStr.charAt(periodStr.length() - 1); if (periodUnit == 'n') { return null; } int periodInt = Integer.parseInt(periodStr.substring(0, periodStr.length() - 1)); switch (periodUnit) { case 'd': period = Days.days(periodInt); break; case 'h': period = Hours.hours(periodInt); break; case 'm': period = Minutes.minutes(periodInt); break; case 's': period = Seconds.seconds(periodInt); break; default: throw new IllegalArgumentException( "Invalid schedule period unit '" + periodUnit + "' for job " + jobname); } return period; }
From source file:azkaban.migration.scheduler.Schedule.java
License:Apache License
public static ReadablePeriod parsePeriodString(String periodStr) { ReadablePeriod period;//from w ww. ja va 2s . c o m char periodUnit = periodStr.charAt(periodStr.length() - 1); if (periodUnit == 'n') { return null; } int periodInt = Integer.parseInt(periodStr.substring(0, periodStr.length() - 1)); switch (periodUnit) { case 'M': period = Months.months(periodInt); break; case 'w': period = Weeks.weeks(periodInt); break; case 'd': period = Days.days(periodInt); break; case 'h': period = Hours.hours(periodInt); break; case 'm': period = Minutes.minutes(periodInt); break; case 's': period = Seconds.seconds(periodInt); break; default: throw new IllegalArgumentException("Invalid schedule period unit '" + periodUnit); } return period; }
From source file:azkaban.utils.TimeUtils.java
License:Apache License
/** * Parse Period String to a ReadablePeriod Object * * @param periodStr string formatted period * @return ReadablePeriod Object//from w w w. j a va2 s . c om */ public static ReadablePeriod parsePeriodString(final String periodStr) { final ReadablePeriod period; final char periodUnit = periodStr.charAt(periodStr.length() - 1); if (periodStr.equals("null") || periodUnit == 'n') { return null; } final int periodInt = Integer.parseInt(periodStr.substring(0, periodStr.length() - 1)); switch (periodUnit) { case 'y': period = Years.years(periodInt); break; case 'M': period = Months.months(periodInt); break; case 'w': period = Weeks.weeks(periodInt); break; case 'd': period = Days.days(periodInt); break; case 'h': period = Hours.hours(periodInt); break; case 'm': period = Minutes.minutes(periodInt); break; case 's': period = Seconds.seconds(periodInt); break; default: throw new IllegalArgumentException("Invalid schedule period unit '" + periodUnit); } return period; }
From source file:azkaban.utils.Utils.java
License:Apache License
public static ReadablePeriod parsePeriodString(String periodStr) { ReadablePeriod period;/*from ww w. j a va 2s. co m*/ char periodUnit = periodStr.charAt(periodStr.length() - 1); if (periodStr.equals("null") || periodUnit == 'n') { return null; } int periodInt = Integer.parseInt(periodStr.substring(0, periodStr.length() - 1)); switch (periodUnit) { case 'y': period = Years.years(periodInt); break; case 'M': period = Months.months(periodInt); break; case 'w': period = Weeks.weeks(periodInt); break; case 'd': period = Days.days(periodInt); break; case 'h': period = Hours.hours(periodInt); break; case 'm': period = Minutes.minutes(periodInt); break; case 's': period = Seconds.seconds(periodInt); break; default: throw new IllegalArgumentException("Invalid schedule period unit '" + periodUnit); } return period; }
From source file:azkaban.web.pages.IndexServlet.java
License:Apache License
private ReadablePeriod parsePeriod(HttpServletRequest req) throws ServletException { int period = getIntParam(req, "period"); String periodUnits = getParam(req, "period_units"); if ("d".equals(periodUnits)) return Days.days(period); else if ("h".equals(periodUnits)) return Hours.hours(period); else if ("m".equals(periodUnits)) return Minutes.minutes(period); else if ("s".equals(periodUnits)) return Seconds.seconds(period); else//from ww w . j a v a 2 s . c o m throw new ServletException("Unknown period unit: " + periodUnits); }
From source file:com.cenrise.test.azkaban.Utils.java
License:Apache License
public static ReadablePeriod parsePeriodString(final String periodStr) { final ReadablePeriod period; final char periodUnit = periodStr.charAt(periodStr.length() - 1); if (periodStr.equals("null") || periodUnit == 'n') { return null; }/*from w w w . ja v a 2 s. c o m*/ final int periodInt = Integer.parseInt(periodStr.substring(0, periodStr.length() - 1)); switch (periodUnit) { case 'y': period = Years.years(periodInt); break; case 'M': period = Months.months(periodInt); break; case 'w': period = Weeks.weeks(periodInt); break; case 'd': period = Days.days(periodInt); break; case 'h': period = Hours.hours(periodInt); break; case 'm': period = Minutes.minutes(periodInt); break; case 's': period = Seconds.seconds(periodInt); break; default: throw new IllegalArgumentException("Invalid schedule period unit '" + periodUnit); } return period; }
From source file:griffon.plugins.jodatime.editors.SecondsPropertyEditor.java
License:Apache License
private Seconds parse(Number number) { return Seconds.seconds(abs(number.intValue())); }
From source file:griffon.plugins.jodatime.JodatimeExtension.java
License:Apache License
public static Seconds toSeconds(Number number) { return Seconds.seconds(abs(number.intValue())); }