コード例 #1
0
ファイル: TimeTest.cs プロジェクト: odnodn/mscui
        public void AddAddHoursAndMinutes()
        {
            DateTime baseDateTime = DateTime.Now; // :-)

            NhsTime time = new NhsTime(baseDateTime);

            string addInstruction = string.Format(CultureInfo.CurrentCulture, "+1{0}+5{1}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.HoursUnit, NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.MinutesUnit);

            Assert.IsTrue(NhsTime.IsAddValid(addInstruction), string.Format(CultureInfo.CurrentCulture, "{0} was not recognised as an Time Add Instruction", addInstruction));

            time.Add(addInstruction);

            Assert.AreEqual(time.TimeValue, baseDateTime.AddHours(1).AddMinutes(5), string.Format(CultureInfo.CurrentCulture, "Failed using {0}", addInstruction));

            // Now try without +

            // Reset
            baseDateTime = DateTime.Now;
            time         = new NhsTime(baseDateTime);

            // reinitialise add instructionstring as instruction without operands

            addInstruction = string.Format(CultureInfo.CurrentCulture, "1{0}5{1}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.HoursUnit, NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.MinutesUnit);

            Assert.IsTrue(NhsTime.IsAddValid(addInstruction), string.Format(CultureInfo.CurrentCulture, "{0} was not recognised as an Time Add Instruction", addInstruction));

            time.Add(addInstruction);

            Assert.AreEqual(time.TimeValue, baseDateTime.AddHours(1).AddMinutes(5), string.Format(CultureInfo.CurrentCulture, "Failed using {0}", addInstruction));
        }
コード例 #2
0
ファイル: TimeTest.cs プロジェクト: odnodn/mscui
        public void NullInstructionTimeOneParameterAddTest()
        {
            DateTime baseDateTime = DateTime.Now;
            NhsTime  time         = new NhsTime(baseDateTime);

            time.Add(null);
        }
コード例 #3
0
ファイル: TimeTest.cs プロジェクト: odnodn/mscui
        public void NullInstructionTimeTwoParametersAddTest()
        {
            DateTime baseDateTime = DateTime.Now;
            NhsTime  time         = new NhsTime(baseDateTime);

            NhsTime.Add(time, null);
        }
コード例 #4
0
ファイル: TimeTest.cs プロジェクト: odnodn/mscui
        public void InvalidInstructionTimeAddTest()
        {
            DateTime baseDateTime = DateTime.Now;
            NhsTime  time         = new NhsTime(baseDateTime);

            NhsTime.Add(time, string.Format(CultureInfo.CurrentCulture, "+1{0}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.resourceCulture));
        }
コード例 #5
0
        /// <summary>
        /// Check if the ControlToValidate is valid
        /// </summary>
        /// <returns>True if control properties is valid</returns>
        protected override bool EvaluateIsValid()
        {
            string value = this.GetControlValidationValue(this.ControlToValidate);

            NhsTime tryParseResult;

            return(NhsTime.TryParseExact(value, out tryParseResult, CultureInfo.CurrentCulture));
        }
コード例 #6
0
ファイル: TimeLabelTest.cs プロジェクト: rbirkby/mscui
        public void ValueProperty()
        {
            NhsTime time = new NhsTime();
            TimeLabel testLabel = new TimeLabel();

            testLabel.Value = time;

            Assert.AreEqual<NhsTime>(testLabel.Value, time);
        }
コード例 #7
0
ファイル: TimeTest.cs プロジェクト: odnodn/mscui
        public void IsNullProperty()
        {
            NhsTime time = new NhsTime();

            // default datetype is exact
            Assert.IsFalse(time.IsNull);
            time.TimeType = TimeType.Null;
            Assert.IsTrue(time.IsNull);
        }
コード例 #8
0
ファイル: TimeLabelTest.cs プロジェクト: odnodn/mscui
        public void ValueProperty()
        {
            NhsTime   time      = new NhsTime();
            TimeLabel testLabel = new TimeLabel();

            testLabel.Value = time;

            Assert.AreEqual <NhsTime>(testLabel.Value, time);
        }
コード例 #9
0
ファイル: TimeTest.cs プロジェクト: odnodn/mscui
        public void ToStringDisplaySeconds()
        {
            NhsTime time = new NhsTime();

            string   formattedTime  = time.ToString(false, CultureInfo.CurrentCulture, true, false, false);
            TimeSpan parsedTimeSpan = TimeSpan.Parse(formattedTime);

            Assert.AreEqual <int>(parsedTimeSpan.Seconds, time.TimeValue.Second, "NhsTime DisplaySeconds incorrect");
        }
コード例 #10
0
        /// <summary>
        /// Converts the provided dictionary into an object of the specified type
        /// </summary>
        /// <param name="dictionary">An IDictionary instance of property data stored as name/value pairs</param>
        /// <param name="type">The Type of the resulting object</param>
        /// <param name="serializer">The JavaScriptSerializer instance</param>
        /// <returns>The deserialized Object</returns>
        /// <remarks>KeyboardShortcut is never sent back up to the server so we do not support Deserialization</remarks>
        /// <exception cref="NotImplementedException">Always returns this exception</exception>
        public override object Deserialize(IDictionary <string, object> dictionary, Type type, JavaScriptSerializer serializer)
        {
            NhsTime deserialisationTarget = new NhsTime();

            deserialisationTarget.NullIndex = (dictionary.ContainsKey("_nullIndex") ? (int)dictionary["_nullIndex"] : (int)dictionary["nullIndex"]);
            deserialisationTarget.TimeType  = (dictionary.ContainsKey("_timeType") ? (TimeType)dictionary["_timeType"] : (TimeType)dictionary["timeType"]);
            deserialisationTarget.TimeValue = (dictionary.ContainsKey("_timeValue") ? ((DateTime)dictionary["_timeValue"]).ToLocalTime() : ((DateTime)dictionary["timeValue"]).ToLocalTime());

            return(deserialisationTarget);
        }
コード例 #11
0
ファイル: TimeTest.cs プロジェクト: odnodn/mscui
        public void ParseNotApproximateTruePassedToToString()
        {
            System.DateTime baseDateTime = System.DateTime.Now;

            NhsTime time = new NhsTime(baseDateTime);

            Assert.AreEqual <TimeType>(time.TimeType, TimeType.Exact, "TimeType should be Exact when set to a date");

            NhsTime.ParseExact(time.ToString(true), CultureInfo.CurrentCulture);
        }
コード例 #12
0
ファイル: TimeTest.cs プロジェクト: odnodn/mscui
        public void ToStringDisplay12Hour()
        {
            int      hours    = 14;
            DateTime dateTime = new DateTime(2006, 1, 1, hours, 20, 11);
            NhsTime  time     = new NhsTime(dateTime);

            string   formattedTime  = time.ToString(false, CultureInfo.CurrentCulture, false, true, false);
            DateTime parsedDateTime = DateTime.Parse(formattedTime, CultureInfo.CurrentCulture);

            Assert.AreEqual <int>(parsedDateTime.Hour, hours - 12, "NhsTime Display12Hour incorrect");
        }
コード例 #13
0
ファイル: TimeTest.cs プロジェクト: odnodn/mscui
        public void ParseWithAMPMDesignator()
        {
            GlobalizationService gs  = new GlobalizationService();
            DateTime             now = DateTime.Now;
            string  formattedTime    = now.ToString(gs.ShortTimePatternWithSecondsAMPM, CultureInfo.CurrentCulture);
            NhsTime time             = NhsTime.ParseExact(formattedTime, CultureInfo.CurrentCulture);

            Assert.AreEqual <int>(now.Hour, time.TimeValue.Hour, "Parse failed to set hours with am/pm designator");
            Assert.AreEqual <int>(now.Minute, time.TimeValue.Minute, "Parse failed to set minutes with am/pm designator");
            Assert.AreEqual <int>(now.Second, time.TimeValue.Second, "Parse failed to set seconds with am/pm designator");
        }
コード例 #14
0
ファイル: TimeInputBoxExtender.cs プロジェクト: odnodn/mscui
        /// <summary>‍
        /// Handle loading of client state
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">args</param>
        private void ExtenderClientStateLoaded(object sender, EventArgs e)
        {
            if (this.ClientState != null)
            {
                JavaScriptSerializer jss = new JavaScriptSerializer();
                jss.RegisterConverters(new JavaScriptConverter[] { new NhsTimeJavascriptConverter() });

                this.state = jss.Deserialize <TimeInputClientState>(ClientState);

                this.value = this.state.Value;
            }
        }
コード例 #15
0
ファイル: TimeTest.cs プロジェクト: odnodn/mscui
        public void ParseInvalidNullIndex()
        {
            NhsTime parsedTime;

            string invalidNullIndexString = "Null:-256";

            Assert.IsFalse(NhsTime.TryParseExact(invalidNullIndexString, out parsedTime, CultureInfo.CurrentCulture), string.Format(CultureInfo.InvariantCulture, "TryParse failed to return false with string of, {0}", invalidNullIndexString));

            invalidNullIndexString = "Null:124";

            Assert.IsFalse(NhsTime.TryParseExact(invalidNullIndexString, out parsedTime, CultureInfo.CurrentCulture), string.Format(CultureInfo.InvariantCulture, "TryParse failed to return false with string of, {0}", invalidNullIndexString));
        }
コード例 #16
0
ファイル: TimeTest.cs プロジェクト: odnodn/mscui
        public void ToStringDisplayAMPM()
        {
            NhsTime morningTime   = NhsTime.ParseExact("10:00:00", CultureInfo.CurrentCulture);
            NhsTime afternoonTime = NhsTime.ParseExact("15:00:00", CultureInfo.CurrentCulture);

            string formattedMorningTime   = morningTime.ToString(false, CultureInfo.CurrentCulture, false, true, true);
            string formattedAfternoonTime = afternoonTime.ToString(false, CultureInfo.CurrentCulture, false, true, true);
            string morningDesignator      = CultureInfo.CurrentCulture.DateTimeFormat.AMDesignator.ToLower(CultureInfo.CurrentCulture);
            string afternoonDesignator    = CultureInfo.CurrentCulture.DateTimeFormat.PMDesignator.ToLower(CultureInfo.CurrentCulture);

            Assert.IsTrue(formattedMorningTime.Contains(morningDesignator));
            Assert.IsTrue(formattedAfternoonTime.Contains(afternoonDesignator));
        }
コード例 #17
0
ファイル: TimeTest.cs プロジェクト: odnodn/mscui
        public void AddSubtract2HoursAdd25Minutes()
        {
            DateTime nowAsItWasAtTheStartofTheTest = DateTime.Now; // :-)

            NhsTime time = new NhsTime(nowAsItWasAtTheStartofTheTest);

            string addInstruction = string.Format(CultureInfo.CurrentCulture, "-2{0}+25{1}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.HoursUnit, NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.MinutesUnit);

            Assert.IsTrue(NhsTime.IsAddValid(addInstruction), string.Format(CultureInfo.CurrentCulture, "{0} was not recognised as a Time Add Instruction", addInstruction));

            time.Add(addInstruction);

            Assert.AreEqual(nowAsItWasAtTheStartofTheTest.AddHours(-2).AddMinutes(25), time.TimeValue);
        }
コード例 #18
0
ファイル: TimeTest.cs プロジェクト: odnodn/mscui
        public void ParseNullIndex()
        {
            NhsTime time = new NhsTime();

            time.TimeType  = TimeType.NullIndex;
            time.NullIndex = 4;

            NhsTime parsedTime;

            Assert.IsTrue(NhsTime.TryParseExact(time.ToString(), out parsedTime, CultureInfo.CurrentCulture), string.Format(CultureInfo.InvariantCulture, "TryParse failed with time, {0}", time.ToString()));

            Assert.AreEqual <TimeType>(time.TimeType, parsedTime.TimeType, "Parse did not error but TimeType does not match");
            Assert.AreEqual(time.NullIndex, parsedTime.NullIndex, "Parse did not error but NullIndex does not match");
        }
コード例 #19
0
ファイル: TimeTest.cs プロジェクト: odnodn/mscui
        public void ParseApproximate()
        {
            System.DateTime baseDateTime = System.DateTime.Now;

            NhsTime time = new NhsTime(baseDateTime, true);

            Assert.AreEqual <TimeType>(time.TimeType, TimeType.Approximate, "TimeType should be Approxinmate when set to a date");

            NhsTime parsedTime;

            Assert.IsTrue(NhsTime.TryParseExact(time.ToString(), out parsedTime, CultureInfo.CurrentCulture), string.Format(CultureInfo.InvariantCulture, "TryParse failed with time, {0}", time.ToString()));

            Assert.AreEqual(time.TimeType, parsedTime.TimeType, "Parse did not error but TimeType does not match");
            Assert.AreEqual <string>(time.TimeValue.ToString("HH:mm", CultureInfo.InvariantCulture), parsedTime.TimeValue.ToString("HH:mm", CultureInfo.InvariantCulture), "Parse did not error but TimeValue does not match");
        }
コード例 #20
0
        /// <summary>
        ///  Builds a dictionary of name/value pairs
        /// </summary>
        /// <param name="obj">The Object to serialize</param>
        /// <param name="serializer">The JavaScriptSerializer responsible for the serialization</param>
        /// <returns>An IDictionary object that contains key/value pairs that represent the object�s data</returns>
        public override IDictionary <string, object> Serialize(object obj, JavaScriptSerializer serializer)
        {
            NhsTime time = obj as NhsTime;

            if (time != null)
            {
                //// Create the representation
                Dictionary <string, object> result = new Dictionary <string, object>();

                result.Add("nullIndex", time.NullIndex);
                result.Add("timeType", time.TimeType);
                result.Add("timeValue", time.TimeValue);

                return(result);
            }

            return(new Dictionary <string, object>());
        }
コード例 #21
0
ファイル: TimeTest.cs プロジェクト: odnodn/mscui
        public void ToStringApproximate()
        {
            DateTime             baseDateTime = System.DateTime.Now;
            GlobalizationService gc           = new GlobalizationService();

            NhsTime time = new NhsTime(baseDateTime, true);

            Assert.AreEqual(string.Format(CultureInfo.CurrentCulture, "{0} {1}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.Approximate, baseDateTime.ToString(gc.ShortTimePattern, CultureInfo.CurrentCulture)), time.ToString());

            Assert.AreEqual(string.Format(CultureInfo.CurrentCulture, "{0} {1}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.Approximate, baseDateTime.ToString(gc.ShortTimePattern, CultureInfo.CurrentCulture)), time.ToString(true));

            time = new NhsTime(baseDateTime);

            time.TimeType = TimeType.Approximate;

            Assert.AreEqual(string.Format(CultureInfo.CurrentCulture, "{0} {1}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.Approximate, baseDateTime.ToString(gc.ShortTimePattern, CultureInfo.CurrentCulture)), time.ToString());

            Assert.AreEqual(string.Format(CultureInfo.CurrentCulture, "{0} {1}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.Approximate, baseDateTime.ToString(gc.ShortTimePattern, CultureInfo.CurrentCulture)), time.ToString(true));
        }
コード例 #22
0
        /// <summary>
        /// Refresh the text displayed in the text box.
        /// </summary>
        private void RefreshDisplayText()
        {
            NhsTime value = this.Value;

            string[] nullStrings = this.NullStrings;

            if (value.TimeType != TimeType.NullIndex || nullStrings == null ||
                value.NullIndex < 0 || value.NullIndex >= nullStrings.Length)
            {
                this.TextBox.Text = value.ToString(
                    false,
                    CultureInfo.CurrentCulture,
                    this.DisplaySeconds,
                    this.Display12Hour,
                    this.DisplayAMPM);
            }
            else
            {
                this.TextBox.Text = nullStrings[value.NullIndex];
            }
        }
コード例 #23
0
ファイル: TimeTest.cs プロジェクト: odnodn/mscui
        public void AddAddHour()
        {
            DateTime baseDateTime = DateTime.Now; // :-)

            NhsTime time = new NhsTime(baseDateTime);

            Assert.IsTrue(NhsTime.IsAddValid(string.Format(CultureInfo.CurrentCulture, "+1{0}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.HoursUnit)));

            time.Add(string.Format(CultureInfo.CurrentCulture, "+1{0}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.HoursUnit));

            Assert.AreEqual(time.TimeValue, baseDateTime.AddHours(1));

            // Now try it without the "+", this will check that + is the default
            // Reset
            baseDateTime = DateTime.Now;
            time         = new NhsTime(baseDateTime);

            Assert.IsTrue(NhsTime.IsAddValid(string.Format(CultureInfo.CurrentCulture, "1{0}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.HoursUnit)), "1h was not recognised as a Time Add Instruction");

            time.Add(string.Format(CultureInfo.CurrentCulture, "1{0}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.HoursUnit));

            Assert.AreEqual(time.TimeValue, baseDateTime.AddHours(1));
        }
コード例 #24
0
ファイル: TimeTest.cs プロジェクト: odnodn/mscui
        public void ParseEmptyString()
        {
            NhsTime time = NhsTime.ParseExact(string.Empty, CultureInfo.CurrentCulture);

            Assert.AreEqual <TimeType>(time.TimeType, TimeType.Null, "Parse did not error but TimeType does not match");
        }
コード例 #25
0
ファイル: TimeTest.cs プロジェクト: odnodn/mscui
        public void ParseWithSeconds()
        {
            NhsTime time = NhsTime.ParseExact("10:30:23", CultureInfo.CurrentCulture);

            Assert.AreEqual <int>(time.TimeValue.Second, 23, "Parse failed to set seconds");
        }
コード例 #26
0
ファイル: TimeTest.cs プロジェクト: rbirkby/mscui
        public void ParseNullIndex()
        {
            NhsTime time = new NhsTime();

            time.TimeType = TimeType.NullIndex;
            time.NullIndex = 4;           
            
            NhsTime parsedTime;

            Assert.IsTrue(NhsTime.TryParseExact(time.ToString(), out parsedTime, CultureInfo.CurrentCulture), string.Format(CultureInfo.InvariantCulture, "TryParse failed with time, {0}", time.ToString()));

            Assert.AreEqual<TimeType>(time.TimeType, parsedTime.TimeType, "Parse did not error but TimeType does not match");
            Assert.AreEqual(time.NullIndex, parsedTime.NullIndex, "Parse did not error but NullIndex does not match");
        }
コード例 #27
0
ファイル: TimeTest.cs プロジェクト: rbirkby/mscui
        public void IsNullProperty()
        {
            NhsTime time = new NhsTime();

            // default datetype is exact
            Assert.IsFalse(time.IsNull);
            time.TimeType = TimeType.Null;
            Assert.IsTrue(time.IsNull);
        }
コード例 #28
0
ファイル: TimeTest.cs プロジェクト: odnodn/mscui
 public void ParseShouldFail()
 {
     NhsTime.ParseExact("barf", CultureInfo.CurrentCulture);
 }
コード例 #29
0
ファイル: TimeTest.cs プロジェクト: odnodn/mscui
 public void NullSourceTimeAddTest()
 {
     NhsTime.Add(null, string.Format(CultureInfo.CurrentCulture, "+1{0}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.HoursUnit));
 }
コード例 #30
0
ファイル: TimeTest.cs プロジェクト: rbirkby/mscui
        public void ParseNotApproximateTruePassedToToString()
        {
            System.DateTime baseDateTime = System.DateTime.Now;
            
            NhsTime time = new NhsTime(baseDateTime);

            Assert.AreEqual<TimeType>(time.TimeType, TimeType.Exact, "TimeType should be Exact when set to a date");

            NhsTime.ParseExact(time.ToString(true), CultureInfo.CurrentCulture);
        }
コード例 #31
0
        /// <summary>
        /// Converts the provided dictionary into an object of the specified type
        /// </summary>
        /// <param name="dictionary">An IDictionary instance of property data stored as name/value pairs</param>
        /// <param name="type">The Type of the resulting object</param>
        /// <param name="serializer">The JavaScriptSerializer instance</param>
        /// <returns>The deserialized Object</returns>
        /// <remarks>KeyboardShortcut is never sent back up to the server so we do not support Deserialization</remarks>
        /// <exception cref="NotImplementedException">Always returns this exception</exception>
        public override object Deserialize(IDictionary<string, object> dictionary, Type type, JavaScriptSerializer serializer)
        {
            NhsTime deserialisationTarget = new NhsTime();

            deserialisationTarget.NullIndex = (dictionary.ContainsKey("_nullIndex") ? (int)dictionary["_nullIndex"] : (int)dictionary["nullIndex"]);            
            deserialisationTarget.TimeType = (dictionary.ContainsKey("_timeType") ? (TimeType)dictionary["_timeType"] : (TimeType)dictionary["timeType"]);
            deserialisationTarget.TimeValue = (dictionary.ContainsKey("_timeValue") ? ((DateTime)dictionary["_timeValue"]).ToLocalTime() : ((DateTime)dictionary["timeValue"]).ToLocalTime());

            return deserialisationTarget;
        }
コード例 #32
0
ファイル: TimeTest.cs プロジェクト: rbirkby/mscui
 public void NullInstructionTimeOneParameterAddTest()
 {
     DateTime baseDateTime = DateTime.Now;
     NhsTime time = new NhsTime(baseDateTime);
     time.Add(null);
 }
コード例 #33
0
ファイル: TimeInputBoxExtender.cs プロジェクト: rbirkby/mscui
        /// <summary>‍
        /// Handle loading of client state
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">args</param>
        private void ExtenderClientStateLoaded(object sender, EventArgs e)
        {
            if (this.ClientState != null)
            {
                JavaScriptSerializer jss = new JavaScriptSerializer();
                jss.RegisterConverters(new JavaScriptConverter[] { new NhsTimeJavascriptConverter() });

                this.state = jss.Deserialize<TimeInputClientState>(ClientState);
                
                this.value = this.state.Value;
            }
        }
コード例 #34
0
ファイル: NhsTimeEditor.cs プロジェクト: rbirkby/mscui
        private void ValueTextBox_Leave(object sender, EventArgs e)
        {
            NhsTime time;
            if (NhsTime.TryParseExact(this.valueTextBox.Text, out time, CultureInfo.CurrentCulture))
            {
                this.value = time;

                if (this.value.TimeType == TimeType.Exact && this.approxCheckbox.Checked)
                {
                    this.value.TimeType = TimeType.Approximate;
                }
            }

            this.valueTextBox.Text = this.value.ToString(false);

            if (this.value.TimeType != TimeType.Approximate)
            {
                this.approxCheckbox.Checked = false;
            }
        }
コード例 #35
0
ファイル: TimeTest.cs プロジェクト: rbirkby/mscui
        public void ToStringDisplaySeconds()
        {
            NhsTime time = new NhsTime();

            string formattedTime = time.ToString(false, CultureInfo.CurrentCulture, true, false, false);
            TimeSpan parsedTimeSpan = TimeSpan.Parse(formattedTime);

            Assert.AreEqual<int>(parsedTimeSpan.Seconds, time.TimeValue.Second, "NhsTime DisplaySeconds incorrect");
        }
コード例 #36
0
ファイル: TimeInputBox.cs プロジェクト: rbirkby/mscui
 /// <summary>
 /// Resets the control's state fields to their default value.
 /// </summary>
 private void ResetFields()
 {
     this.currentField = Field.Hours;
     this.currentMode = InputMode.Simple;
     this.allowTimeTypeChange = true;
     this.currentValue = this.Value;
     this.EditingTimeType = this.TimeType;
     this.invalidFormat = false;
     this.LoadResources();
     this.SelectCurrentField();
 }
コード例 #37
0
ファイル: TimeTest.cs プロジェクト: rbirkby/mscui
        public void ToStringApproximate()
        {
            DateTime baseDateTime = System.DateTime.Now;
            GlobalizationService gc = new GlobalizationService();

            NhsTime time = new NhsTime(baseDateTime, true);

            Assert.AreEqual(string.Format(CultureInfo.CurrentCulture, "{0} {1}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.Approximate, baseDateTime.ToString(gc.ShortTimePattern, CultureInfo.CurrentCulture)), time.ToString());

            Assert.AreEqual(string.Format(CultureInfo.CurrentCulture, "{0} {1}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.Approximate, baseDateTime.ToString(gc.ShortTimePattern, CultureInfo.CurrentCulture)), time.ToString(true));

            time = new NhsTime(baseDateTime);

            time.TimeType = TimeType.Approximate;

            Assert.AreEqual(string.Format(CultureInfo.CurrentCulture, "{0} {1}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.Approximate, baseDateTime.ToString(gc.ShortTimePattern, CultureInfo.CurrentCulture)), time.ToString());

            Assert.AreEqual(string.Format(CultureInfo.CurrentCulture, "{0} {1}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.Approximate, baseDateTime.ToString(gc.ShortTimePattern, CultureInfo.CurrentCulture)), time.ToString(true));                                                
        }
コード例 #38
0
ファイル: TimeTest.cs プロジェクト: rbirkby/mscui
        public void ParseApproximate()
        {
            System.DateTime baseDateTime = System.DateTime.Now;

            NhsTime time = new NhsTime(baseDateTime, true);

            Assert.AreEqual<TimeType>(time.TimeType, TimeType.Approximate, "TimeType should be Approxinmate when set to a date");

            NhsTime parsedTime;

            Assert.IsTrue(NhsTime.TryParseExact(time.ToString(), out parsedTime, CultureInfo.CurrentCulture), string.Format(CultureInfo.InvariantCulture, "TryParse failed with time, {0}", time.ToString()));

            Assert.AreEqual(time.TimeType, parsedTime.TimeType, "Parse did not error but TimeType does not match");
            Assert.AreEqual<string>(time.TimeValue.ToString("HH:mm", CultureInfo.InvariantCulture), parsedTime.TimeValue.ToString("HH:mm", CultureInfo.InvariantCulture), "Parse did not error but TimeValue does not match");
        }
コード例 #39
0
ファイル: TimeTest.cs プロジェクト: rbirkby/mscui
 public void InvalidInstructionTimeAddTest()
 {
     DateTime baseDateTime = DateTime.Now;
     NhsTime time = new NhsTime(baseDateTime);
     NhsTime.Add(time, string.Format(CultureInfo.CurrentCulture, "+1{0}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.resourceCulture));
 }
コード例 #40
0
ファイル: TimeTest.cs プロジェクト: rbirkby/mscui
        public void AddSubtract2HoursAdd25Minutes()
        {
            DateTime nowAsItWasAtTheStartofTheTest = DateTime.Now; // :-)

            NhsTime time = new NhsTime(nowAsItWasAtTheStartofTheTest);

            string addInstruction = string.Format(CultureInfo.CurrentCulture, "-2{0}+25{1}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.HoursUnit, NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.MinutesUnit);

            Assert.IsTrue(NhsTime.IsAddValid(addInstruction), string.Format(CultureInfo.CurrentCulture, "{0} was not recognised as a Time Add Instruction", addInstruction));

            time.Add(addInstruction);

            Assert.AreEqual(nowAsItWasAtTheStartofTheTest.AddHours(-2).AddMinutes(25), time.TimeValue);
        }       
コード例 #41
0
ファイル: TimeTest.cs プロジェクト: rbirkby/mscui
 public void NullInstructionTimeTwoParametersAddTest()
 {
     DateTime baseDateTime = DateTime.Now;
     NhsTime time = new NhsTime(baseDateTime);
     NhsTime.Add(time, null);
 }
コード例 #42
0
ファイル: TimeTest.cs プロジェクト: rbirkby/mscui
        public void ToStringDisplay12Hour()
        {
            int hours = 14;
            DateTime dateTime = new DateTime(2006, 1, 1, hours, 20, 11);
            NhsTime time = new NhsTime(dateTime);

            string formattedTime = time.ToString(false, CultureInfo.CurrentCulture, false, true, false);
            DateTime parsedDateTime = DateTime.Parse(formattedTime, CultureInfo.CurrentCulture);

            Assert.AreEqual<int>(parsedDateTime.Hour, hours - 12, "NhsTime Display12Hour incorrect");
        }
コード例 #43
0
ファイル: TimeTest.cs プロジェクト: rbirkby/mscui
        public void AddAddHoursAndMinutes()
        {
            DateTime baseDateTime = DateTime.Now; // :-)

            NhsTime time = new NhsTime(baseDateTime);

            string addInstruction = string.Format(CultureInfo.CurrentCulture, "+1{0}+5{1}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.HoursUnit, NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.MinutesUnit);

            Assert.IsTrue(NhsTime.IsAddValid(addInstruction), string.Format(CultureInfo.CurrentCulture, "{0} was not recognised as an Time Add Instruction", addInstruction));

            time.Add(addInstruction);

            Assert.AreEqual(time.TimeValue, baseDateTime.AddHours(1).AddMinutes(5), string.Format(CultureInfo.CurrentCulture, "Failed using {0}", addInstruction));

            // Now try without +

            // Reset
            baseDateTime = DateTime.Now;
            time = new NhsTime(baseDateTime);

            // reinitialise add instructionstring as instruction without operands

            addInstruction = string.Format(CultureInfo.CurrentCulture, "1{0}5{1}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.HoursUnit, NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.MinutesUnit);

            Assert.IsTrue(NhsTime.IsAddValid(addInstruction), string.Format(CultureInfo.CurrentCulture, "{0} was not recognised as an Time Add Instruction", addInstruction));

            time.Add(addInstruction);

            Assert.AreEqual(time.TimeValue, baseDateTime.AddHours(1).AddMinutes(5), string.Format(CultureInfo.CurrentCulture, "Failed using {0}", addInstruction));
        }
コード例 #44
0
ファイル: TimeInputBox.cs プロジェクト: rbirkby/mscui
        /// <summary>
        /// Refresh the text displayed in the text box.
        /// </summary>
        /// <returns>
        /// Status of update.
        /// </returns>
        private bool ValidateAndUpdateValue()
        {
            NhsTime result;
            bool status = true;
            bool containedPM = this.ISPMContained();
            this.SetValid();
            this.recentSelectionStart = this.txtInput.SelectionStart;
            this.recentSelectionLength = this.txtInput.SelectionLength;

            // for null index nothing to be done as index is updated while setting.
            if (this.EditingTimeType != TimeType.NullIndex)
            {
                if (NhsTime.IsAddValid(this.txtInput.Text))
                {
                    this.Value.Add(this.txtInput.Text);
                    this.RefreshDisplayText();
                    this.ResetFields();
                    return status;
                }
                else if (NhsTime.TryParseExact(this.txtInput.Text, out result, CultureInfo.CurrentCulture))
                {
                    // Handles an exception case, TryParse always returns the text in am no matter
                    // input contains am or pm.
                    if (containedPM && result.TimeValue.Hour < 12)
                    {
                        result.TimeValue = result.TimeValue.AddHours(12);
                    }

                    this.Value = result;
                    this.invalidFormat = false;
                }
                else
                {
                    this.SetInvalid(ref status);
                } 
            }

            this.allowTimeTypeChange = true;
            this.currentValue = this.Value;
            this.EditingTimeType = this.TimeType;
            this.currentMode = InputMode.Simple;
            this.txtInput.SelectionStart = this.txtInput.TextLength;
            this.txtInput.SelectionLength = 0;
            return status;
        }
コード例 #45
0
 /// <summary>
 /// Set the value to 23:59.
 /// </summary>
 /// <param name="sender">Sender of the event.</param>
 /// <param name="e">Event args for the event.</param>
 private void SetTo2359Button_Click(object sender, EventArgs e)
 {
     this.timeInputBox3.Value = NhsTime.ParseExact("23:59", CultureInfo.CurrentCulture);
 }
コード例 #46
0
ファイル: TimeTest.cs プロジェクト: odnodn/mscui
 public void NullInstructionTimeIsAddInstructionTest()
 {
     NhsTime.IsAddValid(null);
 }
コード例 #47
0
ファイル: TimeTest.cs プロジェクト: rbirkby/mscui
        public void AddAddHour()
        {
            DateTime baseDateTime = DateTime.Now; // :-)

            NhsTime time = new NhsTime(baseDateTime);

            Assert.IsTrue(NhsTime.IsAddValid(string.Format(CultureInfo.CurrentCulture, "+1{0}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.HoursUnit)));

            time.Add(string.Format(CultureInfo.CurrentCulture, "+1{0}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.HoursUnit));

            Assert.AreEqual(time.TimeValue, baseDateTime.AddHours(1));
                        
            // Now try it without the "+", this will check that + is the default
            // Reset
            baseDateTime = DateTime.Now;
            time = new NhsTime(baseDateTime);

            Assert.IsTrue(NhsTime.IsAddValid(string.Format(CultureInfo.CurrentCulture, "1{0}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.HoursUnit)), "1h was not recognised as a Time Add Instruction");

            time.Add(string.Format(CultureInfo.CurrentCulture, "1{0}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.HoursUnit));

            Assert.AreEqual(time.TimeValue, baseDateTime.AddHours(1));
        }