List of usage examples for org.joda.time.chrono ISOChronology getInstance
public static ISOChronology getInstance()
From source file:AgeCalculator.java
License:Apache License
public AgeCalculator() { super();/*from w w w . j ava 2 s . c om*/ iChronology = ISOChronology.getInstance(); iBirthdateStr = "1970-01-01T00:00:00"; setTitle("Age Calculator"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); addMainArea(getContentPane()); addNotify(); Dimension size = getPreferredSize(); setSize(size); Dimension screenSize = getToolkit().getScreenSize(); setLocation(screenSize.width / 2 - size.width / 2, screenSize.height / 2 - size.height / 2); iTimer = new Timer(500, new ActionListener() { public void actionPerformed(ActionEvent e) { updateResults(); } }); iTimer.setInitialDelay(0); iTimer.start(); }
From source file:com.facebook.presto.plugin.jdbc.JdbcRecordCursor.java
License:Apache License
@Override public long getLong(int field) { checkState(!closed, "cursor is closed"); try {/*from w w w . ja v a 2 s.c o m*/ Type type = getType(field); if (type.equals(TinyintType.TINYINT)) { return (long) resultSet.getByte(field + 1); } if (type.equals(SmallintType.SMALLINT)) { return (long) resultSet.getShort(field + 1); } if (type.equals(IntegerType.INTEGER)) { return (long) resultSet.getInt(field + 1); } if (type.equals(RealType.REAL)) { return (long) floatToRawIntBits(resultSet.getFloat(field + 1)); } if (type.equals(BigintType.BIGINT)) { return resultSet.getLong(field + 1); } if (type.equals(DateType.DATE)) { // JDBC returns a date using a timestamp at midnight in the JVM timezone long localMillis = resultSet.getDate(field + 1).getTime(); // Convert it to a midnight in UTC long utcMillis = ISOChronology.getInstance().getZone().getMillisKeepLocal(UTC, localMillis); // convert to days return TimeUnit.MILLISECONDS.toDays(utcMillis); } if (type.equals(TimeType.TIME)) { Time time = resultSet.getTime(field + 1); return UTC_CHRONOLOGY.millisOfDay().get(time.getTime()); } if (type.equals(TimestampType.TIMESTAMP)) { Timestamp timestamp = resultSet.getTimestamp(field + 1); return timestamp.getTime(); } throw new PrestoException(GENERIC_INTERNAL_ERROR, "Unhandled type for long: " + type.getTypeSignature()); } catch (SQLException | RuntimeException e) { throw handleSqlException(e); } }
From source file:com.facebook.presto.plugin.jdbc.StandardReadMappings.java
License:Apache License
public static ReadMapping dateReadMapping() { return longReadMapping(DATE, (resultSet, columnIndex) -> { /*//from w w w . j av a 2 s . c om * JDBC returns a date using a timestamp at midnight in the JVM timezone, or earliest time after that if there was no midnight. * This works correctly for all dates and zones except when the missing local times 'gap' is 24h. I.e. this fails when JVM time * zone is Pacific/Apia and date to be returned is 2011-12-30. * * `return resultSet.getObject(columnIndex, LocalDate.class).toEpochDay()` avoids these problems but * is currently known not to work with Redshift (old Postgres connector) and SQL Server. */ long localMillis = resultSet.getDate(columnIndex).getTime(); // Convert it to a ~midnight in UTC. long utcMillis = ISOChronology.getInstance().getZone().getMillisKeepLocal(UTC, localMillis); // convert to days return MILLISECONDS.toDays(utcMillis); }); }
From source file:com.gs.fw.common.mithra.util.ImmutableTimestamp.java
License:Apache License
@Deprecated public int getTimezoneOffset() { return -ISOChronology.getInstance().getZone().getOffset(this.getTime()) / 60000; }
From source file:com.helger.datetime.config.PDTConfig.java
License:Apache License
/** * @return The default chronology ({@link ISOChronology} or * {@link GJChronology}) with the system date time zone. Never * <code>null</code>. * @see #isUseISOChronology()/*from w ww . j a v a 2 s . c o m*/ */ @Nonnull public static Chronology getDefaultChronologyWithDefaultDateTimeZone() { if (isUseISOChronology()) return ISOChronology.getInstance(); return GJChronology.getInstance(); }
From source file:com.jjlharrison.jollyday.util.CalendarUtil.java
License:Apache License
/** * Creates the current date within the gregorian calendar. * * @return today//from ww w . ja va 2 s.c om */ public LocalDate create() { return new LocalDate(ISOChronology.getInstance()); }
From source file:com.jjlharrison.jollyday.util.CalendarUtil.java
License:Apache License
/** * Creates the date within the ISO chronology. * * @param year// w w w . java 2s . co m * a int. * @param month * a int. * @param day * a int. * @return date */ public LocalDate create(int year, int month, int day) { return create(year, month, day, ISOChronology.getInstance()); }
From source file:com.jjlharrison.jollyday.util.CalendarUtil.java
License:Apache License
/** * Creates a LocalDate. Does not use the Chronology of the Calendar. * * @param c//from www . j av a2 s.co m * a {@link java.util.Calendar} object. * @return The local date representing the provided date. */ public LocalDate create(final Calendar c) { return new LocalDate(c, ISOChronology.getInstance()); }
From source file:com.jjlharrison.jollyday.util.CalendarUtil.java
License:Apache License
/** * Searches for the occurrences of a month/day in one chronology within one * gregorian year.//www .jav a 2 s.c o m * * @param targetMonth * @param targetDay * @param gregorianYear * @param targetChrono * @return the list of gregorian dates. */ private Set<LocalDate> getDatesFromChronologyWithinGregorianYear(int targetMonth, int targetDay, int gregorianYear, Chronology targetChrono) { Set<LocalDate> holidays = new HashSet<LocalDate>(); LocalDate firstGregorianDate = new LocalDate(gregorianYear, DateTimeConstants.JANUARY, 1, ISOChronology.getInstance()); LocalDate lastGregorianDate = new LocalDate(gregorianYear, DateTimeConstants.DECEMBER, 31, ISOChronology.getInstance()); LocalDate firstTargetDate = new LocalDate(firstGregorianDate.toDateTimeAtStartOfDay().getMillis(), targetChrono); LocalDate lastTargetDate = new LocalDate(lastGregorianDate.toDateTimeAtStartOfDay().getMillis(), targetChrono); Interval interv = new Interval(firstTargetDate.toDateTimeAtStartOfDay(), lastTargetDate.plusDays(1).toDateTimeAtStartOfDay()); int targetYear = firstTargetDate.getYear(); for (; targetYear <= lastTargetDate.getYear();) { LocalDate d = new LocalDate(targetYear, targetMonth, targetDay, targetChrono); if (interv.contains(d.toDateTimeAtStartOfDay())) { holidays.add(convertToISODate(d)); } targetYear++; } return holidays; }
From source file:com.jjlharrison.jollyday.util.CalendarUtil.java
License:Apache License
/** * Converts the provided date into a date within the ISO chronology. If it * is already a ISO date it will return it. * * @param date//from w ww. j a v a2 s . c o m * a {@link org.joda.time.LocalDate} object. * @return a {@link org.joda.time.LocalDate} object. */ public LocalDate convertToISODate(final LocalDate date) { if (!(date.getChronology() instanceof ISOChronology)) { return new LocalDate(date.toDateTimeAtStartOfDay().getMillis(), ISOChronology.getInstance()); } return date; }