public Range <int> ParseToRange(int value) { var intervalDuration = JavascriptMaths.Round(value / (double)RangeFactor); //TODO Check the intent? var daysSinceLastDayOfInterval = value - intervalDuration * RangeFactor; return(new Range <int>(daysSinceLastDayOfInterval - (intervalDuration - 1), daysSinceLastDayOfInterval)); }
//From the JS public bool TryDecode(int value, out DsosDecodeResult result) { result = null; if (ValidRange.Contains(value)) { result = DsosDecodeResult.CreateSymptomatic(value); return(true); } //1 day @ -14 to 19 days @ +21 if (85 < value && value < 1922) { var intervalDuration = JavascriptMaths.Round(value / (double)RangeFactor); //TODO Check the intent? var daysSinceLastDayOfInterval = value - intervalDuration * RangeFactor; //TODO //if (!ValidRange.Contains(daysSinceLastDayOfInterval)) // return false; var r = new Range <int>(daysSinceLastDayOfInterval - (intervalDuration - 1), daysSinceLastDayOfInterval); result = DsosDecodeResult.CreateSymptomatic(r); return(true); } if (ValidRange.Lo + OffsetSymptomaticOnsetDateUnknown <= value && value <= OffsetSymptomaticOnsetDateUnknown) { result = DsosDecodeResult.CreateSymptomaticOnsetUnknown(value - OffsetSymptomaticOnsetDateUnknown); return(true); } if (value >= OffsetAsymptomatic + ValidRange.Lo && value <= OffsetAsymptomatic) { result = DsosDecodeResult.CreateAsymptomatic(value - OffsetAsymptomatic); return(true); } if (value >= OffsetSymptomStateUnknown + ValidRange.Lo && value <= OffsetSymptomStateUnknown) { result = DsosDecodeResult.CreateSymptomsStatusUnknown(value - OffsetSymptomStateUnknown); return(true); } result = null; return(false); }