List of usage examples for java.util Calendar clear
public final void clear()
Calendar
undefined. From source file:org.kuali.coeus.common.budget.impl.summary.BudgetSummaryServiceImpl.java
@Override public boolean isLeapDaysInPeriod(Date sDate, Date eDate) { Date leapDate;/*from w w w . ja v a2 s .c o m*/ int sYear = getYear(sDate); int eYear = getYear(eDate); if (isLeapYear(sDate)) { Calendar c1 = Calendar.getInstance(); c1.clear(); c1.set(sYear, 1, 29); leapDate = new java.sql.Date(c1.getTime().getTime()); // start date is before 2/29 & enddate >= 2/29 if (sDate.before(leapDate)) { if (eDate.compareTo(leapDate) >= 0) { return true; } } else if (sDate.equals(leapDate)) { return true; } } else if (isLeapYear(eDate)) { Calendar c1 = Calendar.getInstance(); c1.set(eYear, 1, 29); leapDate = new java.sql.Date(c1.getTime().getTime()); if (eDate.compareTo(leapDate) >= 0) { return true; } } else { sYear++; while (eYear > sYear) { if (isLeapYear(sYear)) { return true; } sYear++; } } return false; }
From source file:io.minio.MinioClientTest.java
@Test public void testGetObjectHeaders() throws NoSuchAlgorithmException, InvalidKeyException, IOException, XmlPullParserException, MinioException { MockWebServer server = new MockWebServer(); MockResponse response = new MockResponse(); response.setResponseCode(200);// w ww.ja v a 2 s. c o m response.setHeader("Date", "Sun, 05 Jun 2015 22:01:10 GMT"); response.setHeader(CONTENT_LENGTH, "5080"); response.setHeader(CONTENT_TYPE, APPLICATION_OCTET_STREAM); response.setHeader("ETag", "\"a670520d9d36833b3e28d1e4b73cbe22\""); response.setHeader(LAST_MODIFIED, MON_04_MAY_2015_07_58_51_GMT); server.enqueue(response); server.start(); // build expected request Calendar expectedDate = Calendar.getInstance(); expectedDate.clear(); expectedDate.setTimeZone(TimeZone.getTimeZone("GMT")); expectedDate.set(2015, Calendar.MAY, 4, 7, 58, 51); ObjectStat expectedStatInfo = new ObjectStat(BUCKET, "key", expectedDate.getTime(), 5080, "a670520d9d36833b3e28d1e4b73cbe22", APPLICATION_OCTET_STREAM); // get request MinioClient client = new MinioClient(server.url("")); ObjectStat objectStatInfo = client.statObject(BUCKET, "key"); assertEquals(expectedStatInfo, objectStatInfo); }
From source file:io.minio.MinioClientTest.java
@Test public void testSigningKey() throws NoSuchAlgorithmException, InvalidKeyException, IOException, XmlPullParserException, MinioException { MockWebServer server = new MockWebServer(); MockResponse response = new MockResponse(); response.addHeader("Date", SUN_29_JUN_2015_22_01_10_GMT); response.addHeader(CONTENT_LENGTH, "5080"); response.addHeader(CONTENT_TYPE, APPLICATION_OCTET_STREAM); response.addHeader("ETag", "\"a670520d9d36833b3e28d1e4b73cbe22\""); response.addHeader(LAST_MODIFIED, MON_04_MAY_2015_07_58_51_UTC); response.setResponseCode(200);/*from www . j a v a 2s .co m*/ server.enqueue(response); server.start(); // build expected request Calendar expectedDate = Calendar.getInstance(); expectedDate.clear(); expectedDate.setTimeZone(TimeZone.getTimeZone("UTC")); expectedDate.set(2015, Calendar.MAY, 4, 7, 58, 51); String contentType = APPLICATION_OCTET_STREAM; ObjectStat expectedStatInfo = new ObjectStat(BUCKET, "key", expectedDate.getTime(), 5080, "a670520d9d36833b3e28d1e4b73cbe22", contentType); // get request MinioClient client = new MinioClient(server.url(""), "foo", "bar"); ObjectStat objectStatInfo = client.statObject(BUCKET, "key"); assertEquals(expectedStatInfo, objectStatInfo); }
From source file:io.minio.MinioClientTest.java
@Test public void testListObjects() throws NoSuchAlgorithmException, InvalidKeyException, IOException, XmlPullParserException, MinioException { final String body = "<ListBucketResult xmlns=\"http://doc.s3.amazonaws.com/2006-03-01\"><Name>bucket</Name><Prefix></Prefix><Marker></Marker><MaxKeys>1000</MaxKeys><Delimiter></Delimiter><IsTruncated>false</IsTruncated><Contents><Key>key</Key><LastModified>2015-05-05T02:21:15.716Z</LastModified><ETag>\"5eb63bbbe01eeed093cb22bb8f5acdc3\"</ETag><Size>11</Size><StorageClass>STANDARD</StorageClass><Owner><ID>minio</ID><DisplayName>minio</DisplayName></Owner></Contents><Contents><Key>key2</Key><LastModified>2015-05-05T20:36:17.498Z</LastModified><ETag>\"2a60eaffa7a82804bdc682ce1df6c2d4\"</ETag><Size>1661</Size><StorageClass>STANDARD</StorageClass><Owner><ID>minio</ID><DisplayName>minio</DisplayName></Owner></Contents></ListBucketResult>"; MockWebServer server = new MockWebServer(); MockResponse response = new MockResponse(); response.addHeader("Date", SUN_29_JUN_2015_22_01_10_GMT); response.addHeader(CONTENT_LENGTH, "414"); response.addHeader(CONTENT_TYPE, "application/xml"); response.setBody(new Buffer().writeUtf8(body)); response.setResponseCode(200);//from w w w . jav a2s.c o m server.enqueue(response); server.start(); MinioClient client = new MinioClient(server.url("")); Iterator<Result<Item>> objectsInBucket = client.listObjects(BUCKET).iterator(); Item item = objectsInBucket.next().get(); assertEquals("key", item.objectName()); assertEquals(11, item.objectSize()); assertEquals("STANDARD", item.storageClass()); Calendar expectedDate = Calendar.getInstance(); expectedDate.clear(); expectedDate.setTimeZone(TimeZone.getTimeZone("UTC")); expectedDate.set(2015, Calendar.MAY, 5, 2, 21, 15); expectedDate.set(Calendar.MILLISECOND, 716); assertEquals(expectedDate.getTime(), item.lastModified()); Owner owner = item.owner(); assertEquals("minio", owner.id()); assertEquals("minio", owner.displayName()); }
From source file:io.minio.MinioClientTest.java
@Test public void testListBuckets() throws NoSuchAlgorithmException, InvalidKeyException, IOException, XmlPullParserException, MinioException, ParseException { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); final String body = "<ListAllMyBucketsResult xmlns=\"http://doc.s3.amazonaws.com/2006-03-01\"><Owner><ID>minio</ID><DisplayName>minio</DisplayName></Owner><Buckets><Bucket><Name>bucket</Name><CreationDate>2015-05-05T20:35:51.410Z</CreationDate></Bucket><Bucket><Name>foo</Name><CreationDate>2015-05-05T20:35:47.170Z</CreationDate></Bucket></Buckets></ListAllMyBucketsResult>"; MockWebServer server = new MockWebServer(); MockResponse response = new MockResponse(); response.addHeader("Date", SUN_29_JUN_2015_22_01_10_GMT); response.addHeader(CONTENT_LENGTH, "351"); response.addHeader(CONTENT_TYPE, "application/xml"); response.setBody(new Buffer().writeUtf8(body)); response.setResponseCode(200);//from w w w .j a v a 2 s. c o m server.enqueue(response); server.start(); MinioClient client = new MinioClient(server.url("")); Iterator<Bucket> buckets = client.listBuckets().iterator(); Bucket bucket = buckets.next(); assertEquals(BUCKET, bucket.name()); assertEquals(dateFormat.parse("2015-05-05T20:35:51.410Z"), bucket.creationDate()); bucket = buckets.next(); assertEquals("foo", bucket.name()); assertEquals(dateFormat.parse("2015-05-05T20:35:47.170Z"), bucket.creationDate()); Calendar expectedDate = Calendar.getInstance(); expectedDate.clear(); expectedDate.setTimeZone(TimeZone.getTimeZone("UTC")); expectedDate.set(2015, Calendar.MAY, 5, 20, 35, 47); expectedDate.set(Calendar.MILLISECOND, 170); assertEquals(expectedDate.getTime(), bucket.creationDate()); }
From source file:org.sakaiproject.tool.assessment.qti.util.Iso8601DateFormat.java
/** * DOCUMENTATION PENDING/*from w w w . j a v a 2 s . c om*/ * * @param iso8601String DOCUMENTATION PENDING * * @return DOCUMENTATION PENDING * * @throws Iso8601FormatException DOCUMENTATION PENDING */ public Calendar parse(String iso8601String) throws Iso8601FormatException { log.debug("parse(String " + iso8601String + ")"); if (iso8601String == null) { throw new Iso8601FormatException("illegal String iso8601TimeInterval argument: iso8601String == null"); } iso8601String = iso8601String.toUpperCase(); final Matcher matcher = PATTERN_MATCH.matcher(iso8601String); if (matcher.matches()) { if (log.isDebugEnabled()) { for (int i = 0; i <= matcher.groupCount(); i++) { log.debug(i + "=" + matcher.group(i)); } } String tz = matcher.group(7); Calendar cal = null; if ((tz != null) && (tz.length() > 0)) { if ("Z".equals(tz)) { tz = "Zulu"; } else { tz = GMT + tz; } if (log.isDebugEnabled()) { log.debug("tz=" + tz); log.debug("TimeZone.getID()=" + TimeZone.getTimeZone(tz).getID()); } cal = GregorianCalendar.getInstance(TimeZone.getTimeZone(tz)); } else { cal = GregorianCalendar.getInstance(); /* data must be zeroed out to counteract now behavior*/ cal.clear(); } /* year */ if (matcher.group(1) != null) { final int year = Integer.parseInt(matcher.group(1)); cal.set(Calendar.YEAR, year); } else { throw new Iso8601FormatException("Year is required"); } /* month */ if (matcher.group(2) != null) { final int month = Integer.parseInt(matcher.group(2)) - 1; // zero based cal.set(Calendar.MONTH, month); } /* date (day) */ if (matcher.group(3) != null) { final int date = Integer.parseInt(matcher.group(3)); cal.set(Calendar.DAY_OF_MONTH, date); } /* hour */ if (matcher.group(4) != null) { final int hour = Integer.parseInt(matcher.group(4)); cal.set(Calendar.HOUR_OF_DAY, hour); } /* minutes */ if (matcher.group(5) != null) { final int min = Integer.parseInt(matcher.group(5)); cal.set(Calendar.MINUTE, min); } /* seconds */ if (matcher.group(6) != null) { final int sec = Integer.parseInt(matcher.group(6)); cal.set(Calendar.SECOND, sec); } return cal; } throw new Iso8601FormatException("ISO8601 format could not be matched"); }
From source file:fr.paris.lutece.plugins.calendar.service.Utils.java
/** * Returns the Week as a formatted string corresponding to the date code * @return The week label/*from ww w.j a v a2s . c o m*/ * @param locale The locale used for display settings * @param strDate The date code */ public static String getWeekLabel(String strDate, Locale locale) { Calendar calendar = new GregorianCalendar(); Calendar calendarFirstDay = new GregorianCalendar(); Calendar calendarLastDay = new GregorianCalendar(); calendar.set(Utils.getYear(strDate), Utils.getMonth(strDate), Utils.getDay(strDate)); int nDayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); if (nDayOfWeek == 1) { nDayOfWeek = 8; } calendarFirstDay = calendar; calendarFirstDay.add(Calendar.DATE, Calendar.MONDAY - nDayOfWeek); calendarLastDay = (GregorianCalendar) calendarFirstDay.clone(); calendarLastDay.add(Calendar.DATE, 6); String strFormat = AppPropertiesService.getProperty(Constants.PROPERTY_LABEL_FORMAT_DATE_OF_DAY); DateFormat formatDate = new SimpleDateFormat(strFormat, locale); String strLabelFirstDay = formatDate.format(calendarFirstDay.getTime()); String strLabelLastDay = formatDate.format(calendarLastDay.getTime()); calendarFirstDay.clear(); calendarLastDay.clear(); return strLabelFirstDay + "-" + strLabelLastDay; }
From source file:com.application.utils.FastDateParser.java
@Override public Date parse(final String source, final ParsePosition pos) { final int offset = pos.getIndex(); final Matcher matcher = parsePattern.matcher(source.substring(offset)); if (!matcher.lookingAt()) { return null; }/*from www . j a v a 2 s. c om*/ // timing tests indicate getting new instance is 19% faster than cloning final Calendar cal = Calendar.getInstance(timeZone, locale); cal.clear(); for (int i = 0; i < strategies.length;) { final Strategy strategy = strategies[i++]; strategy.setCalendar(this, cal, matcher.group(i)); } pos.setIndex(offset + matcher.end()); return cal.getTime(); }
From source file:org.codice.ddf.spatial.ogc.csw.catalog.converter.TestCswRecordConverter.java
@Test public void testUnmarshalSingleCswRecordToMetacard() { XStream xstream = new XStream(new WstxDriver()); xstream.registerConverter(converter); xstream.alias("Record", MetacardImpl.class); InputStream is = TestCswRecordConverter.class.getResourceAsStream("/Csw_Record_Text.xml"); Metacard mc = (Metacard) xstream.fromXML(is); assertThat(mc, not(nullValue()));/*w ww. j a v a 2 s.com*/ assertThat((String) mc.getAttribute(CswRecordMetacardType.CSW_IDENTIFIER).getValue(), startsWith("urn:uuid:e933")); assertThat((String) mc.getAttribute(CswRecordMetacardType.CSW_SUBJECT).getValue(), equalTo("Land titles")); Date returned = (Date) mc.getAttribute(CswRecordMetacardType.CSW_DATE).getValue(); Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); cal.clear(); cal.set(2003, 4, 9); Date expected = new Date(cal.getTimeInMillis()); assertThat(returned, equalTo(expected)); assertThat(mc.getResourceURI(), is(nullValue())); }
From source file:org.exfio.csyncdroid.resource.LocalCalendar.java
protected Date dateValueToDate(DateValue dateValue) { Calendar calUtc = Calendar.getInstance(TimeZone.getTimeZone("UTC")); calUtc.clear(); calUtc.set(dateValue.year(), dateValue.month(), dateValue.day()); return calUtc.getTime(); }