Java Code Examples for com.ibm.icu.util.Calendar#clone()
The following examples show how to use
com.ibm.icu.util.Calendar#clone() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FormatterImpl.java From org.openntf.domino with Apache License 2.0 | 6 votes |
public String formatDateTimeWithFormat(final DateTime sdt, final String format) { Calendar cal = sdt.toJavaCal(); if (sdt.isAnyDate() || sdt.isAnyTime()) { Calendar calCopy = (Calendar) cal.clone(); if (sdt.isAnyDate()) { calCopy.set(YEAR, 1970); calCopy.set(MONTH, 0); calCopy.set(DAY_OF_MONTH, 1); } if (sdt.isAnyTime()) { calCopy.set(HOUR_OF_DAY, 0); calCopy.set(MINUTE, 0); calCopy.set(SECOND, 0); } cal = calCopy; } return formatCalWithFormat(cal, format); }
Example 2
Source File: TemporalExpressions.java From scipio-erp with Apache License 2.0 | 6 votes |
@Override public boolean includesDate(Calendar cal) { int month = cal.get(Calendar.MONTH); if (month == this.start || month == this.end) { return true; } Calendar compareCal = (Calendar) cal.clone(); while (compareCal.get(Calendar.MONTH) != this.start) { compareCal.add(Calendar.MONTH, 1); } while (compareCal.get(Calendar.MONTH) != this.end) { if (compareCal.get(Calendar.MONTH) == month) { return true; } compareCal.add(Calendar.MONTH, 1); } return false; }
Example 3
Source File: TemporalExpressions.java From scipio-erp with Apache License 2.0 | 6 votes |
@Override public boolean includesDate(Calendar cal) { int minute = cal.get(Calendar.MINUTE); if (minute == this.start || minute == this.end) { return true; } Calendar compareCal = (Calendar) cal.clone(); compareCal.set(Calendar.MINUTE, this.start); while (compareCal.get(Calendar.MINUTE) != this.end) { if (compareCal.get(Calendar.MINUTE) == minute) { return true; } compareCal.add(Calendar.MINUTE, 1); } return false; }
Example 4
Source File: TemporalExpressions.java From scipio-erp with Apache License 2.0 | 6 votes |
@Override public boolean includesDate(Calendar cal) { int dow = cal.get(Calendar.DAY_OF_WEEK); if (dow == this.start || dow == this.end) { return true; } Calendar compareCal = (Calendar) cal.clone(); while (compareCal.get(Calendar.DAY_OF_WEEK) != this.start) { compareCal.add(Calendar.DAY_OF_MONTH, 1); } while (compareCal.get(Calendar.DAY_OF_WEEK) != this.end) { if (compareCal.get(Calendar.DAY_OF_WEEK) == dow) { return true; } compareCal.add(Calendar.DAY_OF_MONTH, 1); } return false; }
Example 5
Source File: TemporalExpressions.java From scipio-erp with Apache License 2.0 | 6 votes |
@Override public boolean includesDate(Calendar cal) { int hour = cal.get(Calendar.HOUR_OF_DAY); if (hour == this.start || hour == this.end) { return true; } Calendar compareCal = (Calendar) cal.clone(); compareCal.set(Calendar.HOUR_OF_DAY, this.start); while (compareCal.get(Calendar.HOUR_OF_DAY) != this.end) { if (compareCal.get(Calendar.HOUR_OF_DAY) == hour) { return true; } compareCal.add(Calendar.HOUR_OF_DAY, 1); } return false; }
Example 6
Source File: TemporalExpressions.java From scipio-erp with Apache License 2.0 | 5 votes |
protected Calendar prepareCal(Calendar cal) { // Performs a "sane" skip forward in time - avoids time consuming loops // like incrementing every second from Jan 1 2000 until today Calendar skip = (Calendar) cal.clone(); skip.setTime(this.start); long deltaMillis = cal.getTimeInMillis() - this.start.getTime(); if (deltaMillis < 1000) { return skip; } long divisor = deltaMillis; if (this.freqType == Calendar.DAY_OF_MONTH) { divisor = 86400000; } else if (this.freqType == Calendar.HOUR) { divisor = 3600000; } else if (this.freqType == Calendar.MINUTE) { divisor = 60000; } else if (this.freqType == Calendar.SECOND) { divisor = 1000; } else { return skip; } long units = deltaMillis / divisor; units -= units % this.freqCount; skip.add(this.freqType, (int)units); while (skip.after(cal)) { skip.add(this.freqType, -this.freqCount); } return skip; }
Example 7
Source File: TemporalExpressions.java From scipio-erp with Apache License 2.0 | 5 votes |
@Override public boolean isSubstitutionCandidate(Calendar cal, TemporalExpression expressionToTest) { Calendar checkCal = (Calendar) cal.clone(); checkCal.add(Calendar.MONTH, -1); while (!includesDate(checkCal)) { if (expressionToTest.includesDate(checkCal)) { return true; } checkCal.add(Calendar.MONTH, -1); } return false; }
Example 8
Source File: TemporalExpressions.java From scipio-erp with Apache License 2.0 | 5 votes |
@Override public boolean isSubstitutionCandidate(Calendar cal, TemporalExpression expressionToTest) { Calendar checkCal = (Calendar) cal.clone(); checkCal.add(Calendar.MINUTE, -1); while (!includesDate(checkCal)) { if (expressionToTest.includesDate(checkCal)) { return true; } checkCal.add(Calendar.MINUTE, -1); } return false; }
Example 9
Source File: TemporalExpressions.java From scipio-erp with Apache License 2.0 | 5 votes |
@Override public boolean isSubstitutionCandidate(Calendar cal, TemporalExpression expressionToTest) { Calendar checkCal = (Calendar) cal.clone(); checkCal.add(Calendar.HOUR_OF_DAY, -1); while (!includesDate(checkCal)) { if (expressionToTest.includesDate(checkCal)) { return true; } checkCal.add(Calendar.HOUR_OF_DAY, -1); } return false; }
Example 10
Source File: TemporalExpressions.java From scipio-erp with Apache License 2.0 | 5 votes |
@Override public boolean isSubstitutionCandidate(Calendar cal, TemporalExpression expressionToTest) { Calendar checkCal = (Calendar) cal.clone(); checkCal.add(this.freqType, -this.freqCount); while (!includesDate(checkCal)) { if (expressionToTest.includesDate(checkCal)) { return true; } checkCal.add(this.freqType, -this.freqCount); } return false; }
Example 11
Source File: TemporalExpressions.java From scipio-erp with Apache License 2.0 | 5 votes |
@Override public boolean isSubstitutionCandidate(Calendar cal, TemporalExpression expressionToTest) { Calendar checkCal = (Calendar) cal.clone(); checkCal.add(Calendar.DAY_OF_MONTH, -1); while (!includesDate(checkCal)) { if (expressionToTest.includesDate(checkCal)) { return true; } checkCal.add(Calendar.DAY_OF_MONTH, -1); } return false; }
Example 12
Source File: TemporalExpressions.java From scipio-erp with Apache License 2.0 | 5 votes |
@Override public boolean isSubstitutionCandidate(Calendar cal, TemporalExpression expressionToTest) { Calendar checkCal = (Calendar) cal.clone(); checkCal.add(Calendar.DAY_OF_MONTH, -1); while (!includesDate(checkCal)) { if (expressionToTest.includesDate(checkCal)) { return true; } checkCal.add(Calendar.DAY_OF_MONTH, -1); } return false; }
Example 13
Source File: TemporalExpressions.java From scipio-erp with Apache License 2.0 | 5 votes |
@Override public boolean includesDate(Calendar cal) { if (cal.get(Calendar.DAY_OF_WEEK) != this.dayOfWeek) { return false; } int month = cal.get(Calendar.MONTH); int dom = cal.get(Calendar.DAY_OF_MONTH); Calendar next = (Calendar) cal.clone(); alignDayOfWeek(next); return dom == next.get(Calendar.DAY_OF_MONTH) && next.get(Calendar.MONTH) == month; }
Example 14
Source File: TimeDuration.java From scipio-erp with Apache License 2.0 | 5 votes |
private static int advanceCalendar(Calendar start, Calendar end, int units, int type) { if (units >= 1) { // Bother, the below needs explanation. // // If start has a day value of 31, and you add to the month, // and the target month is not allowed to have 31 as the day // value, then the day will be changed to a value that is in // range. But, when the code needs to then subtract 1 from // the month, because it has advanced to far, the day is *not* // set back to the original value of 31. // // This bug can be triggered by having a duration of -1 day, // then adding this duration to a calendar that represents 0 // milliseconds, then creating a new duration by using the 2 // Calendar constructor, with cal1 being 0, and cal2 being the // new calendar that you added the duration to. // // To solve this problem, we make a temporary copy of the // start calendar, and only modify it if we actually have to. Calendar tmp = (Calendar) start.clone(); int tmpUnits = units; tmp.add(type, tmpUnits); while (tmp.after(end)) { tmp.add(type, -1); units--; } if (units != 0) { start.add(type, units); } } return units; }
Example 15
Source File: TimeDurationTests.java From scipio-erp with Apache License 2.0 | 5 votes |
public void testDuration() throws Exception { Calendar now = Calendar.getInstance(); TimeDuration zeroDuration = TimeDuration.ZeroTimeDuration; assertFalse("zero equals null", zeroDuration.equals(null)); Calendar newTime = (Calendar) now.clone(); zeroDuration.addToCalendar(newTime); assertEquals("zero same calendar", now, newTime); assertDurationFields("zero(same zero calendar)", 0, 0, 0, 0, 0, 0, 0, "0:0:0:0:0:0:0", new TimeDuration(zero, zero), false, true); assertDurationFields("zero(same now calendar)", 0, 0, 0, 0, 0, 0, 0, "0:0:0:0:0:0:0", new TimeDuration(now, now), false, true); assertDurationFields("zero(empty parse)", 0, 0, 0, 0, 0, 0, 0, "0:0:0:0:0:0:0", TimeDuration.parseDuration(""), false, true); assertDurationFields("zero(zero parse)", 0, 0, 0, 0, 0, 0, 0, "0:0:0:0:0:0:0", TimeDuration.parseDuration("0:0:0:0:0:0:0"), false, true); assertDurationFields("zero(from null number)", 0, 0, 0, 0, 0, 0, 0, "0:0:0:0:0:0:0", TimeDuration.fromNumber(null), false, true); assertDurationFields("zero(from null number)", 0, 0, 0, 0, 0, 0, 0, "0:0:0:0:0:0:0", TimeDuration.fromNumber(null), false, true); assertDuration("millisecond", 0, 0, 0, 0, 0, 0, 1); assertDuration("second", 0, 0 ,0 ,0, 0, 1, 0); assertDuration("minute", 0, 0, 0, 0, 1, 0, 0); assertDuration("hour", 0, 0, 0, 1, 0, 0, 0); assertDuration("day", 0, 0, 1, 0, 0, 0, 0); assertDuration("month", 0, 1, 0, 0, 0, 0, 0); assertDuration("year", 1, 0, 0, 0, 0, 0, 0); Calendar start = new com.ibm.icu.util.GregorianCalendar(1967, 1, 1, 0, 0, 0); start.set(Calendar.MILLISECOND, 0); Calendar end = (Calendar) start.clone(); end.add(Calendar.MILLISECOND, 1); end.add(Calendar.SECOND, 1); end.add(Calendar.MINUTE, 1); end.add(Calendar.HOUR_OF_DAY, 1); end.add(Calendar.DAY_OF_MONTH, 1); end.add(Calendar.MONTH, 1); end.add(Calendar.YEAR, 1); assertDurationFields("pre-epoch elapsed time", 1, 1, 1, 1, 1, 1, 1, "1:1:1:1:1:1:1", new TimeDuration(start, end), false, false); }
Example 16
Source File: RelativeDateFormat.java From fitnotifications with Apache License 2.0 | 5 votes |
/** * @return the number of days in "until-now" */ private static int dayDifference(Calendar until) { Calendar nowCal = (Calendar)until.clone(); Date nowDate = new Date(System.currentTimeMillis()); nowCal.clear(); nowCal.setTime(nowDate); int dayDiff = until.get(Calendar.JULIAN_DAY) - nowCal.get(Calendar.JULIAN_DAY); return dayDiff; }
Example 17
Source File: SpinnerTable.java From birt with Eclipse Public License 1.0 | 4 votes |
/** * sets the calendar * * @param calendar */ public void setCalendar( Calendar calendar ) { this.cale = (Calendar) calendar.clone( ); Calendar tempcalendar = getOriCalendar( calendar ); int dayCount = tempcalendar.getActualMaximum( Calendar.DAY_OF_MONTH ); int moreDayCount = tempcalendar.get( Calendar.DAY_OF_WEEK ) - 1; //int count = table.getItemCount(); for ( int i = 0; i < ROW_COUNT; i++ ) { TableItem item = table.getItem( i ); if ( i == 0 ) { continue; } String[] values = new String[7]; for ( int j = 0; j < DAY_WEEK_COUNT; j++ ) { int index = ( i - 1 ) * DAY_WEEK_COUNT + j; int dayIndex = index - moreDayCount + 1; if ( index < moreDayCount || dayIndex > dayCount ) { values[j] = ""; //$NON-NLS-1$ } else { values[j] = String.valueOf( dayIndex ); } } item.setText( values ); } TableColumn[] cols = table.getColumns( ); int size = cols.length; for ( int i = 0; i < size; i++ ) { cols[i].pack( ); } table.pack( ); setOriValue( ); }
Example 18
Source File: SpinnerTable.java From birt with Eclipse Public License 1.0 | 4 votes |
private Calendar getOriCalendar( Calendar calendar ) { Calendar retValue = (Calendar) calendar.clone( ); retValue.set( Calendar.DAY_OF_MONTH, 1 ); return retValue; }
Example 19
Source File: TrailingFunction.java From birt with Eclipse Public License 1.0 | 4 votes |
/** * Move to get end date. * Note: * If the input is 2011 May, and the offset is 3 months. * The passed-in startDate will be May 1st, 2011, * and calculateUnit is MONTH, that means start from May, * move 3 months, to August, the endDate to be returned is * August 31st, 2011. * @param startDate * @param calculateUnit * @return */ private Calendar getEndDate(Calendar startDate, String calculateUnit ) { Calendar endDate = ( Calendar ) startDate.clone(); if ( calculateUnit.equals( YEAR ) ) { if ( isMoveForward ) setToYearEnd( endDate ); else setToYearStart( endDate); } else if ( calculateUnit.equals( QUARTER ) ) { if ( isMoveForward ) setToQuarterEnd( endDate ); else setToQuarterStart( endDate); } else if ( calculateUnit.equals( MONTH ) ) { if ( isMoveForward ) setToMonthEnd( endDate ); else setToMonthStart( endDate); } else if ( calculateUnit.equals( WEEK ) ) { if ( isMoveForward ) setToWeekEnd( endDate ); else setToWeekStart( endDate); } if ( offsetLevel.equals( TimeMember.TIME_LEVEL_TYPE_YEAR ) ) endDate.add( Calendar.YEAR, offset ); else if ( offsetLevel.equals( TimeMember.TIME_LEVEL_TYPE_QUARTER ) ) endDate.add( Calendar.MONTH, offset *3 ); else if ( offsetLevel.equals( TimeMember.TIME_LEVEL_TYPE_MONTH ) ) endDate.add( Calendar.MONTH, offset ); else if ( offsetLevel.equals( TimeMember.TIME_LEVEL_TYPE_WEEK_OF_MONTH ) ) endDate.add( Calendar.WEEK_OF_YEAR, offset ); else if ( offsetLevel.equals( TimeMember.TIME_LEVEL_TYPE_WEEK_OF_YEAR ) ) endDate.add( Calendar.WEEK_OF_YEAR, offset ); else if ( offsetLevel.equals( TimeMember.TIME_LEVEL_TYPE_DAY_OF_MONTH ) ) endDate.add( Calendar.DATE, offset ); else if ( offsetLevel.equals( TimeMember.TIME_LEVEL_TYPE_DAY_OF_WEEK ) ) endDate.add( Calendar.DATE, offset ); else if ( offsetLevel.equals( TimeMember.TIME_LEVEL_TYPE_DAY_OF_YEAR ) ) endDate.add( Calendar.DATE, offset ); return endDate; }
Example 20
Source File: SimpleDateFormat.java From fitnotifications with Apache License 2.0 | 2 votes |
/** * Package-private constructor that allows a subclass to specify * whether it supports fast formatting. * * TODO make this API public. */ SimpleDateFormat(String pattern, DateFormatSymbols formatData, Calendar calendar, ULocale locale, boolean useFastFormat, String override) { this(pattern, (DateFormatSymbols)formatData.clone(), (Calendar)calendar.clone(), null, locale, useFastFormat,override); }