Example usage for java.util Calendar MONTH

List of usage examples for java.util Calendar MONTH

Introduction

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

Prototype

int MONTH

To view the source code for java.util Calendar MONTH.

Click Source Link

Document

Field number for get and set indicating the month.

Usage

From source file:com.nagarro.core.validator.PaymentDetailsDTOValidator.java

@Override
public void validate(final Object target, final Errors errors) {
    final PaymentDetailsWsDTO paymentDetails = (PaymentDetailsWsDTO) target;

    if (StringUtils.isNotBlank(paymentDetails.getStartMonth())
            && StringUtils.isNotBlank(paymentDetails.getStartYear())
            && StringUtils.isNotBlank(paymentDetails.getExpiryMonth())
            && StringUtils.isNotBlank(paymentDetails.getExpiryYear())) {
        final Calendar start = Calendar.getInstance();
        start.set(Calendar.DAY_OF_MONTH, 0);
        start.set(Calendar.MONTH, Integer.parseInt(paymentDetails.getStartMonth()) - 1);
        start.set(Calendar.YEAR, Integer.parseInt(paymentDetails.getStartYear()) - 1);

        final Calendar expiration = Calendar.getInstance();
        expiration.set(Calendar.DAY_OF_MONTH, 0);
        expiration.set(Calendar.MONTH, Integer.parseInt(paymentDetails.getExpiryMonth()) - 1);
        expiration.set(Calendar.YEAR, Integer.parseInt(paymentDetails.getExpiryYear()) - 1);

        if (start.after(expiration)) {
            errors.rejectValue("startMonth", "payment.startDate.invalid");
        }//from www.  j  a v  a 2s .c o m
    }

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "accountHolderName", "field.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "cardType.code", "field.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "cardNumber", "field.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "expiryMonth", "field.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "expiryYear", "field.required");

    paymentAddressValidator.validate(paymentDetails, errors);
}

From source file:com.example.geomesa.authorizations.AuthorizationsTutorial.java

/**
 * Creates a base filter that will return a small subset of our results. This can be tweaked to
 * return different results if desired. Currently it should return 16 results.
 *
 * @return/*ww w  .  ja v  a2s .c o  m*/
 *
 * @throws CQLException
 * @throws IOException
 */
static Filter createBaseFilter() throws CQLException, IOException {

    // Get a FilterFactory2 to build up our query
    FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();

    // We are going to query for events in Ukraine during the
    // civil unrest.

    // We'll start by looking at a particular day in February of 2014
    Calendar calendar = Calendar.getInstance();
    calendar.clear();
    calendar.set(Calendar.YEAR, 2013);
    calendar.set(Calendar.MONTH, Calendar.JANUARY);
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    Date start = calendar.getTime();

    calendar.set(Calendar.YEAR, 2014);
    calendar.set(Calendar.MONTH, Calendar.APRIL);
    calendar.set(Calendar.DAY_OF_MONTH, 30);
    calendar.set(Calendar.HOUR_OF_DAY, 23);
    Date end = calendar.getTime();
    //        2013-01-01T00:00:00.000Z/2014-04-30T23:00:00.000Z
    Filter timeFilter = ff.between(ff.property(GdeltFeature.Attributes.SQLDATE.getName()), ff.literal(start),
            ff.literal(end));

    // We'll bound our query spatially to Ukraine
    Filter spatialFilter = ff.bbox(GdeltFeature.Attributes.geom.getName(), 31.6, 44, 37.4, 47.75, "EPSG:4326");

    // we'll also restrict our query to only articles about the US, UK or UN
    Filter attributeFilter = ff.like(ff.property(GdeltFeature.Attributes.Actor1Name.getName()), "UNITED%");

    // Now we can combine our filters using a boolean AND operator
    Filter conjunction = ff.and(Arrays.asList(timeFilter, spatialFilter, attributeFilter));

    return conjunction;
}

From source file:edu.stanford.muse.email.CalendarUtil.java

public static int getDiffInMonths(Date firstDate, Date lastDate) {
    Calendar cFirst = new GregorianCalendar();
    cFirst.setTime(firstDate);// w  ww.j a v a 2s . c om
    Calendar cLast = new GregorianCalendar();
    cLast.setTime(lastDate);
    int cFirst_year = cFirst.get(Calendar.YEAR);
    int cFirst_month = cFirst.get(Calendar.MONTH);
    int cLast_year = cLast.get(Calendar.YEAR);
    int cLast_month = cLast.get(Calendar.MONTH);
    return (cLast_year - cFirst_year)
            * (cLast.getMaximum(Calendar.MONTH) - cLast.getMinimum(Calendar.MONTH) + 1)
            + (cLast_month - cFirst_month);
}

From source file:com.eryansky.common.utils.DateUtil.java

/**
 *  ?2009-08-01//  ww w  . j a  v  a2s.c o m
 */
public static String beforeMonth() {
    Calendar localTime = Calendar.getInstance();
    localTime.add(Calendar.MONTH, -1); // ????
    String strz = null;
    int x = localTime.get(Calendar.YEAR); // 
    int y = localTime.get(Calendar.MONTH) + 1; // 
    strz = y >= 10 ? String.valueOf(y) : ("0" + y);
    return x + "-" + strz + "-01";
}

From source file:com.bsb.cms.content.service.utils.PublishUtil.java

public static String getCtURL(String contentId) {
    Calendar date = Calendar.getInstance();
    int month = date.get(Calendar.MONTH) + 1;

    if (StringUtils.isNotBlank(contentId)) {
        return "/" + date.get(Calendar.YEAR) + "/" + (month < 10 ? ("0" + month) : month) + "/" + contentId
                + ".html";
    } else {//w w  w  .j  ava 2 s  .  c  o  m
        return "/" + date.get(Calendar.YEAR) + "/" + (month < 10 ? ("0" + month) : month) + "/";
    }

}

From source file:ch.cyberduck.core.ftp.parser.MicrosoftFTPEntryParserTest.java

@Test
public void testParse() throws Exception {
    FTPFile parsed;//from  w w  w  .  ja v a 2s.c om

    // #3701
    parsed = parser.parseFTPEntry("12-04-06  12:43PM                65335 fon1.kucuk.jpg");
    assertNotNull(parsed);
    assertEquals("fon1.kucuk.jpg", parsed.getName());
    assertEquals(FTPFile.FILE_TYPE, parsed.getType());
    assertEquals(65335, parsed.getSize());
    assertEquals(2006, parsed.getTimestamp().get(Calendar.YEAR));
    assertEquals(Calendar.DECEMBER, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(4, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
}

From source file:edu.umm.radonc.ca_dash.controllers.D3PieChartController.java

public D3PieChartController() {
    endDate = new Date();
    GregorianCalendar gc = new GregorianCalendar();
    gc.setTime(endDate);//  www  . j a  va2s . c o m
    gc.add(Calendar.MONTH, -1);
    startDate = gc.getTime();
    interval = "1m";
    this.df = new SimpleDateFormat("MM/dd/YYYY");
    this.selectedFacility = new Long(-1);
    this.dstats = new SynchronizedDescriptiveStatistics();
    this.interval = "";
    selectedFilters = new ArrayList<>();
    jsonData = new JSONArray();
}

From source file:net.seratch.taskun.util.CalendarUtil.java

 public static Calendar getCalendar(int yyyy, int mm, int dd) {
   Calendar cal = Calendar.getInstance();
   cal.set(Calendar.YEAR, yyyy);//from   w ww.jav a 2s.co m
   cal.set(Calendar.MONTH, mm - 1);
   cal.set(Calendar.DATE, dd);
   cal.set(Calendar.HOUR_OF_DAY, 0);
   cal.set(Calendar.MINUTE, 0);
   cal.set(Calendar.SECOND, 0);
   cal.set(Calendar.MILLISECOND, 0);
   return cal;
}

From source file:com.glaf.core.job.SysDataLogCreateTableJob.java

public void runJob(JobExecutionContext context) throws JobExecutionException {
    String jobName = context.getJobDetail().getKey().getName();
    logger.info("Executing job: " + jobName + " executing at " + DateUtils.getDateTime(new Date()));
    Date date = DateUtils.getDateAfter(new Date(), 0);
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);/*from ww w.j  a  v  a  2s .c  o m*/
    int year = calendar.get(Calendar.YEAR);
    int month = calendar.get(Calendar.MONTH);
    int daysOfMonth = DateUtils.getYearMonthDays(year, month + 1);

    calendar.set(year, month, daysOfMonth);

    int begin = getYearMonthDay(date);
    int end = getYearMonthDay(calendar.getTime());

    for (int i = begin; i <= end; i++) {
        try {
            SysDataLogTableUtils.createTable("SYS_DATA_LOG_" + i);
        } catch (Exception ex) {
            ex.printStackTrace();
            logger.error(ex);
        }
    }

}

From source file:com.acc.validator.CCPaymentInfoValidator.java

@Override
public void validate(final Object target, final Errors errors) {
    final CCPaymentInfoData ccPaymentData = (CCPaymentInfoData) target;

    if (StringUtils.isNotBlank(ccPaymentData.getStartMonth())
            && StringUtils.isNotBlank(ccPaymentData.getStartYear())
            && StringUtils.isNotBlank(ccPaymentData.getExpiryMonth())
            && StringUtils.isNotBlank(ccPaymentData.getExpiryYear())) {
        final Calendar start = Calendar.getInstance();
        start.set(Calendar.DAY_OF_MONTH, 0);
        start.set(Calendar.MONTH, Integer.parseInt(ccPaymentData.getStartMonth()) - 1);
        start.set(Calendar.YEAR, Integer.parseInt(ccPaymentData.getStartYear()) - 1);

        final Calendar expiration = Calendar.getInstance();
        expiration.set(Calendar.DAY_OF_MONTH, 0);
        expiration.set(Calendar.MONTH, Integer.parseInt(ccPaymentData.getExpiryMonth()) - 1);
        expiration.set(Calendar.YEAR, Integer.parseInt(ccPaymentData.getExpiryYear()) - 1);

        if (start.after(expiration)) {
            errors.rejectValue("startMonth", "payment.startDate.invalid");
        }//w ww.  j a v  a 2 s. c o  m
    }

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "accountHolderName", "field.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "cardType", "field.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "cardNumber", "field.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "expiryMonth", "field.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "expiryYear", "field.required");

    paymentAddressValidator.validate(ccPaymentData, errors);
}