List of usage examples for java.util GregorianCalendar GregorianCalendar
public GregorianCalendar()
GregorianCalendar
using the current time in the default time zone with the default Locale.Category#FORMAT FORMAT locale. From source file:com.sapienter.jbilling.server.user.validator.RepeatedPasswordValidator.java
/** * Queries the event_log table to check whether the user has already used * in the past the password he's trying to set now. * @param userId Id of the user whose password is being changed. * @return An array of <code>java.lang.String</code> containing the passwords * recently used by this user./*w ww .j av a2 s . com*/ */ private static String[] getPasswords(Integer userId) throws SQLException, NamingException { String[] passw = null; CachedRowSet cachedResults = new CachedRowSet(); JNDILookup jndi = JNDILookup.getFactory(); Connection conn = jndi.lookUpDataSource().getConnection(); cachedResults.setCommand(UserSQL.findUsedPasswords); GregorianCalendar date = new GregorianCalendar(); date.add(GregorianCalendar.YEAR, -2); cachedResults.setDate(1, new Date(date.getTimeInMillis())); cachedResults.setInt(2, userId); cachedResults.execute(conn); List<String> result = new ArrayList<String>(); while (cachedResults.next()) { result.add(cachedResults.getString(1)); } if (!result.isEmpty()) { passw = new String[result.size()]; int index = 0; for (Iterator i = result.iterator(); i.hasNext();) { passw[index] = (String) i.next(); index++; } } conn.close(); return passw; }
From source file:Main.java
public static XMLGregorianCalendar getXMLDate(final Date dateAndTime) { GregorianCalendar c = new GregorianCalendar(); c.setTimeZone(UTC);// www .j a v a2s. c om c.setTime(dateAndTime); try { XMLGregorianCalendar ret = DatatypeFactory.newInstance().newXMLGregorianCalendar(c); ret.setMillisecond(DatatypeConstants.FIELD_UNDEFINED); return ret; } catch (DatatypeConfigurationException e) { return null; } }
From source file:com.autentia.common.util.DateFormater.java
public static Date normalizeEndDate(Date date) { GregorianCalendar gCalendar = new GregorianCalendar(); gCalendar.setTime(date);/*from w w w . jav a2 s.co m*/ gCalendar.set(Calendar.HOUR_OF_DAY, 23); gCalendar.set(Calendar.MINUTE, 59); gCalendar.set(Calendar.SECOND, 59); gCalendar.set(Calendar.MILLISECOND, 999); return gCalendar.getTime(); }
From source file:org.openhie.openempi.util.DateConverterTest.java
public void testConvertStringToDate() throws Exception { Date today = new Date(); Calendar todayCalendar = new GregorianCalendar(); todayCalendar.setTime(today);// w w w. j a v a 2 s . c om String datePart = DateUtil.convertDateToString(today); Date date = (Date) converter.convert(Date.class, datePart); Calendar cal = new GregorianCalendar(); cal.setTime(date); assertEquals(todayCalendar.get(Calendar.YEAR), cal.get(Calendar.YEAR)); assertEquals(todayCalendar.get(Calendar.MONTH), cal.get(Calendar.MONTH)); assertEquals(todayCalendar.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.DAY_OF_MONTH)); }
From source file:com.boundary.sdk.event.EventCLITest.java
/** * @throws java.lang.Exception//from w w w . j a va2s.c o m */ @Before public void setUp() throws Exception { args = new ArrayList<String>(); cli = new EventCLI(); cal = new GregorianCalendar(); }
From source file:de.dekarlab.moneybuilder.model.parser.JsonBookLoader.java
/** * Load book from JSON file./*from w w w . j a va 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.openmrs.module.drughistory.api.DrugEventServiceTest.java
@Test @ExpectedException(IllegalArgumentException.class) public void generateAllDrugEvents_shouldThrowExceptionIfSinceWhenIsGreaterThanToday() throws Exception { GregorianCalendar gc = new GregorianCalendar(); gc.add(GregorianCalendar.DAY_OF_MONTH, 1); Date sinceWhen = gc.getTime(); Context.getService(DrugEventService.class).generateAllDrugEvents(sinceWhen); }
From source file:DateUtils.java
public static final String dateToString(Date dt, String tzString, String dateformat) { GregorianCalendar cal = new GregorianCalendar(); cal.setTime(dt);//from ww w . j a va 2 s .c o m cal.setTimeZone(TimeZone.getTimeZone(tzString)); StringBuffer ret = new StringBuffer(); String separator = new String(); if (dateformat.equals(DateUtils.FORMAT_YYYYMMDD)) { separator = "-"; } if (dateformat.equals(DateUtils.FORMAT_YYYYMMDD_SLASHES)) { separator = "/"; } ret.append(cal.get(Calendar.YEAR)); ret.append(separator); ret.append(cal.get(Calendar.MONTH) + 1); ret.append(separator); ret.append(cal.get(Calendar.DATE)); return ret.toString(); }
From source file:TestReservasSalas.java
@Test public void testDisponibilidadSala() throws OperationFailedException { Establecimiento e = new Establecimiento(1, "El toque", "123.456.789-1", "calle falsa 123", new Time(700), new Time(1900), 0, "Usaquen", "1234567", "34301293809213820921"); logica.registrarEstablecimiento(e);//from ww w . j a v a2 s. c om Sala s = new Sala(1, logica.consultarEstablecimiento(1), "1000", "Sala de Orcas"); logica.registrarSala(s); Date d = new Date(); GregorianCalendar gc = new GregorianCalendar(); gc.setTime(d); Time t = new Time(gc.getTime().getTime()); assertTrue(logica.verificarDisponibilidadSala(d, t, s.getIdSala(), 1)); Reservacion r = new Reservacion(1, s, d, t, 1); //s.getReservacions().add(r); String resp = logica.registrarReserva(e.getIdEstablecimiento(), s.getIdSala(), d, t, 2); assertFalse(logica.verificarDisponibilidadSala(d, t, s.getIdSala(), 1)); List<Reservacion> l = logica.consultarReservacionesPorSala(s.getIdSala()); System.out.println(l.get(0).getFecha().toString()); Cliente c = new Cliente(1016040342, "ORCA"); logica.registrarCliente(c); for (Reservacion rs : l) { if (rs.getFecha().equals(r.getFecha())) r = rs; } r.setIdReservacion(0); if (resp.equals("0")) logica.crearEnsayoAlquiler(c.getIdCliente(), r, "ensayaremos mucho"); }
From source file:org.psidnell.omnifocus.expr.ExpressionFunctionsTest.java
@Test public void testDateRoundToDay() throws ParseException { Date date1 = ExpressionFunctions.roundToDay(new Date()); Calendar cal2 = new GregorianCalendar(); assertNotEquals(date1, cal2.getTime()); cal2.set(Calendar.HOUR_OF_DAY, 0); cal2.set(Calendar.MINUTE, 0); cal2.set(Calendar.SECOND, 0); cal2.set(Calendar.MILLISECOND, 0); assertEquals(date1, cal2.getTime()); }