Пример #1
0
        public void NowEarlierStartIsolationFailTest()
        {
            var startQuarantine = _localClock.InZoneStrictly(_zoneGmt).ToInstant().Plus(Duration.FromHours(3));

            var fred = new IsolateRecord("Fred", startQuarantine, false);
            var calc = new CalcUk(fred);

            Assert.Equal(ExtNodatime.DurationError, calc.GetIsolationRemaining(_clock.GetCurrentInstant())); //now is earlier than start
        }
Пример #2
0
        public void SymptomsTest()
        {
            var startQuarantine = _localClock.InZoneStrictly(_zoneGmt).ToInstant();

            var fred = new IsolateRecord("Fred", startQuarantine, true);
            var calc = new CalcUk(fred);

            Assert.Equal(Duration.FromDays(10), calc.GetIsolationRemaining(_clock.GetCurrentInstant())); //now same as startQuarantine
        }
Пример #3
0
        public void GetIsolationPeriodMaxTest()
        {
            var startQuarantine = _localClock.InZoneStrictly(_zoneGmt).ToInstant();

            var fred = new IsolateRecord("Fred", startQuarantine, false);
            var calc = new CalcUk(fred);

            Assert.Equal(14, calc.GetIsolationPeriodMax());
        }
Пример #4
0
        public void SymptomsFeverAfterStartTest()
        {
            var startQuarantine = _localClock.InZoneStrictly(_zoneGmt).ToInstant().Minus(Duration.FromHours(3));
            var startFever      = startQuarantine.Plus(Duration.FromHours(1));

            var fred = new IsolateRecord("Fred", startQuarantine, true, startFever);
            var calc = new CalcUk(fred);

            Assert.Equal(Duration.FromHours((9 * 24) + 22), calc.GetIsolationRemaining(_clock.GetCurrentInstant())); //now 3 hours after startQuarantine and 2 hours after startFever
        }
Пример #5
0
        public void NoSymptomsAtDay14Test()
        {
            var startQuarantine = _localClock.InZoneStrictly(_zoneGmt).ToInstant().Minus(Duration.FromDays(14));
            var expected        = Duration.FromTimeSpan(new TimeSpan(0, 0, 0, 0));

            var fred = new IsolateRecord("Fred", startQuarantine, false);
            var calc = new CalcUk(fred);

            Assert.Equal(expected, calc.GetIsolationRemaining(_clock.GetCurrentInstant()));
        }
Пример #6
0
        public void StartFeverEarlierStartIsolationFailTest()
        {
            var startQuarantine = _localClock.InZoneStrictly(_zoneGmt).ToInstant().Minus(Duration.FromHours(3));   //3 hours before _clock (now)
            var startFever      = startQuarantine.Minus(Duration.FromHours(1));                                    //1 hour before startQuarantine

            var fred = new IsolateRecord("Fred", startQuarantine, false, startFever);
            var calc = new CalcUk(fred);

            Assert.Equal(ExtNodatime.DurationError, calc.GetIsolationRemaining(_clock.GetCurrentInstant())); //startFever is earlier than startQuarantine
        }
Пример #7
0
        public void SymptomsAtDay14Test() //It could be argued that the self-isolation is complete so fever is irrelevant, but side with caution
        {
            var startQuarantine = _localClock.InZoneStrictly(_zoneGmt).ToInstant().Minus(Duration.FromDays(14));
            var startFever      = startQuarantine.Plus(Duration.FromDays(14));
            var expected        = Duration.FromTimeSpan(new TimeSpan(10, 0, 0, 0));

            var fred = new IsolateRecord("Fred", startQuarantine, true, startFever);
            var calc = new CalcUk(fred);

            Assert.Equal(expected, calc.GetIsolationRemaining(_clock.GetCurrentInstant()));
        }
Пример #8
0
        public void SymptomsAtDay0Test()
        {
            var startQuarantine = _localClock.InZoneStrictly(_zoneGmt).ToInstant();
            var startFever      = startQuarantine;
            var expected        = Duration.FromTimeSpan(new TimeSpan(10, 0, 0, 0));

            var fred = new IsolateRecord("Fred", startQuarantine, true, startFever);
            var calc = new CalcUk(fred);

            Assert.Equal(expected, calc.GetIsolationRemaining(_clock.GetCurrentInstant()));
        }
Пример #9
0
        public IActionResult OnPost()
        {
            IActionResult rc = Page();

            SampleDateTime = GetText("ExampleDateTime");

            TextColor = "red";
            ShowRange = true;
            InitialiseSettingsFromCookies();


            var form = ProcessForm(SelectedTzDbName ?? AppSupportedTimeZones.DefaultTzDbName, SelectedCultureTab ?? AppSupportedCultures.DefaultTab);   //get time and culture from dropdowns on form

            if (ModelState.IsValid && (form != null))
            {
                try
                {
                    var nowInstance = _clock.GetCurrentInstant();
                    var record      = new IsolateRecord("Fred", form.StartIsolation, form.HasSymptoms, form.StartSymptoms);
                    var calc        = new CalcUk(record);

                    IsolationDaysMax = calc.GetIsolationPeriodMax();
                    if (calc.IsSymptomatic() && (form.StartSymptoms == null))
                    {
                        StartSymptoms = nowInstance.ToString(SelectedCultureTab, DateTimeZoneProviders.Tzdb[SelectedTzDbName], WithoutDaylightSavings);
                    }

                    var isolationDaysRemaining = calc.GetIsolationDaysRemaining(nowInstance, out var colour, out var comment);
                    if (isolationDaysRemaining == -1)
                    {
                        ModelState.TryAddModelError(nameof(ProgramError), $"{MxFormProc.ProgramErrorMsg} 101: An internal error has been detected. Please report this problem");
                    }
                    else
                    {
                        TextColor = colour;
                        Result    = comment;
                        IsolationDaysRemaining = isolationDaysRemaining;
                    }
                }
                catch (Exception e)
                {
                    ModelState.TryAddModelError(nameof(ProgramError), $"{MxFormProc.ProgramErrorMsg} 102: {e.Message}. Please report this problem.");
                }
            }
            return(rc);
        }