/** * Initialize from a string, which may either be an ISO date in the "yyyy-mm-dd" format, or a modified ISO string * where the year is followed by an "s" to indicade that decade only is known. Also supported: "yyyy[s]-mm" and * "yyyy[s]". Formally, the format is: "yyyy[s][-mm[-dd]]". * * @param phenoTipsDateString a date string. */ public PhenoTipsDate(String phenoTipsDateString) { // treat null input as empty input String useDateString = (phenoTipsDateString == null) ? "" : phenoTipsDateString; // string: "1920s" or "1990" or "1990-05" or "1990-01-21" or "1990s-01-01" Matcher m = DATE_STRING_REGEXP.matcher(useDateString); if (m.find()) { // note: month (#4) and day (#6) groups may be null, that is supported this.year = stringToIntegerInRange(m.group(1), null, null); this.month = stringToIntegerInRange(m.group(4), MIN_MONTH, MAX_MONTH); this.day = stringToIntegerInRange(m.group(6), MIN_DAY, MAX_DAY); if (m.group(2) != null) { this.rangeYears = 10; } else { this.rangeYears = null; } } else { this.rangeYears = null; this.year = null; this.month = null; this.day = null; } }
/** * Initialize from a string, which may either be an ISO date in the "yyyy-mm-dd" format, or a modified ISO string * where the year is followed by an "s" to indicade that decade only is known. Also supported: "yyyy[s]-mm" and * "yyyy[s]". Formally, the format is: "yyyy[s][-mm[-dd]]". * * @param phenoTipsDateString a date string. */ public PhenoTipsDate(String phenoTipsDateString) { // treat null input as empty input String useDateString = (phenoTipsDateString == null) ? "" : phenoTipsDateString; // string: "1920s" or "1990" or "1990-05" or "1990-01-21" or "1990s-01-01" Matcher m = DATE_STRING_REGEXP.matcher(useDateString); if (m.find()) { // note: month (#4) and day (#6) groups may be null, that is supported this.year = stringToIntegerInRange(m.group(1), null, null); this.month = stringToIntegerInRange(m.group(4), MIN_MONTH, MAX_MONTH); this.day = stringToIntegerInRange(m.group(6), MIN_DAY, MAX_DAY); if (m.group(2) != null) { this.rangeYears = 10; } else { this.rangeYears = null; } } else { this.rangeYears = null; this.year = null; this.month = null; this.day = null; } }
private Integer getNumericValueFromJSON(JSONObject json, String key, Integer validRangeMin, Integer validRangeMax) { if (!json.has(key)) { return null; } // check if the key is an integer int intValue = json.optInt(key, Integer.MIN_VALUE); if (intValue != Integer.MIN_VALUE) { if (valueInRange(intValue, validRangeMin, validRangeMax)) { return intValue; } return null; } // check if the key is a string and try to parse the value from it return stringToIntegerInRange(json.optString(key, ""), validRangeMin, validRangeMax); }
useFuzzyDate.put(JSON_RANGE_FIELDNAME, range); Integer firstYearOfDecade = stringToIntegerInRange(m.group(1), null, null); useFuzzyDate.put(JSON_YEAR_FIELDNAME, firstYearOfDecade);
useFuzzyDate.put(JSON_RANGE_FIELDNAME, range); Integer firstYearOfDecade = stringToIntegerInRange(m.group(1), null, null); useFuzzyDate.put(JSON_YEAR_FIELDNAME, firstYearOfDecade);