List of usage examples for java.util Calendar DAY_OF_YEAR
int DAY_OF_YEAR
To view the source code for java.util Calendar DAY_OF_YEAR.
Click Source Link
get
and set
indicating the day number within the current year. From source file:ezbake.data.elastic.test.TestUtils.java
public static Facet generateDateBucketFacet() { final SimpleDateFormat dtg = new SimpleDateFormat("ddHHmm'Z' MM yy"); final Calendar calendar = new GregorianCalendar(); final Facet ssrDateFacet = new Facet(); final RangeFacet dateRangeFacet = new RangeFacet(); final BaseFacetValue dateField = new BaseFacetValue(); dateField.setFacetField("visit"); dateRangeFacet.setField(dateField);//from www . j av a 2 s . co m final FacetRange last24 = new FacetRange(RangeType.DATE); calendar.add(Calendar.DAY_OF_YEAR, -1); last24time = DateUtils.round(calendar, Calendar.HOUR).getTimeInMillis(); last24.setFrom(dtg.format(last24time)); dateRangeFacet.addToRanges(last24); final FacetRange last48 = new FacetRange(RangeType.DATE); calendar.add(Calendar.DAY_OF_YEAR, -1); last48time = DateUtils.round(calendar, Calendar.HOUR).getTimeInMillis(); last48.setFrom(dtg.format(last48time)); dateRangeFacet.addToRanges(last48); final FacetRange last72 = new FacetRange(RangeType.DATE); calendar.add(Calendar.DAY_OF_YEAR, -1); last72time = DateUtils.round(calendar, Calendar.HOUR).getTimeInMillis(); last72.setFrom(dtg.format(last72time)); dateRangeFacet.addToRanges(last72); final FacetRange lastWeek = new FacetRange(RangeType.DATE); calendar.add(Calendar.DAY_OF_YEAR, -4); lastWeekTime = DateUtils.round(calendar, Calendar.HOUR).getTimeInMillis(); lastWeek.setFrom(dtg.format(lastWeekTime)); dateRangeFacet.addToRanges(lastWeek); final FacetRange last30Days = new FacetRange(RangeType.DATE); calendar.add(Calendar.DAY_OF_YEAR, -23); last30DaysTime = DateUtils.round(calendar, Calendar.HOUR).getTimeInMillis(); last30Days.setFrom(dtg.format(last30DaysTime)); dateRangeFacet.addToRanges(last30Days); final FacetRange last90Days = new FacetRange(RangeType.DATE); calendar.add(Calendar.DAY_OF_YEAR, -60); last90DaysTime = DateUtils.round(calendar, Calendar.HOUR).getTimeInMillis(); last90Days.setFrom(dtg.format(last90DaysTime)); dateRangeFacet.addToRanges(last90Days); final FacetRange lastYear = new FacetRange(RangeType.DATE); calendar.add(Calendar.DAY_OF_YEAR, -275); lastYearTime = DateUtils.round(calendar, Calendar.HOUR).getTimeInMillis(); lastYear.setFrom(dtg.format(lastYearTime)); dateRangeFacet.addToRanges(lastYear); final FacetRequest dateRequest = new FacetRequest(); dateRequest.setRangeFacet(dateRangeFacet); ssrDateFacet.setLabel("Report Date"); ssrDateFacet.setFacet(dateRequest); return ssrDateFacet; }
From source file:com.intuit.tank.harness.functions.DateFunctions.java
/** * Get the date x days from now.// w w w . ja v a 2 s . co m * * e.g. #function.date.addDays.1.MM-dd-yyyy * * @param days * The number of days to add (negative number to remove) * @param format * The format of the response (MM-dd-yyyy, MMddyyyy, etc) * @return The new date */ private static String addDays(int days, @Nullable String format) { Calendar now = Calendar.getInstance(); now.add(Calendar.DAY_OF_YEAR, days); DateFormat formatter = getFormatter(format); return formatter.format(now.getTime()); }
From source file:Main.java
/** * Checks if two calendar objects are on the same day ignoring time. * * 28 Mar 2002 13:45 and 28 Mar 2002 06:01 would return true. * 28 Mar 2002 13:45 and 12 Mar 2002 13:45 would return false. * /* w w w .j a va 2 s . co m*/ * * @param cal1 the first calendar, not altered, not null * @param cal2 the second calendar, not altered, not null * @return true if they represent the same day * @throws IllegalArgumentException if either calendar is <code>null</code> * @since 2.1 */ public static boolean isSameDay(Calendar cal1, Calendar cal2) { if (cal1 == null || cal2 == null) { throw new IllegalArgumentException("The date must not be null"); } return (cal1.get(Calendar.ERA) == cal2.get(Calendar.ERA) && cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) && cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR)); }
From source file:py.una.pol.karaku.dao.entity.interceptors.TimeInterceptor.java
/** * @param c */ private void handleTime(Calendar c) { c.set(Calendar.YEAR, FIRST_YEAR); c.set(Calendar.DAY_OF_YEAR, FIRST_DAY_OF_YEAR); }
From source file:com.autodomum.daylight.algorithm.DaylightAlgorithm.java
@Override public Date sunrise(final Coordinate coordinate, final Date date) { final Calendar calendar = GregorianCalendar.getInstance(); calendar.setTime(date);/*from w ww.ja va 2 s. c o m*/ final int day = calendar.get(Calendar.DAY_OF_YEAR); final double total = length(coordinate.getLatitude(), day); final int hours = (int) total; final int minutes = (int) ((((double) total) - ((double) hours)) * 60d); calendar.set(Calendar.HOUR_OF_DAY, 12); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); calendar.add(Calendar.HOUR_OF_DAY, -hours / 2); calendar.add(Calendar.MINUTE, -minutes / 2); calendar.add(Calendar.MINUTE, (int) localSolarTime(day)); final TimeZone timeZone = TimeZone.getDefault(); if (timeZone.inDaylightTime(date)) { calendar.add(Calendar.MILLISECOND, timeZone.getDSTSavings()); } return calendar.getTime(); }
From source file:MonthPanel.java
protected JPanel createDaysGUI() { JPanel dayPanel = new JPanel(true); dayPanel.setLayout(new GridLayout(0, dayNames.length)); Calendar today = Calendar.getInstance(); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.MONTH, month); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.DAY_OF_MONTH, 1); Calendar iterator = (Calendar) calendar.clone(); iterator.add(Calendar.DAY_OF_MONTH, -(iterator.get(Calendar.DAY_OF_WEEK) - 1)); Calendar maximum = (Calendar) calendar.clone(); maximum.add(Calendar.MONTH, +1); for (int i = 0; i < dayNames.length; i++) { JPanel dPanel = new JPanel(true); dPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); JLabel dLabel = new JLabel(dayNames[i]); dPanel.add(dLabel);/* w w w .ja va2 s . c om*/ dayPanel.add(dPanel); } int count = 0; int limit = dayNames.length * 6; while (iterator.getTimeInMillis() < maximum.getTimeInMillis()) { int lMonth = iterator.get(Calendar.MONTH); int lYear = iterator.get(Calendar.YEAR); JPanel dPanel = new JPanel(true); dPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); JLabel dayLabel = new JLabel(); if ((lMonth == month) && (lYear == year)) { int lDay = iterator.get(Calendar.DAY_OF_MONTH); dayLabel.setText(Integer.toString(lDay)); } dPanel.add(dayLabel); dayPanel.add(dPanel); iterator.add(Calendar.DAY_OF_YEAR, +1); count++; } for (int i = count; i < limit; i++) { JPanel dPanel = new JPanel(true); dPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); dPanel.add(new JLabel()); dayPanel.add(dPanel); } return dayPanel; }
From source file:de.micromata.genome.util.types.DateUtils.java
/** * Arbeitet ber die Millisekunden./*from ww w .j a v a2s .com*/ * * @param date Nie <code>null</code>. * @param days Positive und negative Zahlen erlaubt. * @return Das neue Datum. */ public static Date addDays(final Date date, final int days) { Validate.notNull(date, "date not set"); final Calendar cal = getCalendarInstance(); cal.setTime(date); cal.add(Calendar.DAY_OF_YEAR, days); final Date result = cal.getTime(); return result; }
From source file:fr.gael.dhus.datastore.eviction.EvictionManager.java
/** * Computes the date <i>days</i> days ago. * * @param days number of days// w w w.j av a 2 s . c o m * @return a date representation of date <i>days</i> ago. */ public Date getKeepPeriod(int days) { Calendar cal = Calendar.getInstance(); cal.add(Calendar.DAY_OF_YEAR, -days); logger.info("Eviction Max date : " + cal.getTime()); return cal.getTime(); }
From source file:com.netflix.genie.web.tasks.job.JobMonitorUnitTests.java
/** * Setup for the tests.// ww w.j a va 2 s . co m */ @Before public void setup() { final Calendar tomorrow = Calendar.getInstance(JobConstants.UTC); tomorrow.add(Calendar.DAY_OF_YEAR, 1); this.jobExecution = new JobExecution.Builder(UUID.randomUUID().toString()).withProcessId(3808) .withCheckDelay(DELAY).withTimeout(tomorrow.getTime()).withId(UUID.randomUUID().toString()).build(); this.executor = Mockito.mock(Executor.class); this.publisher = Mockito.mock(ApplicationEventPublisher.class); this.eventMulticaster = Mockito.mock(ApplicationEventMulticaster.class); this.successfulCheckRate = Mockito.mock(Counter.class); this.timeoutRate = Mockito.mock(Counter.class); this.finishedRate = Mockito.mock(Counter.class); this.unsuccessfulCheckRate = Mockito.mock(Counter.class); this.stdOutTooLarge = Mockito.mock(Counter.class); this.stdErrTooLarge = Mockito.mock(Counter.class); this.registry = Mockito.mock(Registry.class); this.stdOut = Mockito.mock(File.class); this.stdErr = Mockito.mock(File.class); Mockito.when(this.registry.counter("genie.jobs.successfulStatusCheck.rate")) .thenReturn(this.successfulCheckRate); Mockito.when(this.registry.counter("genie.jobs.timeout.rate")).thenReturn(this.timeoutRate); Mockito.when(this.registry.counter("genie.jobs.finished.rate")).thenReturn(this.finishedRate); Mockito.when(this.registry.counter("genie.jobs.unsuccessfulStatusCheck.rate")) .thenReturn(this.unsuccessfulCheckRate); Mockito.when(this.registry.counter("genie.jobs.stdOutTooLarge.rate")).thenReturn(this.stdOutTooLarge); Mockito.when(this.registry.counter("genie.jobs.stdErrTooLarge.rate")).thenReturn(this.stdErrTooLarge); final JobsProperties outputMaxProperties = new JobsProperties(); outputMaxProperties.getMax().setStdOutSize(MAX_STD_OUT_LENGTH); outputMaxProperties.getMax().setStdErrSize(MAX_STD_ERR_LENGTH); this.monitor = new JobMonitor(this.jobExecution, this.stdOut, this.stdErr, this.executor, this.publisher, this.eventMulticaster, this.registry, outputMaxProperties); }
From source file:net.chrisrichardson.foodToGo.domain.hibernate.HibernateOrderRepositoryImplTests.java
private void insertTestData() throws HibernateException { doWithTransaction(new TxnCallback() { public void execute() throws Throwable { delete(OrderLineItem.class); delete(Order.class); Calendar c = Calendar.getInstance(); Date order2Time = c.getTime(); c.add(Calendar.DAY_OF_YEAR, -30); Date order1Time = c.getTime(); Order o1 = OrderMother.makeOrder(order1Time); Order o2 = OrderMother.makeOrder(order2Time); save(o1.getRestaurant());/* w w w . j av a2s. c o m*/ save(o2.getRestaurant()); save(o1); save(o2); orderId1 = o1.getId(); orderId2 = o2.getId(); } }); }