Search in sources :

Example 6 with Cal

use of org.hisp.dhis.period.Cal in project dhis2-core by dhis2.

the class EthiopianCalendarTest method testGenerateWeeklyPeriods.

@Test
public void testGenerateWeeklyPeriods() {
    Date startDate = new Cal(1975, 1, 1, true).time();
    Date endDate = new Cal(2025, 1, 2, true).time();
    List<Period> weeks = new WeeklyPeriodType().generatePeriods(calendar, startDate, endDate);
    assertEquals(2610, weeks.size());
}
Also used : WeeklyPeriodType(org.hisp.dhis.period.WeeklyPeriodType) Period(org.hisp.dhis.period.Period) Date(java.util.Date) Cal(org.hisp.dhis.period.Cal) Test(org.junit.Test)

Example 7 with Cal

use of org.hisp.dhis.period.Cal in project dhis2-core by dhis2.

the class PersianCalendarTest method testGenerateQuarterlyPeriods.

@Test
public void testGenerateQuarterlyPeriods() {
    Date startDate = new Cal(2017, 3, 21, true).time();
    Date endDate = new Cal(2017, 6, 21, true).time();
    List<Period> monthly = new QuarterlyPeriodType().generatePeriods(calendar, startDate, endDate);
    assertEquals(1, monthly.size());
}
Also used : QuarterlyPeriodType(org.hisp.dhis.period.QuarterlyPeriodType) Period(org.hisp.dhis.period.Period) Date(java.util.Date) Cal(org.hisp.dhis.period.Cal) Test(org.junit.Test)

Example 8 with Cal

use of org.hisp.dhis.period.Cal in project dhis2-core by dhis2.

the class DefaultSecurityService method initRestore.

@Override
public String[] initRestore(UserCredentials credentials, RestoreOptions restoreOptions) {
    String token = restoreOptions.getTokenPrefix() + CodeGenerator.generateCode(RESTORE_TOKEN_LENGTH);
    String code = CodeGenerator.generateCode(RESTORE_CODE_LENGTH);
    String hashedToken = passwordManager.encode(token);
    String hashedCode = passwordManager.encode(code);
    RestoreType restoreType = restoreOptions.getRestoreType();
    Date expiry = new Cal().now().add(restoreType.getExpiryIntervalType(), restoreType.getExpiryIntervalCount()).time();
    credentials.setRestoreToken(hashedToken);
    credentials.setRestoreCode(hashedCode);
    credentials.setRestoreExpiry(expiry);
    userService.updateUserCredentials(credentials);
    return new String[] { token, code };
}
Also used : Date(java.util.Date) Cal(org.hisp.dhis.period.Cal)

Aggregations

Date (java.util.Date)8 Cal (org.hisp.dhis.period.Cal)8 Period (org.hisp.dhis.period.Period)7 Test (org.junit.Test)6 DailyPeriodType (org.hisp.dhis.period.DailyPeriodType)2 MonthlyPeriodType (org.hisp.dhis.period.MonthlyPeriodType)2 QuarterlyPeriodType (org.hisp.dhis.period.QuarterlyPeriodType)2 ArrayList (java.util.ArrayList)1 Calendar (org.hisp.dhis.calendar.Calendar)1 UniqueArrayList (org.hisp.dhis.commons.collection.UniqueArrayList)1 PeriodType (org.hisp.dhis.period.PeriodType)1 WeeklyPeriodType (org.hisp.dhis.period.WeeklyPeriodType)1