List of usage examples for java.util GregorianCalendar setTime
public final void setTime(Date date)
Date
. From source file:com.athena.peacock.common.core.util.XMLGregorialCalendarUtil.java
/** * <pre>/*from www . ja v a2s. com*/ * ? GMT+09:00? UTC . * </pre> * @param date * @param tz * @return ? * @throws DatatypeConfigurationException */ private static GregorianCalendar convertTimezone(Date date, TimeZone tz) throws DatatypeConfigurationException { Assert.notNull(date, "date must not be null."); Assert.notNull(tz, "tz must not be null."); GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("ROK")); cal.setTime(date); cal.setTimeZone(tz); return cal; }
From source file:org.mifos.calendar.CalendarUtils.java
public static DateTime getNextDateForMonthOnDate(final DateTime startDate, final int dayOfMonth, final int every) { final GregorianCalendar gc = new GregorianCalendar(); gc.setTime(startDate.toDate()); gc.add(GregorianCalendar.MONTH, every); int M1 = gc.get(GregorianCalendar.MONTH); gc.set(GregorianCalendar.DATE, dayOfMonth); int M2 = gc.get(GregorianCalendar.MONTH); int daynum = dayOfMonth; while (M1 != M2) { gc.set(GregorianCalendar.MONTH, gc.get(GregorianCalendar.MONTH) - 1); gc.set(GregorianCalendar.DATE, daynum - 1); M2 = gc.get(GregorianCalendar.MONTH); daynum--;/*from ww w . ja v a2 s . c o m*/ } return new DateTime(gc.getTime().getTime()); }
From source file:de.dekarlab.moneybuilder.model.parser.JsonBookLoader.java
/** * Load book from JSON file.// w w w . ja v a 2 s.c o m * * @return */ public static Book loadBook(File file) throws Exception { Book book = new Book(); if (!file.exists()) { book.setName("Book"); GregorianCalendar cal = new GregorianCalendar(); cal.setTime(new Date()); cal.set(Calendar.DAY_OF_MONTH, 1); // create period Period newPeriod = new Period(cal.getTime()); newPeriod.setId(Formatter.formatDateId(cal.getTime())); book.getPeriodList().add(newPeriod); book.setCurrPeriod(newPeriod); book.getAssetList().setName(App.getGuiProp("default.assets")); book.getLiabilityList().setName(App.getGuiProp("default.liability")); book.getExpenseList().setName(App.getGuiProp("default.expenses")); book.getIncomeList().setName(App.getGuiProp("default.income")); return book; } FileReader fr = null; try { fr = new FileReader(file); JSONTokener jsonTokener = new JSONTokener(fr); JSONObject root = new JSONObject(jsonTokener); JSONObject jsonBook = root.getJSONObject("book"); book.setName(jsonBook.getString("name")); book.setCurrPeriodId(jsonBook.getString("currPeriodId")); parseAccounts(jsonBook.getJSONObject("assets"), book.getAssetList()); parseAccounts(jsonBook.getJSONObject("liability"), book.getLiabilityList()); parseAccounts(jsonBook.getJSONObject("income"), book.getIncomeList()); parseAccounts(jsonBook.getJSONObject("expenses"), book.getExpenseList()); parsePeriods(jsonBook.getJSONArray("periodList"), book.getPeriodList(), book); } finally { if (fr != null) { fr.close(); } } return book; }
From source file:org.mifos.calendar.CalendarUtils.java
/** * for monthly on date return the next date falling on the same day. If date has passed, pass in the date of next * month, adjust to day number if day number exceed total number of days in month *//*from w ww.j a v a 2s . c om*/ public static DateTime getFirstDateForMonthOnDate(final DateTime startDate, final int dayOfMonth) { final GregorianCalendar gc = new GregorianCalendar(); gc.setTime(startDate.toDate()); int dt = gc.get(GregorianCalendar.DATE); // if date passed in, is after the date on which schedule has to // lie, move to next month if (dt > dayOfMonth) { gc.add(GregorianCalendar.MONTH, 1); } // set the date on which schedule has to lie int M1 = gc.get(GregorianCalendar.MONTH); gc.set(GregorianCalendar.DATE, dayOfMonth); int M2 = gc.get(GregorianCalendar.MONTH); int daynum = dayOfMonth; while (M1 != M2) { gc.set(GregorianCalendar.MONTH, gc.get(GregorianCalendar.MONTH) - 1); gc.set(GregorianCalendar.DATE, daynum - 1); M2 = gc.get(GregorianCalendar.MONTH); daynum--; } return new DateTime(gc.getTime()); }
From source file:be.vds.jtbdive.client.view.core.stats.StatChartGenerator.java
private static JFreeChart buildChartForDive(StatQueryObject sqo) { Collection<StatSerie> s = sqo.getValues(); String legend = I18nResourceManager.sharedInstance().getString("dive.times"); TimeSeriesCollection collection = new TimeSeriesCollection(); for (StatSerie statSerie : s) { TimeSeries ts = new TimeSeries(legend); for (StatPoint point : statSerie.getPoints()) { Date dd = (Date) point.getX(); FixedMillisecond day = new FixedMillisecond(dd); Object index = ts.getDataItem(day); if (null != index) { GregorianCalendar gc = new GregorianCalendar(); gc.setTime(dd); gc.add(Calendar.MILLISECOND, 1); day = new FixedMillisecond(gc.getTime()); }//from ww w. j av a 2 s .c om if (sqo.getStatYAxisParams().getStatYAxis().equals(StatYAxis.DEPTHS)) { ts.add(day, UnitsAgent.getInstance().convertLengthFromModel((Double) point.getY())); } else if (sqo.getStatYAxisParams().getStatYAxis().equals(StatYAxis.TEMPERATURES)) { ts.add(day, UnitsAgent.getInstance().convertTemperatureFromModel((Double) point.getY())); } else { ts.add(day, point.getY()); } } collection.addSeries(ts); } JFreeChart chart = createLineChart(collection, getXLabel(sqo), getYLabel(sqo)); if (sqo.getStatYAxisParams().getStatYAxis().equals(StatYAxis.DIVE_TIME)) { XYPlot xyp = (XYPlot) chart.getPlot(); ((NumberAxis) xyp.getRangeAxis()).setNumberFormatOverride(new HoursMinutesNumberFormat()); } return chart; }
From source file:com.athena.peacock.common.core.util.XMLGregorialCalendarUtil.java
/** * <pre>// w w w . j ava 2 s .c om * YYYY-MM-DDTHH:MI:SS.SSS+09:00 ? ?(:2007-02-13T10:25:05.986+07:00) ? GregorianCalendar ?. * </pre> * * @param stringTypeDate YYYY-MM-DDTHH:MI:SS.SSS+09:00 ? ?(:2007-02-13T10:25:05.986+07:00) * @return ? GregorianCalendar */ private static GregorianCalendar gmtStringToGregorianCalendar(String stringTypeDate) throws DatatypeConfigurationException { String yyyy = stringTypeDate.substring(0, 4); String mm = stringTypeDate.substring(5, 7); String dd = stringTypeDate.substring(8, 10); String hh = "00"; String mi = "00"; String ss = "00"; String ms = "00"; String tz = null; if (stringTypeDate.length() > 23) { hh = stringTypeDate.substring(11, 13); mi = stringTypeDate.substring(14, 16); ss = stringTypeDate.substring(17, 19); ms = stringTypeDate.substring(20, 23); tz = stringTypeDate.substring(23); } else { tz = stringTypeDate.substring(10); //tz = "+09:00"; } if (tz.equals("Z")) { tz = "UTC"; } else { tz = "GMT" + tz; } int iyyyy = Integer.parseInt(yyyy); int imm = Integer.parseInt(mm) - 1; int idd = Integer.parseInt(dd); int ihh = Integer.parseInt(hh); int imi = Integer.parseInt(mi); int iss = Integer.parseInt(ss); int ims = Integer.parseInt(ms); Calendar c = Calendar.getInstance(); c.setTimeZone(TimeZone.getTimeZone(tz)); c.set(iyyyy, imm, idd, ihh, imi, iss); c.set(Calendar.MILLISECOND, ims); GregorianCalendar cal = new GregorianCalendar(); cal.setTime(c.getTime()); cal.setTimeZone(TimeZone.getTimeZone("ROK")); return cal; }
From source file:org.mifos.calendar.CalendarUtils.java
/** * Set the day of week according to given start day to the require weekday, i.e. so it matches the meeting week day. * * e.g. - If start date is Monday 9 June 2008 and meeting week day is Tuesday, then roll forward the date to Tuesday * 10 June 2008 - or if start date is Sunday 8 June 2008 and meeting week day is Saturday, then roll forward the * date to Saturday 14 June 2008 - or if start date is Tuesday 10 2008 June and meeting week day is Monday, then * roll forward the date to Monday 16 June 2008 - or if start date is Sunday 8 June 2008 and meeting week day is * Sunday, then keep the date as Sunday 8 June 2008 - or if start date is Saturday 7 June 2008 and meeting week day * is Sunday, then roll forward the date to Sunday 9 June 2008. *///from ww w. j a v a 2 s . co m public static DateTime getFirstDateForWeek(final DateTime startDate, final int dayOfWeek) { /* * In Joda time MONDAY=1 and SUNDAY=7, so shift these to SUNDAY=1, SATURDAY=7 to match this class */ int calendarDayOfWeek = (dayOfWeek % 7) + 1; final GregorianCalendar firstDateForWeek = new GregorianCalendar(); firstDateForWeek.setTime(startDate.toDate()); int startDateWeekDay = firstDateForWeek.get(Calendar.DAY_OF_WEEK); int amountOfDaysToAdd = calendarDayOfWeek - startDateWeekDay; if (amountOfDaysToAdd < 0) { amountOfDaysToAdd += 7; } firstDateForWeek.add(Calendar.DAY_OF_WEEK, amountOfDaysToAdd); return new DateTime(firstDateForWeek.getTime()); }
From source file:org.mifos.calendar.CalendarUtils.java
public static DateTime getNextDayForMonthUsingWeekRankAndWeekday(final DateTime startDate, final int weekOfMonth, final int dayOfWeek, final int every) { /*//from w ww . j a v a2s . co m * In Joda time MONDAY=1 and SUNDAY=7, so shift these to SUNDAY=1, SATURDAY=7 to match this class */ int calendarDayOfWeek = (dayOfWeek % 7) + 1; final GregorianCalendar gc = new GregorianCalendar(); gc.setTime(startDate.toDate()); DateTime scheduleDate; if (!RankOfDay.getRankOfDay(weekOfMonth).equals(RankOfDay.LAST)) { // apply month recurrence gc.add(GregorianCalendar.MONTH, every); gc.set(Calendar.DAY_OF_WEEK, calendarDayOfWeek); gc.set(GregorianCalendar.DAY_OF_WEEK_IN_MONTH, weekOfMonth); scheduleDate = new DateTime(gc.getTime().getTime()); } else {// weekCount=-1 gc.set(GregorianCalendar.DATE, 15); gc.add(GregorianCalendar.MONTH, every); gc.set(Calendar.DAY_OF_WEEK, calendarDayOfWeek); int M1 = gc.get(GregorianCalendar.MONTH); // assumption: there are 5 weekdays in the month gc.set(GregorianCalendar.DAY_OF_WEEK_IN_MONTH, 5); int M2 = gc.get(GregorianCalendar.MONTH); // if assumption fails, it means there exists 4 weekdays in a // month, return last weekday date // if M1==M2, means there exists 5 weekdays otherwise 4 weekdays // in a month if (M1 != M2) { gc.set(GregorianCalendar.MONTH, gc.get(GregorianCalendar.MONTH) - 1); gc.set(GregorianCalendar.DAY_OF_WEEK_IN_MONTH, 4); } scheduleDate = new DateTime(gc.getTime().getTime()); } return scheduleDate; }
From source file:org.oscarehr.phr.model.PHRDocument.java
protected static XMLGregorianCalendar dateToXmlGregorianCalendar(Date date) throws DatatypeConfigurationException { DatatypeFactory datatypeFactory = DatatypeFactory.newInstance(); GregorianCalendar gregorianCalendar = new GregorianCalendar(); gregorianCalendar.setTime(date); return datatypeFactory.newXMLGregorianCalendar(gregorianCalendar); }
From source file:org.mifos.calendar.CalendarUtils.java
public static DateTime getFirstDayForMonthUsingWeekRankAndWeekday(final DateTime startDate, final int calendarWeekOfMonth, final int dayOfWeek) { /*// ww w . ja v a 2 s . c o m * In Joda time MONDAY=1 and SUNDAY=7, so shift these to SUNDAY=1, SATURDAY=7 to match this class */ int calendarDayOfWeek = (dayOfWeek % 7) + 1; final GregorianCalendar gc = new GregorianCalendar(); gc.setTime(startDate.toDate()); DateTime scheduleDate = null; // if current weekday is after the weekday on which schedule has to // lie, move to next week if (gc.get(Calendar.DAY_OF_WEEK) > calendarDayOfWeek) { gc.add(Calendar.WEEK_OF_MONTH, 1); } // set the weekday on which schedule has to lie gc.set(Calendar.DAY_OF_WEEK, calendarDayOfWeek); // if week rank is First, Second, Third or Fourth, Set the // respective week. // if current week rank is after the weekrank on which schedule has // to lie, move to next month if (!RankOfDay.getRankOfDay(calendarWeekOfMonth).equals(RankOfDay.LAST)) { if (gc.get(Calendar.DAY_OF_WEEK_IN_MONTH) > calendarWeekOfMonth) { gc.add(GregorianCalendar.MONTH, 1); gc.set(GregorianCalendar.DATE, 1); } // set the weekrank on which schedule has to lie gc.set(GregorianCalendar.DAY_OF_WEEK_IN_MONTH, calendarWeekOfMonth); scheduleDate = new DateTime(gc.getTime().getTime()); } else {// scheduleData.getWeekRank()=Last int M1 = gc.get(GregorianCalendar.MONTH); // assumption: there are 5 weekdays in the month gc.set(GregorianCalendar.DAY_OF_WEEK_IN_MONTH, 5); int M2 = gc.get(GregorianCalendar.MONTH); // if assumption fails, it means there exists 4 weekdays in a // month, return last weekday date // if M1==M2, means there exists 5 weekdays otherwise 4 weekdays // in a month if (M1 != M2) { gc.set(GregorianCalendar.MONTH, gc.get(GregorianCalendar.MONTH) - 1); gc.set(GregorianCalendar.DAY_OF_WEEK_IN_MONTH, 4); } scheduleDate = new DateTime(gc.getTime().getTime()); } return scheduleDate; }