List of usage examples for org.joda.time DateTime monthOfYear
public Property monthOfYear()
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()); }/* www .ja 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()); }//www . j a va 2s.c om return dt.millisOfSecond().roundCeilingCopy().minusMillis(dt.getMillisOfSecond() % p.getMillis()); }
From source file:org.jevis.commons.driver.DataSourceHelper.java
License:Open Source License
private static DateTime getFolderTime(String name, String[] pathStream) { String compactDateString = getCompactDateString(name, pathStream); String compactDataFormatString = getCompactDateFormatString(name, pathStream); DateTimeFormatter dtf = DateTimeFormat.forPattern(compactDataFormatString); DateTime parseDateTime = dtf.parseDateTime(compactDateString); if (parseDateTime.year().get() == parseDateTime.year().getMinimumValue()) { parseDateTime = parseDateTime.year().withMaximumValue(); }//from w w w.j a va 2 s .co m if (parseDateTime.monthOfYear().get() == parseDateTime.monthOfYear().getMinimumValue()) { parseDateTime = parseDateTime.monthOfYear().withMaximumValue(); } if (parseDateTime.dayOfMonth().get() == parseDateTime.dayOfMonth().getMinimumValue()) { parseDateTime = parseDateTime.dayOfMonth().withMaximumValue(); } if (parseDateTime.hourOfDay().get() == parseDateTime.hourOfDay().getMinimumValue()) { parseDateTime = parseDateTime.hourOfDay().withMaximumValue(); } if (parseDateTime.minuteOfHour().get() == parseDateTime.minuteOfHour().getMinimumValue()) { parseDateTime = parseDateTime.minuteOfHour().withMaximumValue(); } if (parseDateTime.secondOfMinute().get() == parseDateTime.secondOfMinute().getMinimumValue()) { parseDateTime = parseDateTime.secondOfMinute().withMaximumValue(); } if (parseDateTime.millisOfSecond().get() == parseDateTime.millisOfSecond().getMinimumValue()) { parseDateTime = parseDateTime.millisOfSecond().withMaximumValue(); } return parseDateTime; }
From source file:org.joda.example.time.Examples.java
License:Apache License
private void runDateTime() { System.out.println("DateTime"); System.out.println("======="); System.out.println(// w ww . j a v a 2 s. c om "DateTime stores a the date and time using millisecs from 1970-01-01T00:00:00Z internally"); System.out.println("DateTime is immutable and thread-safe"); System.out.println(" in = new DateTime()"); DateTime in = new DateTime(); System.out.println("Millisecond time: in.getMillis(): " + in.getMillis()); System.out.println("ISO string version: in.toString(): " + in.toString()); System.out.println("ISO chronology: in.getChronology(): " + in.getChronology()); System.out.println("Your time zone: in.getDateTimeZone(): " + in.getZone()); System.out.println("Change millis: in.withMillis(0): " + in.withMillis(0L)); System.out.println(""); System.out.println("Get year: in.getYear(): " + in.getYear()); System.out.println("Get monthOfYear: in.getMonthOfYear(): " + in.getMonthOfYear()); System.out.println("Get dayOfMonth: in.getDayOfMonth(): " + in.getDayOfMonth()); System.out.println("..."); System.out.println("Property access: in.dayOfWeek().get(): " + in.dayOfWeek().get()); System.out.println( "Day of week as text: in.dayOfWeek().getAsText(): " + in.dayOfWeek().getAsText()); System.out.println( "Day as short text: in.dayOfWeek().getAsShortText(): " + in.dayOfWeek().getAsShortText()); System.out.println("Day in french: in.dayOfWeek().getAsText(Locale.FRENCH):" + in.dayOfWeek().getAsText(Locale.FRENCH)); System.out.println("Max allowed value: in.dayOfWeek().getMaximumValue(): " + in.dayOfWeek().getMaximumValue()); System.out.println("Min allowed value: in.dayOfWeek().getMinimumValue(): " + in.dayOfWeek().getMinimumValue()); System.out.println( "Copy & set to Jan: in.monthOfYear().setCopy(1): " + in.monthOfYear().setCopy(1)); System.out.println( "Copy & add 14 months: in.monthOfYear().addCopy(14): " + in.monthOfYear().addToCopy(14)); System.out.println("Add 14 mnths in field:in.monthOfYear().addWrapFieldCopy(14): " + in.monthOfYear().addWrapFieldToCopy(14)); System.out.println("..."); System.out.println("Convert to Instant: in.toInstant(): " + in.toInstant()); System.out.println("Convert to DateTime: in.toDateTime(): " + in.toDateTime()); System.out.println("Convert to MutableDT: in.toMutableDateTime(): " + in.toMutableDateTime()); System.out.println("Convert to Date: in.toDate(): " + in.toDate()); System.out.println("Convert to Calendar: in.toCalendar(Locale.UK): " + in.toCalendar(Locale.UK).toString().substring(0, 46)); System.out.println("Convert to GregCal: in.toGregorianCalendar(): " + in.toGregorianCalendar().toString().substring(0, 46)); System.out.println(""); System.out.println(" in2 = new DateTime(in.getMillis() + 10)"); DateTime in2 = new DateTime(in.getMillis() + 10); System.out.println("Equals ms and chrono: in.equals(in2): " + in.equals(in2)); System.out.println("Compare millisecond: in.compareTo(in2): " + in.compareTo(in2)); System.out.println("Compare millisecond: in.isEqual(in2): " + in.isEqual(in2)); System.out.println("Compare millisecond: in.isAfter(in2): " + in.isAfter(in2)); System.out.println("Compare millisecond: in.isBefore(in2): " + in.isBefore(in2)); }
From source file:org.shadowmask.core.mask.rules.generalizer.impl.TimestampGeneralizer.java
License:Apache License
@Override public Long generalize(Long timestamp, int hierarchyLevel) { if (timestamp == null) { return null; }/*from w ww. jav a 2 s .co m*/ if (hierarchyLevel > ROOT_HIERARCHY_LEVEL || hierarchyLevel < 0) { throw new MaskRuntimeException("Root hierarchy level of MobileGeneralizer is " + ROOT_HIERARCHY_LEVEL + ", invalid input hierarchy level[" + hierarchyLevel + "]"); } if (hierarchyLevel == 0) { return timestamp; } try { DateTime dateTime = new DateTime(timestamp); switch (hierarchyLevel) { // mask ms. case 1: dateTime = new DateTime(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth(), dateTime.getHourOfDay(), dateTime.getMinuteOfHour(), dateTime.getSecondOfMinute()); break; // mask second. case 2: dateTime = new DateTime(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth(), dateTime.getHourOfDay(), dateTime.getMinuteOfHour()); break; // mask minute. case 3: dateTime = new DateTime(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth(), dateTime.getHourOfDay(), dateTime.getMinuteOfHour()); dateTime = dateTime.minuteOfHour().setCopy(0); break; // mask hour. case 4: dateTime = new DateTime(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth(), dateTime.getHourOfDay(), dateTime.getMinuteOfHour()); dateTime = dateTime.minuteOfHour().setCopy(0); dateTime = dateTime.hourOfDay().setCopy(0); break; // mask day. case 5: dateTime = new DateTime(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth(), dateTime.getHourOfDay(), dateTime.getMinuteOfHour()); dateTime = dateTime.minuteOfHour().setCopy(0); dateTime = dateTime.hourOfDay().setCopy(0); dateTime = dateTime.dayOfMonth().setCopy(1); break; // mask month. case 6: dateTime = new DateTime(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth(), dateTime.getHourOfDay(), dateTime.getMinuteOfHour()); dateTime = dateTime.minuteOfHour().setCopy(0); dateTime = dateTime.hourOfDay().setCopy(0); dateTime = dateTime.dayOfMonth().setCopy(1); dateTime = dateTime.monthOfYear().setCopy(1); break; // mask year. case 7: dateTime = new DateTime(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth(), dateTime.getHourOfDay(), dateTime.getMinuteOfHour()); dateTime = dateTime.minuteOfHour().setCopy(0); dateTime = dateTime.hourOfDay().setCopy(0); dateTime = dateTime.dayOfMonth().setCopy(1); dateTime = dateTime.monthOfYear().setCopy(1); dateTime = dateTime.year().setCopy(1901); break; } return dateTime.getMillis(); } catch (Throwable e) { throw new MaskRuntimeException("Invalid timestamp to generalize:" + timestamp, e); } }
From source file:org.springframework.analytics.metrics.redis.RedisAggregateCounterRepository.java
License:Apache License
private long[] getMonthCountsForYear(String name, DateTime year) { AggregateKeyGenerator akg = new AggregateKeyGenerator(AGGREGATE_COUNTER_KEY_PREFIX, name, year); return convertToArray(getEntries(akg.getYearKey()), year.monthOfYear().getMaximumValue(), true); // Months in this year }
From source file:org.springframework.cloud.stream.app.metrics.redis.RedisAggregateCounterRepository.java
License:Apache License
private long[] getMonthCountsForYear(String name, DateTime year) { AggregateKeyGenerator akg = new AggregateKeyGenerator(REPO_PREFIX, name, year); return convertToArray(getEntries(akg.getYearKey()), year.monthOfYear().getMaximumValue(), true); // Months in this year }
From source file:org.springframework.xd.analytics.metrics.redis.RedisAggregateCounterRepository.java
License:Apache License
private long[] getMonthCountsForYear(String name, DateTime year) { AggregateKeyGenerator akg = new AggregateKeyGenerator(getPrefix(), name, year); return convertToArray(getEntries(akg.getYearKey()), year.monthOfYear().getMaximumValue(), true); // Months in this year }
From source file:org.thymeleaf.stripes.expression.JodaDates.java
License:Apache License
/** * monthName methods/*from w ww. j a va 2 s . com*/ * Defaults to Long Style */ public String monthName(final DateTime target) { if (target == null) return null; return target.monthOfYear().getAsText(locale); }
From source file:org.thymeleaf.stripes.expression.JodaDates.java
License:Apache License
public String monthNameShort(final DateTime target) { if (target == null) return null; return target.monthOfYear().getAsShortText(locale); }