List of usage examples for org.joda.time DateTime getSecondOfMinute
public int getSecondOfMinute()
From source file:org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.DlmsHelperService.java
License:Open Source License
/** * Creates a COSEM date-time object based on the given {@code dateTime}. * <p>/*www . ja va 2s . c o m*/ * The deviation and clock status (is daylight saving active or not) are * based on the zone of the given {@code dateTime}. * <p> * To use a DateTime as indication of the instant of time to be used with a * specific deviation (that does not have to match the zone of the * DateTime), use {@link #asDataObject(DateTime, int, boolean)} instead. * * @param dateTime * a DateTime to translate into COSEM date-time format. * @return a DataObject having a CosemDateTime matching the given DateTime * as value. */ public DataObject asDataObject(final DateTime dateTime) { final CosemDate cosemDate = new CosemDate(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth()); final CosemTime cosemTime = new CosemTime(dateTime.getHourOfDay(), dateTime.getMinuteOfHour(), dateTime.getSecondOfMinute(), dateTime.getMillisOfSecond() / 10); final int deviation = -(dateTime.getZone().getOffset(dateTime.getMillis()) / MILLISECONDS_PER_MINUTE); final ClockStatus[] clockStatusBits; if (dateTime.getZone().isStandardOffset(dateTime.getMillis())) { clockStatusBits = new ClockStatus[0]; } else { clockStatusBits = new ClockStatus[1]; clockStatusBits[0] = ClockStatus.DAYLIGHT_SAVING_ACTIVE; } final CosemDateTime cosemDateTime = new CosemDateTime(cosemDate, cosemTime, deviation, clockStatusBits); return DataObject.newDateTimeData(cosemDateTime); }
From source file:org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.DlmsHelperService.java
License:Open Source License
/** * Creates a COSEM date-time object based on the given {@code dateTime}. * This COSEM date-time will be for the same instant in time as the given * {@code dateTime} but may be for another time zone. * <p>// ww w .j av a 2s. c o m * Because the time zone with the {@code deviation} may be different than * the one with the {@code dateTime}, and the {@code deviation} alone does * not provide sufficient information on whether daylight savings is active * for the given instant in time, {@code dst} has to be provided to indicate * whether daylight savings are active. * <p> * If a DateTime for an instant in time is known with the correct time zone * set, you can use {@link #asDataObject(DateTime)} as a simpler * alternative. * * @param dateTime * a DateTime indicating an instant in time to be used for the * COSEM date-time. * @param deviation * the deviation in minutes of local time to GMT to be included * in the COSEM date-time. * @param dst * {@code true} if daylight savings are active for the instant of * the COSEM date-time, otherwise {@code false}. * @return a DataObject having a CosemDateTime for the instant of the given * DateTime, with the given deviation and DST status information, as * value. */ public DataObject asDataObject(final DateTime dateTime, final int deviation, final boolean dst) { /* * Create a date time that may not point to the right instant in time, * but that will give proper values getting the different fields for the * COSEM date and time objects. */ final DateTime dateTimeWithOffset = dateTime.toDateTime(DateTimeZone.UTC).minusMinutes(deviation); final CosemDate cosemDate = new CosemDate(dateTimeWithOffset.getYear(), dateTimeWithOffset.getMonthOfYear(), dateTimeWithOffset.getDayOfMonth()); final CosemTime cosemTime = new CosemTime(dateTimeWithOffset.getHourOfDay(), dateTimeWithOffset.getMinuteOfHour(), dateTimeWithOffset.getSecondOfMinute(), dateTimeWithOffset.getMillisOfSecond() / 10); final ClockStatus[] clockStatusBits; if (dst) { clockStatusBits = new ClockStatus[1]; clockStatusBits[0] = ClockStatus.DAYLIGHT_SAVING_ACTIVE; } else { clockStatusBits = new ClockStatus[0]; } final CosemDateTime cosemDateTime = new CosemDateTime(cosemDate, cosemTime, deviation, clockStatusBits); return DataObject.newDateTimeData(cosemDateTime); }
From source file:org.richfaces.fragment.calendar.TimeEditor.java
License:Open Source License
public TimeEditor setTime(DateTime time, SetValueBy inputType) { return setTime(time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), inputType); }
From source file:org.richfaces.tests.page.fragments.impl.calendar.common.editor.time.RichFacesTimeEditor.java
License:Open Source License
@Override public TimeEditor setTime(DateTime time, SetValueBy inputType) { return setTime(time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), inputType); }
From source file:org.rockholla.date.DateUtility.java
License:Open Source License
/** * Formats a datetime for use in a MySQL datetime field * /*from w ww. ja va 2 s. c o m*/ * @param dateTime the org.joda.time.DateTime value to format * @param offset offset the input datetime by this amount of hours * @return the formatted datetime */ public static String getMySqlDate(DateTime dateTime, int offset) { if (offset > 0 || offset < 0) { dateTime = dateTime.plusHours(offset); } String result = String.valueOf(dateTime.getYear()) + "-" + NumberUtility.format(dateTime.getMonthOfYear(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER) + "-" + NumberUtility.format(dateTime.getDayOfMonth(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER) + " " + NumberUtility.format(dateTime.getHourOfDay(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER) + ":" + NumberUtility.format(dateTime.getMinuteOfHour(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER) + ":" + NumberUtility.format(dateTime.getSecondOfMinute(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER); return result; }
From source file:org.rockholla.date.DateUtility.java
License:Open Source License
/** * Returns a unique string based on a timestamp (DateTime must be precise to the second * to ensure uniqueness)//from w w w.jav a2s. co m * * @param dateTime the org.joda.time.DateTime to use to create the ID * @return a unique string representation of the date */ public static String getTimestampId(DateTime dateTime) { String id = ""; id = NumberUtility.format(dateTime.getYear(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER) + NumberUtility.format(dateTime.getMonthOfYear(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER) + NumberUtility.format(dateTime.getDayOfMonth(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER) + NumberUtility.format(dateTime.getHourOfDay(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER) + NumberUtility.format(dateTime.getMinuteOfHour(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER) + NumberUtility.format(dateTime.getSecondOfMinute(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER) + NumberUtility.format(dateTime.getMillisOfSecond(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER); return id; }
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. j av a 2s . 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.smallmind.javafx.extras.instrument.TimeAxis.java
License:Open Source License
@Override protected List<Long> calculateTickValues(double length, Object range) { LinkedList<Long> ticks = new LinkedList<Long>(); DateTime origin = new DateTime(((EndPoints<Long>) range).getLow()).withMillisOfSecond(0); DateTime bound = new DateTime(((EndPoints<Long>) range).getHigh()); int majorInterval; if ((majorInterval = (origin.getSecondOfMinute() / 15) + 1) < 4) { origin = origin.withSecondOfMinute(majorInterval * 15); } else {/* w w w.j av a 2 s. c om*/ origin = origin.plusMinutes(1).withSecondOfMinute(0); } while (origin.isBefore(bound)) { ticks.add(origin.getMillis()); origin = origin.plusSeconds(15); } return ticks; }
From source file:org.smallmind.javafx.extras.instrument.TimeAxis.java
License:Open Source License
@Override protected List<Long> calculateMinorTickMarks() { LinkedList<Long> ticks = new LinkedList<Long>(); Object range = getRange();//from w ww . ja v a 2s .co m DateTime origin = new DateTime(((EndPoints<Long>) range).getLow()).withMillisOfSecond(0); DateTime bound = new DateTime(((EndPoints<Long>) range).getHigh()); int minorInterval; if ((minorInterval = (origin.getSecondOfMinute() / 5) + 1) < 12) { origin = origin.withSecondOfMinute(minorInterval * 5); } else { origin = origin.plusMinutes(1).withSecondOfMinute(0); } while (origin.isBefore(bound)) { if ((origin.getSecondOfMinute() % 15) != 0) { ticks.add(origin.getMillis()); } origin = origin.plusSeconds(5); } return ticks; }
From source file:org.talend.components.netsuite.AbstractNetSuiteTestBase.java
License:Open Source License
protected static XMLGregorianCalendar composeDateTime() throws Exception { DateTime dateTime = DateTime.now(); XMLGregorianCalendar xts = datatypeFactory.newXMLGregorianCalendar(); xts.setYear(dateTime.getYear());/*from w ww. jav a 2s .c o m*/ xts.setMonth(dateTime.getMonthOfYear()); xts.setDay(dateTime.getDayOfMonth()); xts.setHour(dateTime.getHourOfDay()); xts.setMinute(dateTime.getMinuteOfHour()); xts.setSecond(dateTime.getSecondOfMinute()); xts.setMillisecond(dateTime.getMillisOfSecond()); xts.setTimezone(dateTime.getZone().toTimeZone().getRawOffset() / 60000); return xts; }