List of usage examples for java.util Calendar JANUARY
int JANUARY
To view the source code for java.util Calendar JANUARY.
Click Source Link
From source file:de.blizzy.documentr.web.page.PageControllerTest.java
@Test public void getPageMustReturnNormallyIfModified() throws IOException { when(session.getAttribute("authenticationCreationTime")).thenReturn(System.currentTimeMillis()); //$NON-NLS-1$ when(request.getDateHeader("If-Modified-Since")).thenReturn( //$NON-NLS-1$ new GregorianCalendar(2000, Calendar.JANUARY, 1).getTimeInMillis()); when(request.getSession()).thenReturn(session); getPage(request);/* w w w .ja v a 2 s .c o m*/ }
From source file:net.sourceforge.openutils.mgnlcriteria.jcr.query.lucene.AclSearchIndexTest.java
/** * Tests that the execution of a query on all pets returns dogs only, because of an ACL rule. * @throws Exception/* ww w . j av a 2 s. com*/ */ @Test public void testDogsOnly() throws Exception { Context ctx = MgnlContext.getInstance(); final AccessManager wrappedAM = ctx.getAccessManager(RepositoryConstants.WEBSITE); Assert.assertNotNull(wrappedAM, "AccessManager is null"); final AccessManager wrapperAM = new AccessManager() { public boolean isGranted(String path, long permissions) { // ACL rule: deny permission on pets subtree if (StringUtils.startsWith(path, "/pets/")) { // ACL rule: read permission on dogs subtree return StringUtils.startsWith(path, "/pets/dogs/"); } return wrappedAM.isGranted(path, permissions); } public void setPermissionList(List<Permission> permissions) { wrappedAM.setPermissionList(permissions); } public List<Permission> getPermissionList() { return wrappedAM.getPermissionList(); } public long getPermissions(String path) { return wrappedAM.getPermissions(path); } }; MgnlContext.setInstance(new ContextDecorator(MgnlContext.getInstance()) { /** * {@inheritDoc} */ @Override public AccessManager getAccessManager(String name) { if (RepositoryConstants.WEBSITE.equals(name)) { return wrapperAM; } return super.getAccessManager(name); } }); try { Calendar begin = Calendar.getInstance(); begin.set(1999, Calendar.JANUARY, 1); Calendar end = Calendar.getInstance(); end.set(2001, Calendar.DECEMBER, 31); Criteria criteria = JCRCriteriaFactory.createCriteria().setWorkspace(RepositoryConstants.WEBSITE) .setBasePath("/pets").add(Restrictions.between("@birthDate", begin, end)) .addOrder(Order.asc("@birthDate")); // Query results: // --- 9 (title=Lucky, petType=bird, birthDate=1999-08-06) // --- 6 (title=George, petType=snake, birthDate=2000-01-20) // --- 4 (title=Jewel, petType=dog, birthDate=2000-03-07) // --- 11 (title=Freddy, petType=bird, birthDate=2000-03-09) // --- 12 (title=Lucky, petType=dog, birthDate=2000-06-24) // --- 1 (title=Leo, petType=cat, birthDate=2000-09-07) // --- 5 (title=Iggy, petType=lizard, birthDate=2000-11-30) // --- 3 (title=Rosy, petType=dog, birthDate=2001-04-17) AdvancedResult result = criteria.execute(); // Accessible results (dogs only): // --- 4 (title=Jewel, petType=dog, birthDate=2000-03-07) // --- 12 (title=Lucky, petType=dog, birthDate=2000-06-24) // --- 3 (title=Rosy, petType=dog, birthDate=2001-04-17) ResultIterator<? extends Node> iterator = result.getItems(); Assert.assertTrue(iterator.hasNext()); Assert.assertEquals(CriteriaTestUtils.name(iterator.next()), "4"); Assert.assertTrue(iterator.hasNext()); Assert.assertEquals(CriteriaTestUtils.name(iterator.next()), "12"); Assert.assertTrue(iterator.hasNext()); Assert.assertEquals(CriteriaTestUtils.name(iterator.next()), "3"); Assert.assertFalse(iterator.hasNext()); } finally { MgnlContext.setInstance(((ContextDecorator) MgnlContext.getInstance()).getWrappedContext()); } }
From source file:br.msf.commons.util.AbstractDateUtils.java
/** * Returns the month name for the given month index. * <p/>//from ww w.j ava 2 s . c om * Beware! its zero indexed, so JANUARY = 0, FEBRUARY = 1 and so on... * * @param month The month index. * @param locale The desired locale. * @return The month name for the given index. */ public static String monthName(final int month, final Locale locale) { if (month < Calendar.JANUARY || month > Calendar.DECEMBER) { throw new IllegalArgumentException("Month must be between [Calendar.JANUARY, Calendar.DECEMBER]."); } return (new GregorianCalendar(year(), month, 1)).getDisplayName(Calendar.MONTH, Calendar.LONG, LocaleUtils.getNullSafeLocale(locale)); }
From source file:org.techytax.util.DateHelper.java
public static Date getLastDayOfFirstMonthOfNextQuarter(Date date) { int month = getMonth(date); int year = getYear(date); Calendar cal = new GregorianCalendar(); cal.set(Calendar.YEAR, year); Date lastDay = null;//w ww .j a v a2 s . c o m switch (month) { case 0: case 1: case 2: case 3: cal.set(Calendar.MONTH, Calendar.APRIL); cal.set(Calendar.DAY_OF_MONTH, 30); lastDay = cal.getTime(); break; case 4: case 5: case 6: cal.set(Calendar.MONTH, Calendar.JULY); cal.set(Calendar.DAY_OF_MONTH, 31); lastDay = cal.getTime(); break; case 7: case 8: case 9: cal.set(Calendar.MONTH, Calendar.OCTOBER); cal.set(Calendar.DAY_OF_MONTH, 31); lastDay = cal.getTime(); break; case 10: case 11: cal.add(Calendar.YEAR, 1); cal.set(Calendar.MONTH, Calendar.JANUARY); cal.set(Calendar.DAY_OF_MONTH, 31); lastDay = cal.getTime(); break; default: break; } return lastDay; }
From source file:com.netflix.genie.core.jpa.services.JpaJobPersistenceImplIntegrationTests.java
/** * Make sure we can delete jobs that were created before a given date. *///from w w w . j ava 2 s.co m @Test public void canDeleteJobsCreatedBeforeDateWithLargeTransactionAndPageSize() { // Try to delete all jobs before Jan 1, 2016 final Calendar cal = Calendar.getInstance(JobConstants.UTC); cal.set(2016, Calendar.JANUARY, 1, 0, 0, 0); cal.set(Calendar.MILLISECOND, 0); final long deleted = this.jobPersistenceService.deleteBatchOfJobsCreatedBeforeDate(cal.getTime(), 10_000, 1); Assert.assertThat(deleted, Matchers.is(2L)); Assert.assertThat(this.jobExecutionRepository.count(), Matchers.is(1L)); Assert.assertThat(this.jobRequestRepository.count(), Matchers.is(1L)); Assert.assertThat(this.jobRequestMetadataRepository.count(), Matchers.is(1L)); Assert.assertThat(this.jobRepository.count(), Matchers.is(1L)); Assert.assertNotNull(this.jobExecutionRepository.getOne(JOB_3_ID)); Assert.assertNotNull(this.jobRequestRepository.getOne(JOB_3_ID)); Assert.assertNotNull(this.jobRequestMetadataRepository.getOne(JOB_3_ID)); Assert.assertNotNull(this.jobRepository.getOne(JOB_3_ID)); }
From source file:edu.umm.radonc.ca_dash.model.TxInstanceFacade.java
public TreeMap<Date, SynchronizedDescriptiveStatistics> getWeeklySummaryStatsAbs(Date startDate, Date endDate, Long hospitalser, String filter, boolean includeWeekends, boolean ptflag, boolean scheduledFlag) { Calendar cal = new GregorianCalendar(); TreeMap<Date, SynchronizedDescriptiveStatistics> retval = new TreeMap<>(); //SET TO BEGINNING OF WK FOR ABSOLUTE CALC cal.setTime(startDate);//from w ww. j av a2 s . c om cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); startDate = cal.getTime(); List<Object[]> events = getDailyCounts(startDate, endDate, hospitalser, filter, false, ptflag, scheduledFlag); DateFormat df = new SimpleDateFormat("MM/dd/yy"); cal.setTime(startDate); cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); int wk = cal.get(Calendar.WEEK_OF_YEAR); int mo = cal.get(Calendar.MONTH); int yr = cal.get(Calendar.YEAR); if (mo == Calendar.DECEMBER && wk == 1) { yr = yr + 1; } else if (mo == Calendar.JANUARY && wk == 52) { yr = yr - 1; } String currYrWk = yr + "-" + String.format("%02d", wk); //String prevYrWk = ""; String prevYrWk = currYrWk; SynchronizedDescriptiveStatistics currStats = new SynchronizedDescriptiveStatistics(); int i = 0; while (cal.getTime().before(endDate) && i < events.size()) { Object[] event = events.get(i); Date d = (Date) event[0]; Long count = (Long) event[1]; cal.setTime(d); cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); wk = cal.get(Calendar.WEEK_OF_YEAR); mo = cal.get(Calendar.MONTH); yr = cal.get(Calendar.YEAR); if (mo == Calendar.DECEMBER && wk == 1) { yr = yr + 1; } else if (mo == Calendar.JANUARY && wk == 52) { yr = yr - 1; } currYrWk = yr + "-" + String.format("%02d", wk); if (!(prevYrWk.equals(currYrWk))) { GregorianCalendar lastMon = new GregorianCalendar(); lastMon.setTime(cal.getTime()); lastMon.add(Calendar.DATE, -7); retval.put(lastMon.getTime(), currStats); currStats = new SynchronizedDescriptiveStatistics(); } prevYrWk = currYrWk; currStats.addValue(count); i++; } retval.put(cal.getTime(), currStats); return retval; }
From source file:agency.AgentManagerImplTest.java
@Test public void testUpdateAgentValidName() { //create agents Agent agent = newAgent01();// w w w .ja v a 2s . c om Agent agent02 = newAgent02(); manager.createAgent(agent); manager.createAgent(agent02); Agent reference = manager.findAgentById(agent.getId()); assertNotNull("Agent has not been added to the DB", reference); reference.setName("Hawkeye"); manager.updateAgent(reference); assertEquals("Error update of agent name", "Hawkeye", reference.getName()); assertEquals("Error in born attribute while updating agent's name", new GregorianCalendar(1980, Calendar.JANUARY, 1).getTime(), reference.getBorn()); assertEquals("Error in level attribute while updating agent's name", 5, reference.getLevel()); assertEquals("Error in note attribute while updating agent's name", "Best agent ever", reference.getNote()); // Check if updates didn't affect other records assertDeepEquals(agent02, manager.findAgentById(agent02.getId())); }
From source file:com.datamountaineer.streamreactor.connect.json.SimpleJsonConverterTest.java
@Test public void dateToJson() throws IOException { GregorianCalendar calendar = new GregorianCalendar(1970, Calendar.JANUARY, 1, 0, 0, 0); calendar.setTimeZone(TimeZone.getTimeZone("UTC")); calendar.add(Calendar.DATE, 10000); java.util.Date date = calendar.getTime(); JsonNode converted = converter.fromConnectData(Date.SCHEMA, date); assertTrue(converted.isTextual());/*www.j a v a 2 s.co m*/ assertEquals(SimpleJsonConverter.ISO_DATE_FORMAT.format(date), converted.textValue()); }
From source file:connect.app.com.connect.calendar.DayPickerView.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) public DayPickerView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); mAccessibilityManager = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE); // final TypedArray a = context.obtainStyledAttributes(attrs, // R.styleable.CalendarView, defStyleAttr, defStyleRes); //// w ww . jav a2s . c o m // final int firstDayOfWeek = a.getInt(R.styleable.CalendarView_firstDayOfWeek, // LocaleData.get(Locale.getDefault()).firstDayOfWeek); final int firstDayOfWeek = 1; // // final String minDate = a.getString(R.styleable.CalendarView_minDate); final String minDate = null; // final String maxDate = a.getString(R.styleable.CalendarView_maxDate); final String maxDate = null; // // final int monthTextAppearanceResId = a.getResourceId( // R.styleable.CalendarView_monthTextAppearance, // R.style.TextAppearance_Material_Widget_Calendar_Month); // final int dayOfWeekTextAppearanceResId = a.getResourceId( // R.styleable.CalendarView_weekDayTextAppearance, // R.style.TextAppearance_Material_Widget_Calendar_DayOfWeek); // final int dayTextAppearanceResId = a.getResourceId( // R.styleable.CalendarView_dateTextAppearance, // R.style.TextAppearance_Material_Widget_Calendar_Day); // // final ColorStateList daySelectorColor = a.getColorStateList( // R.styleable.CalendarView_daySelectorColor); // // a.recycle(); // Set up adapter. mAdapter = new DayPickerPagerAdapter(context, R.layout.layout_test, com.retrofit.R.id.scrollView); // mAdapter.setMonthTextAppearance(monthTextAppearanceResId); // mAdapter.setDayOfWeekTextAppearance(dayOfWeekTextAppearanceResId); // mAdapter.setDayTextAppearance(dayTextAppearanceResId); // mAdapter.setDaySelectorColor(daySelectorColor); final LayoutInflater inflater = LayoutInflater.from(context); final ViewGroup content = (ViewGroup) inflater.inflate(DEFAULT_LAYOUT, this, false); // Transfer all children from content to here. while (content.getChildCount() > 0) { final View child = content.getChildAt(0); content.removeViewAt(0); addView(child); } mPrevButton = (ImageButton) findViewById(R.id.prev); mPrevButton.setOnClickListener(mOnClickListener); mNextButton = (ImageButton) findViewById(R.id.next); mNextButton.setOnClickListener(mOnClickListener); mViewPager = (ViewPager) findViewById(R.id.day_picker_view_pager); mViewPager.setAdapter(mAdapter); mViewPager.setOnPageChangeListener(mOnPageChangedListener); // Proxy the month text color into the previous and next buttons. // if (monthTextAppearanceResId != 0) { // final TypedArray ta = mContext.obtainStyledAttributes(null, // ATTRS_TEXT_COLOR, 0, monthTextAppearanceResId); // final ColorStateList monthColor = ta.getColorStateList(0); // if (monthColor != null) { // mPrevButton.setImageTintList(monthColor); // mNextButton.setImageTintList(monthColor); // } // ta.recycle(); // } // Set up min and max dates. final Calendar tempDate = Calendar.getInstance(); if (!CalendarView.parseDate(minDate, tempDate)) { tempDate.set(DEFAULT_START_YEAR, Calendar.JANUARY, 1); } final long minDateMillis = tempDate.getTimeInMillis(); if (!CalendarView.parseDate(maxDate, tempDate)) { tempDate.set(DEFAULT_END_YEAR, Calendar.DECEMBER, 31); } final long maxDateMillis = tempDate.getTimeInMillis(); if (maxDateMillis < minDateMillis) { throw new IllegalArgumentException("maxDate must be >= minDate"); } final long setDateMillis = MathUtils.constrain(System.currentTimeMillis(), minDateMillis, maxDateMillis); setFirstDayOfWeek(firstDayOfWeek); setMinDate(minDateMillis); setMaxDate(maxDateMillis); setDate(setDateMillis, false); // Proxy selection callbacks to our own listener. mAdapter.setOnDaySelectedListener(new DayPickerPagerAdapter.OnDaySelectedListener() { @Override public void onDaySelected(DayPickerPagerAdapter adapter, Calendar day) { if (mOnDaySelectedListener != null) { mOnDaySelectedListener.onDaySelected(DayPickerView.this, day); } } }); }
From source file:org.apache.solr.handler.component.RuleManagerComponent.java
/** * Initialize the season mappings configuration used during replacements of the * $SEASON token in rule base categories & ranking rule boost expressions. * * The season mapping string should have this format: * * expressionA:1,2,3,4,5,6;expressionB:7,8,9,10,11,12 * * where 1,2,3,4 are the months of the year (starting at 1=january) * * If there are missing months in the mapping, then they will be default to the following expression: * * * @param seasonMapping The season mapping parameter specified by the user in this component definition in solrconfig *///w w w.j a v a2 s .c o m protected void initSeasonMappings(String seasonMapping) { for (int i = Calendar.JANUARY; i <= Calendar.DECEMBER; i++) { seasonMapper[i] = DEFAULT_SEASON_MAPPER; } if (seasonMapping != null) { logger.info("Initializing season mapping: [" + seasonMapping + "]"); String[] expressions = seasonMapping.split(";"); if (expressions != null) { for (String expression : expressions) { String[] entry = expression.split(":"); if (entry.length != 2) { logger.error("Invalid season mapping expression: [" + expression + "]. Correct format: [expression:1,2,3,4;] where 1,2,3,4 are the months of the year"); } else { String value = entry[0]; String[] months = entry[1].split(","); for (int i = 0; i < months.length; i++) { seasonMapper[Integer.parseInt(months[i]) - 1] = value; } } } } else { logger.error( "Please provide a valid season mapping configuration parameter. Valid format: [expressionA:1,2,3,4,5,6;expressionB:7,8,9,10,11,12]"); } } }