Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into DHIS2-18791-align
Browse files Browse the repository at this point in the history
  • Loading branch information
enricocolasante committed Jan 20, 2025
2 parents 22e50cc + aa707d9 commit 6fdab74
Show file tree
Hide file tree
Showing 56 changed files with 1,434 additions and 1,043 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*/
package org.hisp.dhis.calendar.impl;

import java.time.LocalDate;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -54,6 +55,10 @@ public class NepaliCalendar extends AbstractCalendar {

private static final Calendar SELF = new NepaliCalendar();

private static final int DEFAULT_WEEKS_IN_YEAR = 52;

private static final int WEEK_LENGTH = 7;

public static Calendar getInstance() {
return SELF;
}
Expand Down Expand Up @@ -144,25 +149,46 @@ public int isoWeek(DateTimeUnit dateTimeUnit) {

@Override
public int week(DateTimeUnit dateTimeUnit) {
return isoWeek(dateTimeUnit);
/*
* https://en.m.wikipedia.org/wiki/ISO_week_date
*
* 10 = the constant =>
* 1. we should get zero or positive week number.
* 2. the first week should contain 4th of Jan
* 3. the earliest day_of_year we could ask week number for is 1 = Jan 1
* 4. the latest day_of_week we could ask week number for is 7 = Sun
* week = the constant + 1 - 7 => 0 = the constant + 1 - 7 => the constant = 6
* however, we also need to add 4 more days to ensure Jan 4th is in the week
* hence the constant = 10.
*
*/
int week = (10 + getDayOfYear(dateTimeUnit) - isoWeekday(dateTimeUnit)) / WEEK_LENGTH;
if (week < 1) {
week = DEFAULT_WEEKS_IN_YEAR;
} else if (week > DEFAULT_WEEKS_IN_YEAR) {
week = 1;
}
return week;
}

@Override
public int isoWeekday(DateTimeUnit dateTimeUnit) {
DateTime dateTime =
toIso(dateTimeUnit).toJodaDateTime(ISOChronology.getInstance(DateTimeZone.getDefault()));
return dateTime.getDayOfWeek();
/*
* Calculating week day from calendar dateTimeUnit is best managed
* via Gregorian calendar as week duration is 7 days in 'all' calendars
* and Mon = Day 1, Tue = Day 2, Wed = Day 3, ...
*/
DateTimeUnit isoDateTimeUnit = toIso(dateTimeUnit);

LocalDate localDate =
LocalDate.of(
isoDateTimeUnit.getYear(), isoDateTimeUnit.getMonth(), isoDateTimeUnit.getDay());
return localDate.getDayOfWeek().getValue();
}

@Override
public int weekday(DateTimeUnit dateTimeUnit) {
int dayOfWeek = (isoWeekday(dateTimeUnit) + 1);

if (dayOfWeek > 7) {
return 1;
}

return dayOfWeek;
return isoWeekday(dateTimeUnit);
}

@Override
Expand Down Expand Up @@ -461,11 +487,24 @@ private DateInterval toDayIsoInterval(DateTimeUnit dateTimeUnit, int offset, int
return new DateInterval(from, to, DateIntervalType.ISO8601_DAY);
}

private int getDayOfYear(DateTimeUnit dateTimeUnit) {
int dayOfYear = dateTimeUnit.getDay();

if (CONVERSION_MAP.get(dateTimeUnit.getYear()) != null) {
for (int j = 1; j < dateTimeUnit.getMonth(); j++) {
dayOfYear += CONVERSION_MAP.get(dateTimeUnit.getYear())[j];
}
}
return dayOfYear;
}

// ------------------------------------------------------------------------------------------------------------
// Conversion map for Nepali calendar
// Conversion map for Nepali calendar from year 1970 to 2100.
//
// Based on map from:
// http://forjavaprogrammers.blogspot.com/2012/06/how-to-convert-english-date-to-nepali.html
// http://www.ashesh.com.np
// http://nepalicalendar.rat32.com/index.php
// http://www.ashesh.com.np/nepali-calendar/
// ------------------------------------------------------------------------------------------------------------

/**
Expand All @@ -475,6 +514,39 @@ private DateInterval toDayIsoInterval(DateTimeUnit dateTimeUnit, int offset, int
private static final Map<Integer, int[]> CONVERSION_MAP = new HashMap<>();

static {
CONVERSION_MAP.put(1970, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(1971, new int[] {0, 31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(1972, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31});
CONVERSION_MAP.put(1973, new int[] {0, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31});
CONVERSION_MAP.put(1974, new int[] {0, 30, 32, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(1975, new int[] {0, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(1976, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31});
CONVERSION_MAP.put(1977, new int[] {0, 30, 32, 31, 32, 31, 31, 29, 30, 29, 30, 29, 31});
CONVERSION_MAP.put(1978, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(1979, new int[] {0, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30});

CONVERSION_MAP.put(1980, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31});
CONVERSION_MAP.put(1981, new int[] {0, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30});
CONVERSION_MAP.put(1982, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(1983, new int[] {0, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(1984, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31});
CONVERSION_MAP.put(1985, new int[] {0, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30});
CONVERSION_MAP.put(1986, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(1987, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(1988, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31});
CONVERSION_MAP.put(1989, new int[] {0, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30});

CONVERSION_MAP.put(1990, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(1991, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30});
CONVERSION_MAP.put(1992, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31});
CONVERSION_MAP.put(1993, new int[] {0, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(1994, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(1995, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30});
CONVERSION_MAP.put(1996, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31});
CONVERSION_MAP.put(1997, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(1998, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(1999, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31});

CONVERSION_MAP.put(2000, new int[] {0, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31});
CONVERSION_MAP.put(2001, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2002, new int[] {0, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30});
Expand All @@ -485,6 +557,7 @@ private DateInterval toDayIsoInterval(DateTimeUnit dateTimeUnit, int offset, int
CONVERSION_MAP.put(2007, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31});
CONVERSION_MAP.put(2008, new int[] {0, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31});
CONVERSION_MAP.put(2009, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});

CONVERSION_MAP.put(2010, new int[] {0, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2011, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31});
CONVERSION_MAP.put(2012, new int[] {0, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30});
Expand All @@ -495,6 +568,7 @@ private DateInterval toDayIsoInterval(DateTimeUnit dateTimeUnit, int offset, int
CONVERSION_MAP.put(2017, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2018, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2019, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31});

CONVERSION_MAP.put(2020, new int[] {0, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2021, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2022, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30});
Expand All @@ -505,6 +579,7 @@ private DateInterval toDayIsoInterval(DateTimeUnit dateTimeUnit, int offset, int
CONVERSION_MAP.put(2027, new int[] {0, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31});
CONVERSION_MAP.put(2028, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2029, new int[] {0, 31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30});

CONVERSION_MAP.put(2030, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31});
CONVERSION_MAP.put(2031, new int[] {0, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31});
CONVERSION_MAP.put(2032, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
Expand All @@ -515,6 +590,7 @@ private DateInterval toDayIsoInterval(DateTimeUnit dateTimeUnit, int offset, int
CONVERSION_MAP.put(2037, new int[] {0, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2038, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31});
CONVERSION_MAP.put(2039, new int[] {0, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30});

CONVERSION_MAP.put(2040, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2041, new int[] {0, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2042, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31});
Expand All @@ -525,6 +601,7 @@ private DateInterval toDayIsoInterval(DateTimeUnit dateTimeUnit, int offset, int
CONVERSION_MAP.put(2047, new int[] {0, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2048, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2049, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30});

CONVERSION_MAP.put(2050, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31});
CONVERSION_MAP.put(2051, new int[] {0, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2052, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
Expand All @@ -535,6 +612,7 @@ private DateInterval toDayIsoInterval(DateTimeUnit dateTimeUnit, int offset, int
CONVERSION_MAP.put(2057, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31});
CONVERSION_MAP.put(2058, new int[] {0, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31});
CONVERSION_MAP.put(2059, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});

CONVERSION_MAP.put(2060, new int[] {0, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2061, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31});
CONVERSION_MAP.put(2062, new int[] {0, 30, 32, 31, 32, 31, 31, 29, 30, 29, 30, 29, 31});
Expand All @@ -545,6 +623,7 @@ private DateInterval toDayIsoInterval(DateTimeUnit dateTimeUnit, int offset, int
CONVERSION_MAP.put(2067, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2068, new int[] {0, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2069, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31});

CONVERSION_MAP.put(2070, new int[] {0, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30});
CONVERSION_MAP.put(2071, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2072, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30});
Expand All @@ -555,26 +634,29 @@ private DateInterval toDayIsoInterval(DateTimeUnit dateTimeUnit, int offset, int
CONVERSION_MAP.put(2077, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31});
CONVERSION_MAP.put(2078, new int[] {0, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2079, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});

CONVERSION_MAP.put(2080, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30});
CONVERSION_MAP.put(2081, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31});
CONVERSION_MAP.put(2082, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2083, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2084, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31});
CONVERSION_MAP.put(2085, new int[] {0, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31});
CONVERSION_MAP.put(2086, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2087, new int[] {0, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2088, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31});
CONVERSION_MAP.put(2089, new int[] {0, 30, 32, 31, 32, 31, 31, 29, 30, 29, 30, 29, 31});
CONVERSION_MAP.put(2090, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2091, new int[] {0, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2092, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31});
CONVERSION_MAP.put(2093, new int[] {0, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31});
CONVERSION_MAP.put(2094, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2095, new int[] {0, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 29});
CONVERSION_MAP.put(2096, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 32});
CONVERSION_MAP.put(2097, new int[] {0, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30});
CONVERSION_MAP.put(2098, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2099, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2100, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31});
CONVERSION_MAP.put(2081, new int[] {0, 31, 31, 32, 32, 31, 30, 30, 30, 29, 30, 30, 30});
CONVERSION_MAP.put(2082, new int[] {0, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30});
CONVERSION_MAP.put(2083, new int[] {0, 31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30});
CONVERSION_MAP.put(2084, new int[] {0, 31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30});
CONVERSION_MAP.put(2085, new int[] {0, 31, 32, 31, 32, 30, 31, 30, 30, 29, 30, 30, 30});
CONVERSION_MAP.put(2086, new int[] {0, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30});
CONVERSION_MAP.put(2087, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 30, 29, 30, 30, 30});
CONVERSION_MAP.put(2088, new int[] {0, 30, 31, 32, 32, 30, 31, 30, 30, 29, 30, 30, 30});
CONVERSION_MAP.put(2089, new int[] {0, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30});

CONVERSION_MAP.put(2090, new int[] {0, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30});
CONVERSION_MAP.put(2091, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 30, 29, 30, 30, 30});
CONVERSION_MAP.put(2092, new int[] {0, 31, 31, 32, 32, 31, 30, 30, 30, 29, 30, 30, 30});
CONVERSION_MAP.put(2093, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30});
CONVERSION_MAP.put(2094, new int[] {0, 31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30});
CONVERSION_MAP.put(2095, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 30, 30, 30});
CONVERSION_MAP.put(2096, new int[] {0, 30, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2097, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30});
CONVERSION_MAP.put(2098, new int[] {0, 31, 31, 32, 31, 31, 31, 29, 30, 29, 30, 30, 31});
CONVERSION_MAP.put(2099, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 29, 30, 30, 30});

CONVERSION_MAP.put(2100, new int[] {0, 31, 32, 31, 32, 30, 31, 30, 29, 30, 29, 30, 30});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2004-2025, University of Oslo
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* Neither the name of the HISP project nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.hisp.dhis.expression;

import org.hisp.dhis.common.GenericStore;

/**
* @author david mackessy
*/
public interface ExpressionStore extends GenericStore<Expression> {

/**
* Update all expressions whose expression property contains the 'find' value. When updating, it
* replaces all occurrences of 'find' with 'replace'.
*
* @param find text to search for
* @param replace text used to replace 'find'
* @return number of entities updated
*/
int updateExpressionContaining(String find, String replace);
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,15 @@ public interface IndicatorStore extends IdentifiableObjectStore<Indicator> {
List<Indicator> getIndicatorsWithNumeratorContaining(String search);

List<Indicator> getIndicatorsWithDenominatorContaining(String search);

/**
* Updates any indicator that has the 'find' param in either its numerator or denominator. The
* update involves updating numerator and denominator, replacing all occurrences of 'find' with
* 'replace'.
*
* @param find text to search for
* @param replace text used to replace
* @return number of rows updated
*/
int updateNumeratorDenominatorContaining(String find, String replace);
}
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ public Period createPeriod(DateInterval dateInterval) {
final DateTimeUnit from = cal.toIso(dateInterval.getFrom());
final DateTimeUnit to = cal.toIso(dateInterval.getTo());

return new Period(this, from.toJdkDate(), to.toJdkDate(), getIsoDate(from));
return new Period(this, from.toJdkDate(), to.toJdkDate(), getIsoDate(dateInterval.getFrom()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@
@Getter
@Builder
public class LoginConfigResponse {

@JsonProperty private String apiVersion;

@JsonProperty private String applicationTitle;
@JsonProperty private String applicationDescription;
@JsonProperty private String applicationNotification;
Expand All @@ -57,6 +55,9 @@ public class LoginConfigResponse {
@JsonProperty private String loginPageLayout;
@JsonProperty private String loginPageTemplate;
@JsonProperty private String recaptchaSite;
@JsonProperty private String passwordValidationPattern;
@JsonProperty private String minPasswordLength;
@JsonProperty private String maxPasswordLength;

@JsonProperty private boolean emailConfigured;
@JsonProperty private boolean selfRegistrationEnabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -745,4 +745,15 @@ default boolean isHideUnapprovedDataInAnalytics() {
// -1 means approval is disabled
return getIgnoreAnalyticsApprovalYearThreshold() >= 0;
}

/**
* @return A regex pattern string that enforces the current password validation rules
*/
default String getPasswordValidationPattern() {
return asString(
"passwordValidationPattern",
String.format(
"^(?=.*[A-Z])(?=.*[a-z])(?=.*\\d)(?=.*[\\W_])[A-Za-z\\d\\W_]{%d,%d}$",
getMinPasswordLength(), getMaxPasswordLength()));
}
}
Loading

0 comments on commit 6fdab74

Please sign in to comment.