List of usage examples for org.joda.time DateTime getDayOfMonth
public int getDayOfMonth()
From source file:org.gephi.desktop.timeline.MinimalDrawer.java
License:Open Source License
private void paintUpperRulerForInterval(Graphics2D g2d, DateTime dtFrom, DateTime dtTo) { g2d.setFont(settings.graduations.font); g2d.setColor(settings.graduations.fontColor); int leftMargin = settings.graduations.leftMargin; int textTopPosition = settings.graduations.textTopPosition; int width = getWidth(); int height = getHeight(); // TODO take these from the model Interval interval = new Interval(dtFrom, dtTo); Period p = interval.toPeriod(PeriodType.days()); // try to determine length if we had to show milliseconds int n = p.getDays(); int unitSize = (int) (settings.graduations.fontMetrics.getStringBounds("wednesday ", null)).getWidth(); if (n < (width / unitSize)) { //System.out.println("jour"); for (int i = 0; i < n; i++) { g2d.drawString(dtFrom.plusDays(i).dayOfWeek().getAsText(LOCALE), leftMargin + 2 + i * (width / n), textTopPosition);/* www.j a va 2 s . co m*/ g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n), height - settings.graduations.textBottomMargin); paintSmallGraduations(g2d, leftMargin + i * (width / n), leftMargin + (i + 1) * (width / n), Hours.hoursBetween(dtFrom.plusDays(i), dtFrom.plusDays(i + 1)).getHours()); } return; } unitSize = (int) (settings.graduations.fontMetrics.getStringBounds("wed ", null)).getWidth(); if (n < (width / unitSize)) { //System.out.println("jou"); for (int i = 0; i < n; i++) { g2d.drawString(dtFrom.plusDays(i).dayOfWeek().getAsShortText(LOCALE), leftMargin + 2 + i * (width / n), textTopPosition); g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n), height - settings.graduations.textBottomMargin); paintSmallGraduations(g2d, leftMargin + i * (width / n), leftMargin + (i + 1) * (width / n), Hours.hoursBetween(dtFrom.plusDays(i), dtFrom.plusDays(i + 1)).getHours()); } return; } p = interval.toPeriod(PeriodType.days()); n = p.getDays(); unitSize = (int) (settings.graduations.fontMetrics.getStringBounds("30", null)).getWidth(); if (n < (width / unitSize)) { //System.out.println("j"); for (int i = 0; i < n; i++) { g2d.drawString("" + (dtFrom.getDayOfMonth() + i), leftMargin + 2 + i * (width / n), textTopPosition); g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n), height - settings.graduations.textBottomMargin); paintSmallGraduations(g2d, leftMargin + i * (width / n), leftMargin + (i + 1) * (width / n), Hours.hoursBetween(dtFrom.plusDays(i), dtFrom.plusDays(i + 1)).getHours()); } return; } p = interval.toPeriod(PeriodType.months()); n = p.getMonths(); unitSize = (int) (settings.graduations.fontMetrics.getStringBounds("September ", null)).getWidth(); if (n < (width / unitSize)) { //System.out.println("mois"); for (int i = 0; i < n; i++) { g2d.drawString(dtFrom.plusMonths(i).monthOfYear().getAsText(LOCALE), leftMargin + 2 + i * (width / n), textTopPosition); g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n), height - settings.graduations.textBottomMargin); paintSmallGraduations(g2d, leftMargin + i * (width / n), leftMargin + (i + 1) * (width / n), Days.daysBetween(dtFrom.plusMonths(i), dtFrom.plusMonths(i + 1)).getDays()); } return; } unitSize = (int) (settings.graduations.fontMetrics.getStringBounds("dec ", null)).getWidth(); if (n < (width / unitSize)) { //System.out.println("mo"); for (int i = 0; i < n; i++) { g2d.drawString(dtFrom.plusMonths(i).monthOfYear().getAsShortText(LOCALE), leftMargin + 2 + i * (width / n), textTopPosition); g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n), height - settings.graduations.textBottomMargin); paintSmallGraduations(g2d, leftMargin + i * (width / n), leftMargin + (i + 1) * (width / n), Days.daysBetween(dtFrom.plusMonths(i), dtFrom.plusMonths(i + 1)).getDays()); } return; } unitSize = (int) (settings.graduations.fontMetrics.getStringBounds("29 ", null)).getWidth(); if (n < (width / unitSize)) { //System.out.println("m"); for (int i = 0; i < n; i++) { g2d.drawString("" + (dtFrom.getMonthOfYear() + i), leftMargin + 2 + i * (width / n), textTopPosition); g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n), height - settings.graduations.textBottomMargin); paintSmallGraduations(g2d, leftMargin + i * (width / n), leftMargin + (i + 1) * (width / n), Days.daysBetween(dtFrom.plusMonths(i), dtFrom.plusMonths(i + 1)).getDays()); } return; } p = interval.toPeriod(PeriodType.years()); n = p.getYears(); unitSize = (int) (settings.graduations.fontMetrics.getStringBounds("1980 ", null)).getWidth(); if (n < (width / unitSize)) { //System.out.println("year"); for (int i = 0; i < n; i++) { g2d.drawString("" + (dtFrom.getYear() + i), leftMargin + 2 + i * (width / n), textTopPosition); g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n), height - settings.graduations.textBottomMargin); paintSmallGraduations(g2d, leftMargin + i * (width / n), leftMargin + (i + 1) * (width / n), Months.monthsBetween(dtFrom.plusYears(i), dtFrom.plusYears(i + 1)).getMonths()); } return; } int group = 10; n = p.getYears() / group; if (n < (width / unitSize)) { //System.out.println("10 years"); for (int i = 0; i < n; i++) { g2d.drawString("" + (dtFrom.getYear() + i * group), leftMargin + 2 + i * (width / n), textTopPosition); g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n), height - settings.graduations.textBottomMargin); paintSmallGraduations(g2d, leftMargin + i * (width / n), leftMargin + (i + 1) * (width / n), Months .monthsBetween(dtFrom.plusYears(i * group), dtFrom.plusYears((i + 1) * group)).getMonths()); } return; } group = 20; n = p.getYears() / group; if (n < (width / unitSize)) { //System.out.println("20 years"); for (int i = 0; i < n; i++) { g2d.drawString("" + (dtFrom.getYear() + i * group), leftMargin + 2 + i * (width / n), textTopPosition); g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n), height - settings.graduations.textBottomMargin); paintSmallGraduations(g2d, leftMargin + i * (width / n), leftMargin + (i + 1) * (width / n), Months .monthsBetween(dtFrom.plusYears(i * group), dtFrom.plusYears((i + 1) * group)).getMonths()); } return; } group = 50; n = p.getYears() / group; if (n < (width / unitSize)) { //System.out.println("50 years"); for (int i = 0; i < n; i++) { g2d.drawString("" + (dtFrom.getYear() + i * group), leftMargin + 2 + i * (width / n), textTopPosition); g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n), height - settings.graduations.textBottomMargin); paintSmallGraduations(g2d, leftMargin + i * (width / n), leftMargin + (i + 1) * (width / n), Months .monthsBetween(dtFrom.plusYears(i * group), dtFrom.plusYears((i + 1) * group)).getMonths()); } return; } group = 100; n = p.getYears() / group; if (n / 100 < (width / unitSize)) { //System.out.println("100 years"); for (int i = 0; i < n; i++) { g2d.drawString("" + (dtFrom.getYear() + i * group), leftMargin + 2 + i * (width / n), textTopPosition); g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n), height - settings.graduations.textBottomMargin); paintSmallGraduations(g2d, leftMargin + i * (width / n), leftMargin + (i + 1) * (width / n), Months .monthsBetween(dtFrom.plusYears(i * group), dtFrom.plusYears((i + 1) * group)).getMonths()); } } return; }
From source file:org.getspout.spout.EasterEggs.java
License:Open Source License
public static int getEasterEggTitleColor() { DateTime now = DateTime.now(); if (halloween.getDayOfMonth() == now.getDayOfMonth() && halloween.getMonthOfYear() == now.getMonthOfYear()) { return 0xFF5E00; //orange }/*from w w w .j av a 2 s . c o m*/ return -1; }
From source file:org.getspout.spout.EasterEggs.java
License:Open Source License
public static String getSplashTextEasterEgg() { DateTime now = DateTime.now(); if (halloween.getDayOfMonth() == now.getDayOfMonth() && halloween.getMonthOfYear() == now.getMonthOfYear()) { return "Happy Halloween!"; }//ww w .java 2 s . c o m return null; }
From source file:org.getspout.spout.EasterEggs.java
License:Open Source License
public static String getEasterEggCape() { DateTime now = DateTime.now(); if (halloween.getDayOfMonth() == now.getDayOfMonth() && halloween.getMonthOfYear() == now.getMonthOfYear()) { return "http://cdn.getspout.org/img/cape/halloween1.png"; }//from w ww . ja v a2 s. c om return null; }
From source file:org.gravidence.gravifon.util.DateTimeUtils.java
License:Open Source License
/** * Converts datetime object to array of UTC datetime fields.<p> * Given datetime object is casted to UTC.<p> * Resulting array content is as follows: <code>[yyyy,MM,dd,HH,mm,ss,SSS]</code>. * /*from w w w .j a v a 2 s . co m*/ * @param value datetime object * @return array of UTC datetime fields */ public static int[] dateTimeToArray(DateTime value) { int[] result; if (value == null) { result = null; } else { result = new int[7]; DateTime valueUTC = value.toDateTime(DateTimeZone.UTC); result[0] = valueUTC.getYear(); result[1] = valueUTC.getMonthOfYear(); result[2] = valueUTC.getDayOfMonth(); result[3] = valueUTC.getHourOfDay(); result[4] = valueUTC.getMinuteOfHour(); result[5] = valueUTC.getSecondOfMinute(); result[6] = valueUTC.getMillisOfSecond(); } return result; }
From source file:org.graylog2.inputs.random.generators.FakeHttpRawMessageGenerator.java
License:Open Source License
private static Map<String, Object> ingestTimeFields(DateTime ingestTime) { return ImmutableMap.<String, Object>builder().put("ingest_time", ingestTime.toString()) .put("ingest_time_epoch", ingestTime.getMillis()) .put("ingest_time_second", ingestTime.getSecondOfMinute()) .put("ingest_time_minute", ingestTime.getMinuteOfHour()) .put("ingest_time_hour", ingestTime.getHourOfDay()) .put("ingest_time_day", ingestTime.getDayOfMonth()) .put("ingest_time_month", ingestTime.getMonthOfYear()).put("ingest_time_year", ingestTime.getYear()) .build();/*from w ww.ja v a2 s .c o m*/ }
From source file:org.hawkular.metrics.core.impl.DateTimeService.java
License:Apache License
public DateTime getTimeSlice(DateTime dt, Duration duration) { Period p = duration.toPeriod(); if (p.getYears() != 0) { return dt.yearOfEra().roundFloorCopy().minusYears(dt.getYearOfEra() % p.getYears()); } else if (p.getMonths() != 0) { return dt.monthOfYear().roundFloorCopy().minusMonths((dt.getMonthOfYear() - 1) % p.getMonths()); } else if (p.getWeeks() != 0) { return dt.weekOfWeekyear().roundFloorCopy().minusWeeks((dt.getWeekOfWeekyear() - 1) % p.getWeeks()); } else if (p.getDays() != 0) { return dt.dayOfMonth().roundFloorCopy().minusDays((dt.getDayOfMonth() - 1) % p.getDays()); } else if (p.getHours() != 0) { return dt.hourOfDay().roundFloorCopy().minusHours(dt.getHourOfDay() % p.getHours()); } else if (p.getMinutes() != 0) { return dt.minuteOfHour().roundFloorCopy().minusMinutes(dt.getMinuteOfHour() % p.getMinutes()); } else if (p.getSeconds() != 0) { return dt.secondOfMinute().roundFloorCopy().minusSeconds(dt.getSecondOfMinute() % p.getSeconds()); }// www .j av a2 s. c o m return dt.millisOfSecond().roundCeilingCopy().minusMillis(dt.getMillisOfSecond() % p.getMillis()); }
From source file:org.hawkular.metrics.datetime.DateTimeService.java
License:Apache License
public static DateTime getTimeSlice(DateTime dt, Duration duration) { Period p = duration.toPeriod(); if (p.getYears() != 0) { return dt.yearOfEra().roundFloorCopy().minusYears(dt.getYearOfEra() % p.getYears()); } else if (p.getMonths() != 0) { return dt.monthOfYear().roundFloorCopy().minusMonths((dt.getMonthOfYear() - 1) % p.getMonths()); } else if (p.getWeeks() != 0) { return dt.weekOfWeekyear().roundFloorCopy().minusWeeks((dt.getWeekOfWeekyear() - 1) % p.getWeeks()); } else if (p.getDays() != 0) { return dt.dayOfMonth().roundFloorCopy().minusDays((dt.getDayOfMonth() - 1) % p.getDays()); } else if (p.getHours() != 0) { return dt.hourOfDay().roundFloorCopy().minusHours(dt.getHourOfDay() % p.getHours()); } else if (p.getMinutes() != 0) { return dt.minuteOfHour().roundFloorCopy().minusMinutes(dt.getMinuteOfHour() % p.getMinutes()); } else if (p.getSeconds() != 0) { return dt.secondOfMinute().roundFloorCopy().minusSeconds(dt.getSecondOfMinute() % p.getSeconds()); }//from w ww.j a v a 2 s . c o m return dt.millisOfSecond().roundCeilingCopy().minusMillis(dt.getMillisOfSecond() % p.getMillis()); }
From source file:org.hawkular.metrics.tasks.api.AbstractTrigger.java
License:Apache License
protected DateTime getExecutionTime(long time, Duration duration) { DateTime dt = new DateTime(time); Period p = duration.toPeriod(); if (p.getYears() != 0) { return dt.yearOfEra().roundFloorCopy().minusYears(dt.getYearOfEra() % p.getYears()); } else if (p.getMonths() != 0) { return dt.monthOfYear().roundFloorCopy().minusMonths((dt.getMonthOfYear() - 1) % p.getMonths()); } else if (p.getWeeks() != 0) { return dt.weekOfWeekyear().roundFloorCopy().minusWeeks((dt.getWeekOfWeekyear() - 1) % p.getWeeks()); } else if (p.getDays() != 0) { return dt.dayOfMonth().roundFloorCopy().minusDays((dt.getDayOfMonth() - 1) % p.getDays()); } else if (p.getHours() != 0) { return dt.hourOfDay().roundFloorCopy().minusHours(dt.getHourOfDay() % p.getHours()); } else if (p.getMinutes() != 0) { return dt.minuteOfHour().roundFloorCopy().minusMinutes(dt.getMinuteOfHour() % p.getMinutes()); } else if (p.getSeconds() != 0) { return dt.secondOfMinute().roundFloorCopy().minusSeconds(dt.getSecondOfMinute() % p.getSeconds()); }//from w w w . jav a2 s . co m return dt.millisOfSecond().roundCeilingCopy().minusMillis(dt.getMillisOfSecond() % p.getMillis()); }
From source file:org.hepaces.surveyfeedbacktestscript.KrogerFeedbackManager.java
/** * Fills in the date and time fields//from w w w. j a v a2 s. com * @param date * @param browser */ public static void fillInDateAndTime(DateTime date, WebDriver browser) { logger.debug("Attempting to fill in the date and time inputs @:" + browser.getCurrentUrl()); try { //Date Inputs WebElement monthInput = browser.findElement(By.id(inputMonthId)); WebElement dayInput = browser.findElement(By.id(inputDayId)); WebElement yearInput = browser.findElement(By.id(inputYearId)); //Time Inputs WebElement hourInput = browser.findElement(By.id(inputHourId)); WebElement minuteInput = browser.findElement(By.id(inputMinuteId)); WebElement amPmInput = browser.findElement(By.id(inputAMPM)); //handle date inputs (year is prepopulated, so not handled) numericDropDownHandler(date.getMonthOfYear(), monthInput); numericDropDownHandler(date.getDayOfMonth(), dayInput); //handle time inputs numericDropDownHandler(date.get(DateTimeFieldType.clockhourOfHalfday()), hourInput); numericDropDownHandler(date.getMinuteOfHour(), minuteInput); numericDropDownHandler(date.get(DateTimeFieldType.halfdayOfDay()) + 1, amPmInput); } catch (Exception e) { } }