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

The following examples show how to use org.joda.time.DateTime#withTimeAtStartOfDay() . These examples are extracted from open source projects. 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
@Override
public List<PlacePurgeRecord> getPlacePurgeRecordingNoLaterThan(Date deleteTime) {
	DateTime d = new DateTime(deleteTime.getTime());
	d = d.withTimeAtStartOfDay();
	List<PlacePurgeRecord> records = new ArrayList<>();
	BoundStatement stmt;
	Iterator<Row> rs;
	for(int i=0; i<config.getPlacePurgeRecordingNumberOfDays(); i++) {
		stmt = purgePinnedRecordingTable.selectBy(d.toDate());
		rs = session.execute(stmt).iterator();
		while(rs.hasNext()) {
			records.add(purgePinnedRecordingTable.buildEntity(rs.next()));				
		}
		d = d.minusDays(1);
	}
	return records;
}
 
Example 2
Source Project: hudi   File: HiveTestUtil.java    License: Apache License 2.0 6 votes vote down vote up
private static HoodieCommitMetadata createPartitions(int numberOfPartitions, boolean isParquetSchemaSimple,
    boolean useSchemaFromCommitMetadata, DateTime startFrom, String instantTime) throws IOException, URISyntaxException {
  startFrom = startFrom.withTimeAtStartOfDay();

  HoodieCommitMetadata commitMetadata = new HoodieCommitMetadata();
  for (int i = 0; i < numberOfPartitions; i++) {
    String partitionPath = dtfOut.print(startFrom);
    Path partPath = new Path(hiveSyncConfig.basePath + "/" + partitionPath);
    fileSystem.makeQualified(partPath);
    fileSystem.mkdirs(partPath);
    List<HoodieWriteStat> writeStats = createTestData(partPath, isParquetSchemaSimple, instantTime);
    startFrom = startFrom.minusDays(1);
    writeStats.forEach(s -> commitMetadata.addWriteStat(partitionPath, s));
  }
  addSchemaToCommitMetadata(commitMetadata, isParquetSchemaSimple, useSchemaFromCommitMetadata);
  return commitMetadata;
}
 
Example 3
/**
 * Method to return a "normalized" version of the input Date
 * whose time is reset to the absolute start of that same day
 * (first millisecond of first second of first minute of first hour).
 *    
 * @param dateInst - instance of Date
 * @return - instance of Date as described
 * @throws AdeException 
 */
public static Date startOfDayUsingOutputTimeZone(Date dateInst) throws AdeException {

    if (outputTimeZone == null) {
        final TimeZone outputTimezone = Ade.getAde().getConfigProperties().getOutputTimeZone();
        outputTimeZone = DateTimeZone.forOffsetMillis(outputTimezone.getRawOffset());
    }

    if (dateInst == null) {
        throw new IllegalArgumentException();
    }

    /* Set start of today */
    DateTime startOFDay = new DateTime(dateInst);
    startOFDay = startOFDay.withZone(outputTimeZone);
    startOFDay = startOFDay.withTimeAtStartOfDay();

    return startOFDay.toDate();

}
 
Example 4
Source Project: onboard   File: ActivityServiceImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public List<Map<String, ?>> getActivityCountForUsersGroupByDate(Integer companyId, Date since, Date until) {
    List<User> companyUsers = userService.getUserByCompanyId(companyId);
    List<Map<String, ?>> result = Lists.newArrayList();
    Map<Integer, Integer> activityCountMap;
    DateTime dt = new DateTime(since);
    dt = dt.withTimeAtStartOfDay();
    DateTime end = new DateTime(until);
    end = end.withTimeAtStartOfDay().plusDays(1).minusMinutes(1);
    while (dt.toDate().before(end.toDate())) {
        activityCountMap = Maps.newHashMap();
        for (User user : companyUsers) {
            activityCountMap.put(user.getId(),
                    getCountByCompanyUserBetweenDates(companyId, user.getId(), dt.toDate(), dt.toDate()));
        }
        result.add(ImmutableMap.of("time", dt.toDate().getTime(), "counts", activityCountMap));
        dt = dt.plusDays(1);
    }
    return result;
}
 
Example 5
@Override
public void deletePurgePinnedRecordingNoLaterThan(Date deleteTime) {
	DateTime d = new DateTime(deleteTime.getTime());
	d = d.withTimeAtStartOfDay();
	BoundStatement stmt;
	for(int i=0; i<config.getPlacePurgeRecordingNumberOfDays(); i++) {
		stmt = purgePinnedRecordingTable.deleteBy(d.toDate());
		session.execute(stmt);			
		d = d.minusDays(1);
	}
	
}
 
Example 6
private void updateIndicatorSet() {

        mIndicatorsYear = mCalendar.get(Calendar.YEAR);

        MutableArrayList<Entry> toFilter = new MutableArrayList<>();
        toFilter.addAll(mainActivity.entries);

        DateTime yearStart = DateTime.now();
        yearStart = yearStart.withDate(mCalendar.get(Calendar.YEAR), 1, 1);
        yearStart = yearStart.withTimeAtStartOfDay();

        DateTime yearEnd = yearStart.plusYears(1).withTimeAtStartOfDay();
        yearEnd = yearEnd.minusMillis(1);

        Log.d("", "Start Year: " + yearStart.toString());
        Log.d("", "End Year: " + yearEnd.toString());

        EntryDateRangePredicate pred = new EntryDateRangePredicate(yearStart.getMillis(), yearEnd.getMillis());
        toFilter.filter(pred);

        HashSet<Integer> mDays = new HashSet<>();
        for (int i = 0; i < toFilter.size(); i++) {
            Entry e = toFilter.get(i);
            int year = e.creationDate.get(Calendar.YEAR);
            int month = e.creationDate.get(Calendar.MONTH);
            int day = e.creationDate.get(Calendar.DAY_OF_MONTH);
            int key = year + (month * 10000) + (day * 1000000);

            if (!mDays.contains(key))
                mDays.add(key);
        }

        mDayPickerView.setIndicators(mDays);
        toFilter.clear();
    }
 
Example 7
/**
 * Method to return a "normalized" version of the input Date
 * whose time is reset to the absolute start of that same day
 * (first millisecond of first second of first minute of first hour).
 *    
 * @param dateInst - instance of Date
 * @return - instance of Date as described
 * @throws AdeException 
 */
public static Date endOfDayUsingOutputTimeZone(Date dateInst) throws AdeException {

    /* 
     * Note: This method generates a different end of day compare to endOfDay().
     * endOfDay() would generate timestamp: 10/10/2013 23:59:59
     * endOfDayUsingOutputTimeZone() would generate timestampe: 10/11/2013 00:00:00
     */

    if (outputTimeZone == null) {
        final TimeZone outputTimezone = Ade.getAde().getConfigProperties().getOutputTimeZone();
        outputTimeZone = DateTimeZone.forOffsetMillis(outputTimezone.getRawOffset());
    }

    if (dateInst == null) {
        throw new IllegalArgumentException();
    }

    /* Set end of today */
    DateTime startOFDay = new DateTime(dateInst);
    startOFDay = startOFDay.withZone(outputTimeZone);
    startOFDay = startOFDay.plusDays(1);
    startOFDay = startOFDay.withTimeAtStartOfDay();

    return startOFDay.toDate();

}
 
Example 8
/**
 * Return the end of day of yesterday
 * @param dateTime
 * @return
 */
private DateTime getYesterdayEndOfDay(DateTime dateTime) {
    dateTime = dateTime.withTimeAtStartOfDay();
    dateTime = dateTime.minusMillis(1);

    return dateTime;
}
 
Example 9
/**
 * Creates a date.
 *
 * @param day the day of the year.
 * @return a date.
 */
public Date getDay( int day )
{
    DateTime dataTime = DateTime.now();
    dataTime = dataTime.withTimeAtStartOfDay();
    dataTime = dataTime.withDayOfYear( day );

    return dataTime.toDate();
}
 
Example 10
@Override
public boolean handler(HandlerData data) {

	Object[] objects = data.getValue("args");

	if (objects == null || objects.length == 0) {
		return true;
	}

	WallpaperDto wallpaperDto = (WallpaperDto) objects[0];

	DateTime nowTime = new DateTime();
	DateTime startOfDay = nowTime.withTimeAtStartOfDay();

	Long count = wallpaperRepository.countByAddDateAfterAndUser(
			startOfDay.toDate(), new User(wallpaperDto.getUserId()));

	if (count == null || count.intValue() < maxAddCredit) {
		Credit credit = new Credit(new User(wallpaperDto.getUserId()),
				com.wms.studio.api.constant.CreditType.收入);
		credit.setCreditNum(addCredit);
		credit.setDescriptions("上传壁纸奖励");
		userRepository.updateUserCreadit(credit.getCreditNum(),
				wallpaperDto.getUserId());
		creditRepository.save(credit);
	}

	return true;
}
 
Example 11
@Override
public boolean handler(HandlerData data) {
	Object[] objects = data.getValue("args");

	if (objects == null || objects.length == 0) {
		return true;
	}

	LoginIpDto loginIp = (LoginIpDto) objects[0];
	DateTime nowTime = new DateTime();
	DateTime startOfDay = nowTime.withTimeAtStartOfDay();
	Long loginCount = loginIpRepository
			.countByLoginTimeAfterAndLoginTypeAndUser(startOfDay.toDate(),
					LoginType.登录成功, new User(loginIp.getUserId()));
	if (loginCount == null || (long) loginCount <= 1L) {

		Credit credit = new Credit(new User(loginIp.getUserId()),
				com.wms.studio.api.constant.CreditType.收入);
		credit.setCreditNum(loginCredit);
		credit.setDescriptions("首次登录奖励");
		userRepository.updateUserCreadit(credit.getCreditNum(),
				loginIp.getUserId());
		creditRepository.save(credit);
	}

	return true;
}
 
Example 12
@Override
public boolean handler(HandlerData data) {

	Object[] objects = data.getValue("args");

	if (objects == null || objects.length == 0) {
		return true;
	}

	LoginIpDto loginIp = (LoginIpDto) objects[0];

	log.info("校验当天登录失败的次数是否达到预警的次数:"
			+ ToStringBuilder.reflectionToString(loginIp));
	// 校验当天登录失败的次数是否达到预警的次数
	DateTime nowTime = new DateTime();
	DateTime startOfDay = nowTime.withTimeAtStartOfDay();
	Long loginFailCount = loginIpRepository
			.countByLoginTimeAfterAndLoginTypeAndUser(startOfDay.toDate(),
					LoginType.登录失败, user);
	if (loginFailCount == null || (long) loginFailCount < failDisableCount) {
		return true;
	}
	user.setDisable(Boolean.TRUE);
	user.setDisableReason(UserDisableReason.登录超过限制);
	this.userRepository.save(user);
	/*
	 * this.userRepository.updateUserDisableStatus(user.getId(),
	 * Boolean.TRUE, UserDisableReason.登录超过限制);
	 */
	return true;
}
 
Example 13
static String getLocalAMString(DateTime now) {
	//we need an AM date
	DateTime dt = now.withTimeAtStartOfDay();
	Locale locale= new ResourceLoader("calendar").getLocale();
	DateTimeFormatter df = new DateTimeFormatterBuilder().appendHalfdayOfDayText().toFormatter().withLocale(locale);
	return df.print(dt);
}
 
Example 14
static String getLocalAMString(DateTime now) {
	//we need an AM date
	DateTime dt = now.withTimeAtStartOfDay();
	Locale locale= new ResourceLoader("calendar").getLocale();
	DateTimeFormatter df = new DateTimeFormatterBuilder().appendHalfdayOfDayText().toFormatter().withLocale(locale);
	return df.print(dt);
}
 
Example 15
public static DateTime getBoundaryAlignedTimeForDataset(DateTime dateTime, TimeUnit unit) {
  switch (unit) {
    case DAYS:
      dateTime = dateTime.withTimeAtStartOfDay();
      break;
    case HOURS:
    default:
      dateTime = dateTime.withTime(dateTime.getHourOfDay(), 0, 0, 0);
      break;
  }
  return dateTime;
}
 
Example 16
@Override
public void setUpTest()
{
    organisationUnit = createOrganisationUnit( 'A' );
    organisationUnitService.addOrganisationUnit( organisationUnit );

    OrganisationUnit organisationUnitB = createOrganisationUnit( 'B' );
    organisationUnitService.addOrganisationUnit( organisationUnitB );

    entityInstanceAttribute = createTrackedEntityAttribute( 'A' );
    attributeService.addTrackedEntityAttribute( entityInstanceAttribute );

    entityInstanceA1 = createTrackedEntityInstance( organisationUnit );
    entityInstanceB1 = createTrackedEntityInstance( organisationUnit );
    entityInstanceB1.setUid( "UID-B1" );

    programA = createProgram( 'A', new HashSet<>(), organisationUnit );

    programService.addProgram( programA );

    ProgramStage stageA = createProgramStage( 'A', programA );
    stageA.setSortOrder( 1 );
    programStageService.saveProgramStage( stageA );

    Set<ProgramStage> programStages = new HashSet<>();
    programStages.add( stageA );
    programA.setProgramStages( programStages );
    programService.updateProgram( programA );

    DateTime enrollmentDate = DateTime.now();
    enrollmentDate.withTimeAtStartOfDay();
    enrollmentDate = enrollmentDate.minusDays( 70 );

    DateTime incidenDate = DateTime.now();
    incidenDate.withTimeAtStartOfDay();

    programInstanceA = new ProgramInstance( enrollmentDate.toDate(), incidenDate.toDate(), entityInstanceA1,
        programA );
    programInstanceA.setUid( "UID-A" );
    programInstanceA.setOrganisationUnit( organisationUnit );

    programStageInstanceA = new ProgramStageInstance( programInstanceA, stageA );
    programInstanceA.setUid( "UID-PSI-A" );
    programInstanceA.setOrganisationUnit( organisationUnit );
}
 
Example 17
@Override
public void setUpTest()
{
    organisationUnitA = createOrganisationUnit( 'A' );
    long idA = organisationUnitService.addOrganisationUnit( organisationUnitA );

    organisationUnitB = createOrganisationUnit( 'B' );
    long idB = organisationUnitService.addOrganisationUnit( organisationUnitB );

    orgunitIds = new HashSet<>();
    orgunitIds.add( idA );
    orgunitIds.add( idB );

    programA = createProgram( 'A', new HashSet<>(), organisationUnitA );

    programService.addProgram( programA );

    ProgramStage stageA = new ProgramStage( "StageA", programA );
    stageA.setSortOrder( 1 );
    programStageService.saveProgramStage( stageA );

    ProgramStage stageB = new ProgramStage( "StageB", programA );
    stageB.setSortOrder( 2 );
    programStageService.saveProgramStage( stageB );

    Set<ProgramStage> programStages = new HashSet<>();
    programStages.add( stageA );
    programStages.add( stageB );
    programA.setProgramStages( programStages );
    programService.updateProgram( programA );

    programB = createProgram( 'B', new HashSet<>(), organisationUnitA );
    programService.addProgram( programB );

    programC = createProgram( 'C', new HashSet<>(), organisationUnitA );
    programService.addProgram( programC );

    entityInstanceA = createTrackedEntityInstance( organisationUnitA );
    entityInstanceService.addTrackedEntityInstance( entityInstanceA );

    TrackedEntityInstance entityInstanceB = createTrackedEntityInstance( organisationUnitB );
    entityInstanceService.addTrackedEntityInstance( entityInstanceB );

    DateTime testDate1 = DateTime.now();
    testDate1.withTimeAtStartOfDay();
    testDate1 = testDate1.minusDays( 70 );
    incidentDate = testDate1.toDate();

    DateTime testDate2 = DateTime.now();
    testDate2.withTimeAtStartOfDay();
    enrollmentDate = testDate2.toDate();

    programInstanceA = new ProgramInstance( enrollmentDate, incidentDate, entityInstanceA, programA );
    programInstanceA.setUid( "UID-A" );

    programInstanceB = new ProgramInstance( enrollmentDate, incidentDate, entityInstanceA, programB );
    programInstanceB.setUid( "UID-B" );
    programInstanceB.setStatus( ProgramStatus.CANCELLED );

    programInstanceC = new ProgramInstance( enrollmentDate, incidentDate, entityInstanceA, programC );
    programInstanceC.setUid( "UID-C" );
    programInstanceC.setStatus( ProgramStatus.COMPLETED );

    programInstanceD = new ProgramInstance( enrollmentDate, incidentDate, entityInstanceB, programA );
    programInstanceD.setUid( "UID-D" );
}
 
Example 18
@Override
public void setUpTest()
{
    organisationUnitA = createOrganisationUnit( 'A' );
    long idA = organisationUnitService.addOrganisationUnit( organisationUnitA );

    organisationUnitB = createOrganisationUnit( 'B' );
    long idB = organisationUnitService.addOrganisationUnit( organisationUnitB );

    orgunitIds = new HashSet<>();
    orgunitIds.add( idA );
    orgunitIds.add( idB );

    programA = createProgram( 'A', new HashSet<>(), organisationUnitA );

    programService.addProgram( programA );

    ProgramStage stageA = createProgramStage( 'A', programA );
    stageA.setSortOrder( 1 );
    programStageService.saveProgramStage( stageA );

    ProgramStage stageB = createProgramStage( 'B', programA );
    stageB.setSortOrder( 2 );
    programStageService.saveProgramStage( stageB );

    Set<ProgramStage> programStages = new HashSet<>();
    programStages.add( stageA );
    programStages.add( stageB );
    programA.setProgramStages( programStages );
    programService.updateProgram( programA );

    programB = createProgram( 'B', new HashSet<>(), organisationUnitA );
    programService.addProgram( programB );

    programC = createProgram( 'C', new HashSet<>(), organisationUnitA );
    programService.addProgram( programC );

    entityInstanceA = createTrackedEntityInstance( organisationUnitA );
    entityInstanceService.addTrackedEntityInstance( entityInstanceA );

    TrackedEntityInstance entityInstanceB = createTrackedEntityInstance( organisationUnitB );
    entityInstanceService.addTrackedEntityInstance( entityInstanceB );

    DateTime testDate1 = DateTime.now();
    testDate1.withTimeAtStartOfDay();
    testDate1 = testDate1.minusDays( 70 );
    incidenDate = testDate1.toDate();

    DateTime testDate2 = DateTime.now();
    testDate2.withTimeAtStartOfDay();
    enrollmentDate = testDate2.toDate();

    programInstanceA = new ProgramInstance( enrollmentDate, incidenDate, entityInstanceA, programA );
    programInstanceA.setUid( "UID-A" );
    programInstanceA.setOrganisationUnit( organisationUnitA );

    programStageInstanceA = new ProgramStageInstance( programInstanceA, stageA );
    programStageInstanceA.setUid( "UID-PSI-A" );
    programStageInstanceA.setOrganisationUnit( organisationUnitA );

    programInstanceB = new ProgramInstance( enrollmentDate, incidenDate, entityInstanceA, programB );
    programInstanceB.setUid( "UID-B" );
    programInstanceB.setStatus( ProgramStatus.CANCELLED );
    programInstanceB.setOrganisationUnit( organisationUnitB );

    programInstanceC = new ProgramInstance( enrollmentDate, incidenDate, entityInstanceA, programC );
    programInstanceC.setUid( "UID-C" );
    programInstanceC.setStatus( ProgramStatus.COMPLETED );
    programInstanceC.setOrganisationUnit( organisationUnitA );

    programInstanceD = new ProgramInstance( enrollmentDate, incidenDate, entityInstanceB, programA );
    programInstanceD.setUid( "UID-D" );
    programInstanceD.setOrganisationUnit( organisationUnitB );
}
 
Example 19
@Override
public void setUpTest()
{
    organisationUnit = createOrganisationUnit( 'A' );
    long idA = organisationUnitService.addOrganisationUnit( organisationUnit );

    orgunitIds = new HashSet<>();
    orgunitIds.add( idA );

    program = createProgram( 'A', new HashSet<>(), organisationUnit );

    programService.addProgram( program );

    ProgramStage stageA = createProgramStage( 'A', program );
    stageA.setSortOrder( 1 );
    programStageService.saveProgramStage( stageA );

    ProgramStage stageB = createProgramStage( 'B', program );
    stageB.setSortOrder( 2 );
    programStageService.saveProgramStage( stageB );

    Set<ProgramStage> programStages = new HashSet<>();
    programStages.add( stageA );
    programStages.add( stageB );
    program.setProgramStages( programStages );
    programService.updateProgram( program );

    entityInstance = createTrackedEntityInstance( organisationUnit );
    entityInstanceService.addTrackedEntityInstance( entityInstance );

    DateTime testDate1 = DateTime.now();
    testDate1.withTimeAtStartOfDay();
    testDate1 = testDate1.minusDays( 70 );
    incidenDate = testDate1.toDate();

    DateTime testDate2 = DateTime.now();
    testDate2.withTimeAtStartOfDay();
    enrollmentDate = testDate2.toDate();

    programInstance = new ProgramInstance( enrollmentDate, incidenDate, entityInstance, program );
    programInstance.setUid( "UID-A" );
    programInstance.setOrganisationUnit( organisationUnit );

    programInstanceService.addProgramInstance( programInstance );
}