Example usage for java.util GregorianCalendar GregorianCalendar

List of usage examples for java.util GregorianCalendar GregorianCalendar

Introduction

In this page you can find the example usage for java.util GregorianCalendar GregorianCalendar.

Prototype

GregorianCalendar(TimeZone zone, Locale locale, boolean flag) 

Source Link

Document

Constructs an empty GregorianCalendar.

Usage

From source file:no.dusken.aranea.service.TestArticleServiceImpl.java

@Before
public void onSetup() {
    issue = new Issue();
    issue.setIssue(1);//from   w w w. j a  v a  2 s.c om
    Calendar from = new GregorianCalendar(2007, 1, 1);
    Calendar to = new GregorianCalendar(2007, 5, 1);

    issue.setFromDate(from);
    issue.setToDate(to);
    issue.setTimeCreated(to);
    issue.setDescription("#UD 01");
    issue = issueService.saveOrUpdate(issue);

    section = new Section();
    section.setName("test");
    section.setUrl("test");
    section = sectionService.saveOrUpdate(section);

    article = new Article();
    article.setTitle("Tittel");
    article.setSummary("Ingress");
    article.setTimeCreated(to);
    article.setText("Lorem Ipsum");
    article.setParent(section);
    article.setIssue(issue);
    article = articleService.saveOrUpdate(article);
}

From source file:it.cilea.osd.jdyna.widget.WidgetDate.java

public long toMilliSeconds(int anno, int mese, int giorno) {

    GregorianCalendar data = new GregorianCalendar(anno, mese, giorno);
    Date d1 = data.getTime();/*www .j  a  va 2 s  . c  o m*/
    long l1 = d1.getTime();

    return l1;

}

From source file:moviemanager.backend.PersonManagerTest.java

/**
 * Unit test for adding persons to database.
 * Attempts to add person to the database and checks if person is present in list of all persons in the database.
 */// w w w  . j a  va 2 s .  c o m
@Test
public void testAddPerson() {
    log.info("Testing adding person...");

    Calendar calendar = new GregorianCalendar(1995, Calendar.DECEMBER, 1);

    Person person = new Person("Jane Doe (Add)", calendar);
    personManager.createPerson(person);

    Long id = person.getId();
    assertNotNull(id);
    Person result = personManager.getPerson(id);
    assertEquals(person, result);
    assertNotSame(person, result);
}

From source file:moviemanager.backend.RelationshipManagerTest.java

@Test
public void addPersonAsCast() {
    log.info("Testing adding person as cast...");
    String personName = "John Doe (personAsCast)";
    String movieTitle = "Cast Movie";

    // create movie
    Movie movie = new Movie();
    movie.setTitle(movieTitle);//  w  w  w . j a  v a2 s  . co m
    movie.setYear(2000);
    movie.setLength(120);
    movieManager.createMovie(movie);
    assertNotNull(movie);

    // create person
    Calendar calendar = new GregorianCalendar(1987, Calendar.APRIL, 27);
    Person person = new Person(personName, calendar);
    personManager.createPerson(person);
    assertNotNull(person);

    // add to relationship dtb and check it was added
    relationManager.addPersonToRole(person, movie, Consts.CAST);
    assertTrue(relationManager.checkRole(person, movie, Consts.CAST));

    // check if person from relationship dtb is the same as person inserted
    List<Person> resultPerson = relationManager.personsOfMovie(movie);
    assertNotNull(resultPerson);
    assertEquals(resultPerson.get(0).getName(), personName);
    assertEquals(resultPerson.get(0), person);

    // check if movie from relationship dtb is the same as movie inserted
    List<Movie> resultMovie = relationManager.moviesOfPerson(person);
    assertNotNull(resultMovie);
    assertEquals(resultMovie.get(0).getTitle(), movieTitle);
    assertEquals(resultMovie.get(0), movie);
}

From source file:org.openhie.openempi.util.DateConverterTest.java

public void testConvertDateToString() throws Exception {
    Calendar cal = new GregorianCalendar(2005, 0, 16);
    String date = (String) converter.convert(String.class, cal.getTime());
    assertEquals(DateUtil.convertDateToString(cal.getTime()), date);
}

From source file:br.com.nordestefomento.jrimum.utilix.TestField.java

@Before
public void setUp() {

    campoString = new Field<String>(StringUtils.EMPTY, 8);
    campoString.setFiller(Filler.WHITE_SPACE_RIGHT);

    campoDate = new Field<Date>(new GregorianCalendar(2007, Calendar.JULY, 22).getTime(), 6,
            DateUtil.FORMAT_DDMMYY);/*from  w ww  . j av a 2  s  .  c o m*/

    campoInteger = new Field<Integer>(0, 6);
    campoInteger.setFiller(Filler.ZERO_LEFT);

    campoLong = new Field<Long>(0L, 6);
    campoLong.setFiller(Filler.ZERO_LEFT);

    campoDecimal = new Field<BigDecimal>(new BigDecimal("875.98"), 11, MonetaryUtil.FORMAT_REAL);
    campoDecimal.setFiller(Filler.ZERO_LEFT);

    campoDecimal_v9 = new Field<BigDecimal>(new BigDecimal("875.9"), 11,
            MonetaryUtil.FORMAT_REAL_UMA_CASA_DECIMAL);
    campoDecimal_v9.setFiller(Filler.ZERO_LEFT);
}

From source file:be.fedict.eid.applet.service.impl.tlv.DateOfBirthDataConvertor.java

public GregorianCalendar convert(byte[] value) throws DataConvertorException {
    String dateOfBirthStr;//from   w  w w  . ja  va2s .  c o m
    try {
        dateOfBirthStr = new String(value, "UTF-8").trim();
    } catch (UnsupportedEncodingException e) {
        throw new DataConvertorException("UTF-8 not supported");
    }
    LOG.debug("\"" + dateOfBirthStr + "\"");
    /*
     * First try to detect the German format as there are cases in which a
     * German format contains both dots and spaces.
     */
    int spaceIdx = dateOfBirthStr.indexOf('.');
    if (-1 == spaceIdx) {
        spaceIdx = dateOfBirthStr.indexOf(' ');
    }

    if (spaceIdx > 0) {
        String dayStr = dateOfBirthStr.substring(0, spaceIdx);
        LOG.debug("day: \"" + dayStr + "\"");
        int day = Integer.parseInt(dayStr);
        String monthStr = dateOfBirthStr.substring(spaceIdx + 1, dateOfBirthStr.length() - 4 - 1);
        if (monthStr.endsWith(".")) {
            monthStr = monthStr.substring(0, monthStr.length() - 1);
        }
        LOG.debug("month: \"" + monthStr + "\"");
        String yearStr = dateOfBirthStr.substring(dateOfBirthStr.length() - 4);
        LOG.debug("year: \"" + yearStr + "\"");
        int year = Integer.parseInt(yearStr);
        int month = toMonth(monthStr);
        return new GregorianCalendar(year, month, day);
    }

    if (dateOfBirthStr.length() == 4) {
        /*
         * "case II2b2". Only a birth year is given
         * 
         * there's no way of representing "missing" fields via
         * GregorianCalendar, so we set Jan 1st
         */
        return new GregorianCalendar(Integer.parseInt(dateOfBirthStr), 0, 1);
    }

    throw new DataConvertorException("Unsupported Birth Date Format [" + dateOfBirthStr + "]");
}

From source file:au.com.jwatmuff.eventmanager.model.misc.SessionLockerTest.java

private static Session setupUnlockedSession(TransactionalDatabase database) throws IOException {
    Session session = null;/*from  www. j  av a  2 s .  c  o m*/
    try {
        CSVImporter.importPlayers(new File("test/player_test_data.csv"), database);
        CSVImporter.importPools(new File("test/pool_test_data.csv"), database);

        CompetitionInfo ci = new CompetitionInfo();
        Calendar cal = new GregorianCalendar(2008, 1, 1);
        ci.setStartDate(cal.getTime());
        cal.roll(GregorianCalendar.DATE, 2);
        ci.setEndDate(cal.getTime());
        ci.setAgeThresholdDate(cal.getTime());
        ci.setName("My Comp");
        ci.setMats(1);
        database.add(ci);

        // lock all players so they can be assigned to pools
        for (Player p : database.findAll(Player.class, PlayerDAO.ALL)) {
            p.setWeight(65.0);
            database.update(p);
            PlayerLocker.lockPlayer(database, p);
        }

        AutoAssign.assignPlayersToPools(database);

        Pool pool = database.findAll(Pool.class, PoolDAO.WITH_PLAYERS).iterator().next();
        for (PlayerPool pp : database.findAll(PlayerPool.class, PlayerPoolDAO.FOR_POOL, pool.getID())) {
            pp.setApproved(true);
            database.update(pp);
        }
        pool = PoolLocker.lockPoolPlayers(database, pool);
        FightGenerator.generateFightsForPool(database, pool);

        pool = PoolLocker.lockPoolFights(database, pool);

        Session mat = new Session();
        mat.setType(Session.SessionType.MAT);
        mat.setMat("Mat");
        database.add(mat);

        session = new Session();
        session.setType(Session.SessionType.NORMAL);
        session.setName("Session");

        Collection<Session> preceding = new ArrayList<Session>();
        Collection<Pool> pools = new ArrayList<Pool>();
        pools.add(pool);

        SessionLinker.insertSession(database, session, mat, preceding, pools);
    } catch (DatabaseStateException ex) {
        fail(ex.getMessage());
    }

    return session;
}

From source file:be.fedict.commons.eid.consumer.tlv.DateOfBirthDataConvertor.java

@Override
public GregorianCalendar convert(final byte[] value) throws DataConvertorException {
    String dateOfBirthStr;/*from w ww  .  j  a  v  a  2 s .c  o m*/
    try {
        dateOfBirthStr = new String(value, "UTF-8").trim();
    } catch (final UnsupportedEncodingException uex) {
        throw new DataConvertorException("UTF-8 not supported");
    }
    LOG.debug("\"" + dateOfBirthStr + "\"");
    /*
     * First try to detect the German format as there are cases in which a
     * German format contains both dots and spaces.
     */
    int spaceIdx = dateOfBirthStr.indexOf('.');
    if (-1 == spaceIdx) {
        spaceIdx = dateOfBirthStr.indexOf(' ');
    }

    if (spaceIdx > 0) {
        final String dayStr = dateOfBirthStr.substring(0, spaceIdx);
        LOG.debug("day: \"" + dayStr + "\"");
        final int day = Integer.parseInt(dayStr);
        String monthStr = dateOfBirthStr.substring(spaceIdx + 1, dateOfBirthStr.length() - 4 - 1);
        if (monthStr.endsWith(".")) {
            monthStr = monthStr.substring(0, monthStr.length() - 1);
        }
        LOG.debug("month: \"" + monthStr + "\"");
        final String yearStr = dateOfBirthStr.substring(dateOfBirthStr.length() - 4);
        LOG.debug("year: \"" + yearStr + "\"");
        final int year = Integer.parseInt(yearStr);
        final int month = toMonth(monthStr);
        return new GregorianCalendar(year, month, day);
    }

    if (dateOfBirthStr.length() == 4) {
        /*
         * "case II2b2". Only a birth year is given
         * 
         * there's no way of representing "missing" fields via
         * GregorianCalendar, so we set Jan 1st
         */
        return new GregorianCalendar(Integer.parseInt(dateOfBirthStr), 0, 1);
    }

    throw new DataConvertorException("Unsupported Birth Date Format [" + dateOfBirthStr + "]");
}

From source file:Easter.java

public static final Calendar findHolyDay(int year) {
    if (year <= 1582) {
        throw new IllegalArgumentException("Algorithm invalid before April 1583");
    }/*from   www .j  av  a2s  .c  om*/
    int golden, century, x, z, d, epact, n;

    golden = (year % 19) + 1; /* E1: metonic cycle */
    century = (year / 100) + 1; /* E2: e.g. 1984 was in 20th C */
    x = (3 * century / 4) - 12; /* E3: leap year correction */
    z = ((8 * century + 5) / 25) - 5; /* E3: sync with moon's orbit */
    d = (5 * year / 4) - x - 10;
    epact = (11 * golden + 20 + z - x) % 30; /* E5: epact */
    if ((epact == 25 && golden > 11) || epact == 24)
        epact++;
    n = 44 - epact;
    n += 30 * (n < 21 ? 1 : 0); /* E6: */
    n += 7 - ((d + n) % 7);
    if (n > 31) /* E7: */
        return new GregorianCalendar(year, 4 - 1, n - 31); /* April */
    else
        return new GregorianCalendar(year, 3 - 1, n); /* March */
}