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

The following examples show how to use org.joda.time.DateTime#getWeekOfWeekyear() . 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: WeekFunction.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Override
public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
    Expression expression = getChildExpression();
    if (!expression.evaluate(tuple, ptr)) {
        return false;
    }
    if ( ptr.getLength() == 0) {
        return true; //means null
    }
    long dateTime = inputCodec.decodeLong(ptr, expression.getSortOrder());
    DateTime dt = new DateTime(dateTime);
    int week = dt.getWeekOfWeekyear();
    PDataType returnType = getDataType();
    byte[] byteValue = new byte[returnType.getByteSize()];
    returnType.getCodec().encodeInt(week, byteValue, 0);
    ptr.set(byteValue);
    return true;
}
 
Example 2
Source File: DateTimeFunctions.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Returns the week number of a given date.
 */
@Function("WEEKNUM")
@FunctionParameters({
	@FunctionParameter("dateObj")})
public Integer WEEKNUM(Object dateObj){
	Date date = convertDateObject(dateObj);
	if(date==null){
		logCannotConvertToDate();
		return null;
	}
	else{
		DateTime dt=new DateTime(date);
		return dt.getWeekOfWeekyear();
	}
}
 
Example 3
Source File: PersianCalendar.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public int isoWeek( DateTimeUnit dateTimeUnit )
{
    DateTime dateTime = toIso( dateTimeUnit )
        .toJodaDateTime( ISOChronology.getInstance( DateTimeZone.getDefault() ) );
    return dateTime.getWeekOfWeekyear();
}
 
Example 4
Source File: Date.java    From foxtrot with Apache License 2.0 5 votes vote down vote up
public Date(DateTime dateTime) {

        this.year = dateTime.getYear();
        this.monthOfYear = dateTime.getMonthOfYear();
        this.dayOfWeek = dateTime.getDayOfWeek();
        this.dayOfMonth = dateTime.getDayOfMonth();
        this.hourOfDay = dateTime.getHourOfDay();
        this.minuteOfHour = dateTime.getMinuteOfHour();
        this.minuteOfDay = dateTime.getMinuteOfDay();
        this.weekOfYear = dateTime.getWeekOfWeekyear();
    }
 
Example 5
Source File: ChronologyBasedCalendar.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public int isoWeek( DateTimeUnit dateTimeUnit )
{
    DateTime dateTime = dateTimeUnit.toJodaDateTime( chronology );
    return dateTime.getWeekOfWeekyear();
}
 
Example 6
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 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: FakeIdRangeTest.java    From Rhombus with MIT License 4 votes vote down vote up
@Test
public void getIteratorTestWeekly() throws RhombusException {
	Long millistamp = 946740000000L;
	millistamp = System.currentTimeMillis();
	System.out.println(millistamp);
	UUID startingUUID = UUIDs.startOf(millistamp);
	System.out.println("UUID of start is "+startingUUID+" (DATE= "+UuidUtil.getDateFromUUID(startingUUID)+" )");


	TimebasedShardingStrategy shardingStrategy = new ShardingStrategyWeekly();
	int numberPerShard = 3;
	long totalNumberOfObjects = 950L;
	FakeIdRange subject = new FakeIdRange(CField.CDataType.TIMEUUID,startingUUID,totalNumberOfObjects,(long)numberPerShard, shardingStrategy, "testing");
	Iterator<FakeIdRange.IdInRange> it = subject.getIterator(CObjectOrdering.ASCENDING);

	long counter = 0;
	int lastweek = -1;
	int countSinceChange = 0;
	while(it.hasNext()){
		counter++;
		FakeIdRange.IdInRange id = it.next();
		DateTime dt = UuidUtil.getDateFromUUID((UUID)id.getId());
		if(lastweek == -1){
			//initialization case
			countSinceChange = 1;
			lastweek = dt.getWeekOfWeekyear();
		}
		else if(dt.getWeekOfWeekyear() == lastweek){
			assert(countSinceChange < numberPerShard);
			countSinceChange++;
		}
		else{
			assertEquals(numberPerShard,countSinceChange);
			countSinceChange=1;
		};
		lastweek = dt.getWeekOfWeekyear();
		//System.out.println("countSinceChange = " + countSinceChange);
		//System.out.println("Actual Counter = " + counter);
		//System.out.println("Id Counter = " + id.getCounterValue());
		//System.out.println("Counter at ID = " + subject.getCounterAtId(id.getId()));
		//System.out.println("Date on UUID is: " + UuidUtil.getDateFromUUID((UUID)id.getId()));
		assertEquals(subject.getCounterAtId(id.getId()), id.getCounterValue());
	}
	assertEquals(totalNumberOfObjects,counter);
}
 
Example 9
Source File: StatisticsXmlReportGenerator.java    From megatron-java with Apache License 2.0 4 votes vote down vote up
private TimePeriod createWeekTimePeriod(DateTime dateTime) throws MegatronException {
    int week = dateTime.getWeekOfWeekyear();
    String periodStr = "w" + dateTime.getYear() + "-" + week;
    return new TimePeriod(periodStr);
}
 
Example 10
Source File: StatsRssGenerator.java    From megatron-java with Apache License 2.0 4 votes vote down vote up
private TimePeriod createWeekTimePeriod(DateTime dateTime) throws MegatronException {
    int week = dateTime.getWeekOfWeekyear();
    String periodStr = "w" + dateTime.getYear() + "-" + week;
    return new TimePeriod(periodStr);
}