Java Code Examples for org.joda.time.DateTime#getDayOfYear()

The following examples show how to use org.joda.time.DateTime#getDayOfYear() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DateCalculator.java    From AsuraFramework with Apache License 2.0 6 votes vote down vote up
/**
 * 是否同一天 年月日是否一致
 *
 * @param date1
 * @param date2
 * @return
 */
public static boolean isTheSameDay(@Nullable Date date1,@Nullable Date date2) {
    if(Check.isNullObjects(date1,date2)){
        return false;
    }
    DateTime dateTime1 = new DateTime(date1);
    DateTime dateTime2 = new DateTime(date2);
    //年份是否一样
    if (dateTime1.getYear() != dateTime2.getYear()) {
        return false;
    }
    //日期是否一样
    if (dateTime1.getDayOfYear() != dateTime2.getDayOfYear()) {
        return false;
    }
    return true;
}
 
Example 2
Source File: SpanRepository.java    From cicada with MIT License 6 votes vote down vote up
/**
 * <p>
 * 根据起始时间和结束时间,获取包含这个时间段的目标index 如果起始时间和结束时间在同一天,返回这一天的索引名称 span_$date.
 * 如果起始时间和结束时间不在同一天,返回全部索引的通配符表达式 span_*.
 * </p>
 */
private String getIndice(final DateTime beginTime, final DateTime endTime) {
  final int beginDay = beginTime.getDayOfYear();
  final int endDay = endTime.getDayOfYear();

  String indexName;
  if (beginDay == endDay) {
    final String dateStr = endTime.toString(DateTimeFormats.FULL_DATE_ENGLISH);
    indexName = props.getEsSpanIndexPrefix() + INDEX_CAT_CHARS + dateStr;
    if (!exists(indexName)) {
      indexName = null;
    }
  } else {
    indexName = getDefaultIndice();
  }

  return indexName;
}
 
Example 3
Source File: DayOfYearFunction.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Override
public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
    Expression arg = getChildren().get(0);
    if (!arg.evaluate(tuple,ptr)) {
        return false;
    }
    if (ptr.getLength() == 0) {
        return true;
    }
    long dateTime = inputCodec.decodeLong(ptr, arg.getSortOrder());
    DateTime jodaDT = new DateTime(dateTime);
    int day = jodaDT.getDayOfYear();
    PDataType returnDataType = getDataType();
    byte[] byteValue = new byte[returnDataType.getByteSize()];
    returnDataType.getCodec().encodeInt(day, byteValue, 0);
    ptr.set(byteValue);
    return true;
}
 
Example 4
Source File: CommitListPanel.java    From onedev with MIT License 5 votes vote down vote up
private List<RevCommit> separateByDate(List<RevCommit> commits) {
	List<RevCommit> separated = new ArrayList<>();
	DateTime groupTime = null;
	for (RevCommit commit: commits) {
		DateTime commitTime = new DateTime(commit.getCommitterIdent().getWhen());
		if (groupTime == null || commitTime.getYear() != groupTime.getYear() 
				|| commitTime.getDayOfYear() != groupTime.getDayOfYear()) {
			groupTime = commitTime;
			separated.add(null);
		} 
		separated.add(commit);
	}
	return separated;
}
 
Example 5
Source File: GanttDiagram.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void generateYearsViewMonthsViewAndDays() {

        DateTime firstMonthDateTime = getFirstInstant();
        DateTime lastMontDateTime = getLastInstant();

        if (firstMonthDateTime != null && lastMontDateTime != null) {
            while ((firstMonthDateTime.getYear() < lastMontDateTime.getYear())
                    || (firstMonthDateTime.getYear() == lastMontDateTime.getYear() && firstMonthDateTime.getDayOfYear() <= lastMontDateTime
                            .getDayOfYear())) {

                getDays().add(firstMonthDateTime);

                YearMonthDay day = firstMonthDateTime.toYearMonthDay().withDayOfMonth(1);
                if (getMonthsView().containsKey(day)) {
                    getMonthsView().put(day, getMonthsView().get(day) + 1);
                } else {
                    getMonthsView().put(day, 1);
                }

                if (getYearsView().containsKey(Integer.valueOf(firstMonthDateTime.getYear()))) {
                    getYearsView().put(Integer.valueOf(firstMonthDateTime.getYear()),
                            getYearsView().get(Integer.valueOf(firstMonthDateTime.getYear())) + 1);
                } else {
                    getYearsView().put(Integer.valueOf(firstMonthDateTime.getYear()), 1);
                }

                firstMonthDateTime = firstMonthDateTime.plusDays(1);
            }
        }
    }
 
Example 6
Source File: DateHelper.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param d1
 * @param d2
 * @return True if the dates are both null or both represents the same day (year, month, day) independant of the hours, minutes etc.
 * @see DateHolder#isSameDay(Date)
 */
public static boolean isSameDay(final DateTime d1, final DateTime d2)
{
  if (d1 == null) {
    if (d2 == null) {
      return true;
    } else {
      return false;
    }
  } else if (d2 == null) {
    return false;
  }
  return d1.getYear() == d2.getYear() && d1.getDayOfYear() == d2.getDayOfYear();
}
 
Example 7
Source File: DateTimeBrowser.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
Object[][] genCalcdValues() {
    Object[][] retValues = null;
    /*
     * Create an array of Objects that will contain
     * other arrays of Objects. (This is the 'column'
     * array).
     */
    ArrayList fileStrings = lddFile.getFileStrings();
    ArrayList dtObjects = lddFile.getDtObjects();
    int numRows = fileStrings.size();
    retValues = new Object[numRows][];
    int numCols = colNames.length;
    // System.err.println("NumCols : " + numCols);
    /*
     * Prime the array of arrays of Objects, allocating a new
     * secondary array for each of the primary array's
     * elements.
     */
    for (int nextStrNum = 0; nextStrNum < fileStrings.size(); ++ nextStrNum) {
        retValues[nextStrNum] = new Object[numCols]; // get the 'col' array
        //****
        //* This needs to be sync'd with the colNames array.
        //****
        // Current row, 1st column
        int column = 0; // working row value
        String fileString = (String)fileStrings.get(nextStrNum);
        retValues[nextStrNum][column++] = fileString;
        // Current row, 2nd column
        DateTime adt = (DateTime)dtObjects.get(nextStrNum);
        String adtStr = adt.toString();
        retValues[nextStrNum][column++] = adtStr;
        // Current row, other columns.
        // Order here must match that specified in the colNames
        // array.
        retValues[nextStrNum][column++]  = new Integer( adt.getMillisOfSecond() );
        retValues[nextStrNum][column++]  = new Integer( adt.getSecondOfMinute() );
        retValues[nextStrNum][column++]  = new Integer( adt.getMinuteOfHour() );
        retValues[nextStrNum][column++]  = new Integer( adt.getHourOfDay() );
        retValues[nextStrNum][column++]  = new Integer( adt.getDayOfWeek() );
        retValues[nextStrNum][column++]  = new Integer( adt.getDayOfMonth() );
        retValues[nextStrNum][column++]  = new Integer( adt.getDayOfYear() );
        retValues[nextStrNum][column++]  = new Integer( adt.getWeekOfWeekyear() );
        retValues[nextStrNum][column++] = new Integer( adt.getWeekyear() );
        retValues[nextStrNum][column++] = new Integer( adt.getMonthOfYear() );
        retValues[nextStrNum][column++] = new Integer( adt.getYear() );
        //
    } // the for
    if ( debugf ) dumpObjs( retValues, System.err );
    return retValues;
}
 
Example 8
Source File: DateTimeBrowser.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
Object[][] genCalcdValues() {
    Object[][] retValues = null;
    /*
     * Create an array of Objects that will contain
     * other arrays of Objects. (This is the 'column'
     * array).
     */
    ArrayList fileStrings = lddFile.getFileStrings();
    ArrayList dtObjects = lddFile.getDtObjects();
    int numRows = fileStrings.size();
    retValues = new Object[numRows][];
    int numCols = colNames.length;
    // System.err.println("NumCols : " + numCols);
    /*
     * Prime the array of arrays of Objects, allocating a new
     * secondary array for each of the primary array's
     * elements.
     */
    for (int nextStrNum = 0; nextStrNum < fileStrings.size(); ++ nextStrNum) {
        retValues[nextStrNum] = new Object[numCols]; // get the 'col' array
        //****
        //* This needs to be sync'd with the colNames array.
        //****
        // Current row, 1st column
        int column = 0; // working row value
        String fileString = (String)fileStrings.get(nextStrNum);
        retValues[nextStrNum][column++] = fileString;
        // Current row, 2nd column
        DateTime adt = (DateTime)dtObjects.get(nextStrNum);
        String adtStr = adt.toString();
        retValues[nextStrNum][column++] = adtStr;
        // Current row, other columns.
        // Order here must match that specified in the colNames
        // array.
        retValues[nextStrNum][column++]  = new Integer( adt.getMillisOfSecond() );
        retValues[nextStrNum][column++]  = new Integer( adt.getSecondOfMinute() );
        retValues[nextStrNum][column++]  = new Integer( adt.getMinuteOfHour() );
        retValues[nextStrNum][column++]  = new Integer( adt.getHourOfDay() );
        retValues[nextStrNum][column++]  = new Integer( adt.getDayOfWeek() );
        retValues[nextStrNum][column++]  = new Integer( adt.getDayOfMonth() );
        retValues[nextStrNum][column++]  = new Integer( adt.getDayOfYear() );
        retValues[nextStrNum][column++]  = new Integer( adt.getWeekOfWeekyear() );
        retValues[nextStrNum][column++] = new Integer( adt.getWeekyear() );
        retValues[nextStrNum][column++] = new Integer( adt.getMonthOfYear() );
        retValues[nextStrNum][column++] = new Integer( adt.getYear() );
        //
    } // the for
    if ( debugf ) dumpObjs( retValues, System.err );
    return retValues;
}
 
Example 9
Source File: OmsInsolation.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
@Execute
public void process() throws Exception { // transform the
    checkNull(inElev, tStartDate, tEndDate);
    // extract some attributes of the map
    HashMap<String, Double> attribute = CoverageUtilities.getRegionParamsFromGridCoverage(inElev);
    double dx = attribute.get(CoverageUtilities.XRES);

    /*
     * The models use only one value of the latitude. So I have decided to
     * set it to the center of the raster. Extract the CRS of the
     * GridCoverage and transform the value of a WGS84 latitude.
     */
    CoordinateReferenceSystem sourceCRS = inElev.getCoordinateReferenceSystem2D();
    CoordinateReferenceSystem targetCRS = DefaultGeographicCRS.WGS84;

    double srcPts[] = new double[]{attribute.get(CoverageUtilities.EAST), attribute.get(CoverageUtilities.SOUTH)};

    Coordinate source = new Coordinate(srcPts[0], srcPts[1]);
    Point[] so = new Point[]{GeometryUtilities.gf().createPoint(source)};
    CrsUtilities.reproject(sourceCRS, targetCRS, so);
    // the latitude value
    lambda = Math.toRadians(so[0].getY());

    /*
     * transform the start and end date in an int value (the day in the
     * year, from 1 to 365)
     */
    DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd").withZone(DateTimeZone.UTC);
    DateTime currentDatetime = formatter.parseDateTime(tStartDate);
    int startDay = currentDatetime.getDayOfYear();
    currentDatetime = formatter.parseDateTime(tEndDate);
    int endDay = currentDatetime.getDayOfYear();
    CoverageUtilities.getRegionParamsFromGridCoverage(inElev);
    RenderedImage pitTmpRI = inElev.getRenderedImage();
    int width = pitTmpRI.getWidth();
    int height = pitTmpRI.getHeight();
    WritableRaster pitWR = CoverageUtilities.replaceNovalue(pitTmpRI, -9999.0);
    pitTmpRI = null;

    WritableRaster insolationWR = CoverageUtilities.createWritableRaster(width, height, null, pitWR.getSampleModel(),
            0.0);
    WritableRandomIter insolationIterator = RandomIterFactory.createWritable(insolationWR, null);

    WritableRaster gradientWR = normalVector(pitWR, dx);

    pm.beginTask(msg.message("insolation.calculating"), endDay - startDay);

    for( int i = startDay; i <= endDay; i++ ) {
        calcInsolation(lambda, pitWR, gradientWR, insolationWR, i, dx);
        pm.worked(i - startDay);
    }
    pm.done();
    for( int y = 2; y < height - 2; y++ ) {
        for( int x = 2; x < width - 2; x++ ) {
            if (HMConstants.isNovalue(pitWR.getSampleDouble(x, y, 0))) {
                insolationIterator.setSample(x, y, 0, HMConstants.doubleNovalue);

            }
        }
    }

    outIns = CoverageUtilities.buildCoverage("insolation", insolationWR, attribute, inElev.getCoordinateReferenceSystem());
}