Pages

Men

rh

7/30/2014

Converts Days Hours Minutes using C#

  #region Fields

            private Int32 daysValue;
            private Int32 hoursValue;
            private Int32 minutesValue;

        #endregion

        #region Properties

            public Int32 DaysValue
            {
                get { return daysValue; }
                set { daysValue = value; }
            }

            public Int32 HoursValue
            {
                get { return hoursValue; }
                set { hoursValue = value; }
            }

            public Int32 MinutesValue
            {
                get { return minutesValue; }
                set { minutesValue = value; }
            }
        #endregion

        #region Methods
            /// <summary>
            /// This method 'ConvertMinutesToDHM' receives a Int32 value +
            /// and converts this value into Days, Hours and Minutes, +
            /// assigns these Days, Hours and Minutes values to a String +
            /// array and returns this array.
            /// </summary>
            /// <param name="ConsolidatedMinutesValue"></param>
            /// <returns></returns>
            public String[] ConvertMinutesToDHM(Int32 ConsolidatedMinutesValue)
            {
                /// The 'ConsolidatedMinutesValue' holds the value for the +
                /// consolidated days, hours and minutes.
                /// The String variable is required for the return value.
                /// The Int32's are used here, as it helps in setting the +
                /// breakpoints while debugging. The Hours(24) and Minutes(60) +
                /// are specified as discreet values and not as (1440) so +
                /// that it is easier to understand.
               
                String[] DHM = new String[3];
                Int32 TemporaryDaysValue;
                Int32 ConsolidatedHoursValue;
                Int32 TemporaryHoursValue;
                Int32 TemporaryMinutesValue;

                /// This variable 'TemporaryDaysValue' holds the value of the +
                /// actual number of Days.
               
                TemporaryDaysValue = ConsolidatedMinutesValue / (24 * 60);
                DHM[0] = TemporaryDaysValue.ToString();

                /// The 'ConsolidatedHoursValue' holds the value of the +
                /// consolidated hours which include hours and minutes.
                /// Deducting the consolidated days value
                /// ('TemporaryDaysValue * 24 * 60') from the consolidated +
                /// minutes give the 'ConsolidatedHoursValue' value.
                /// The 'TemporaryHoursValue' holds the value of the +
                /// actual number of Hours
               
                ConsolidatedHoursValue = (ConsolidatedMinutesValue -  (TemporaryDaysValue * 24 * 60));
                TemporaryHoursValue = ConsolidatedHoursValue / 60;
                DHM[1] = TemporaryHoursValue.ToString();

                /// The 'TemporaryMinutesValue' holds the value of the +
                /// actual number of Minutes. This is obtained by +
                /// deducting the Consolidated Hours Value +
                /// ('TemporaryHoursValue * 60') and the +
                /// Consolidated Days Value ('TemporaryDaysValue * 24 * 60') +
                /// from the Consolidated Minutes Value.
               
                TemporaryMinutesValue = ConsolidatedMinutesValue - (TemporaryDaysValue * 24 * 60) - (TemporaryHoursValue * 60) ;
                DHM[2] = TemporaryMinutesValue.ToString(); ;
               
                return DHM;

            }
            public Int32 ConvertDHMToMinutes(Int32 DaysValue, Int32 HoursValue, Int32 MinutesValue)
            {
                Int32 ConsolidatedDaysValue = 0;
                Int32 ConsolidatedHoursValue = 0;
                Int32 ConsolidateMinutesValue = 0;

                ConsolidatedDaysValue = DaysValue * 24 * 60;
                ConsolidatedHoursValue = HoursValue * 60;
                ConsolidateMinutesValue = ConsolidatedDaysValue + ConsolidatedHoursValue + MinutesValue;

                return ConsolidateMinutesValue;

            }
            public String[] ConvertMinutesToDH(Int32 ConsolidatedMinutesValue)
            {
                /// The 'ConsolidatedMinutesValue' holds the value for the +
                /// consolidated days, hours and minutes.
                /// The String variable is required for the return value.
                /// The Int32's are used here, as it helps in setting the +
                /// breakpoints while debugging. The Hours(24) and Minutes(60) +
                /// are specified as discreet values and not as (1440) so +
                /// that it is easier to understand.

                String[] DHM = new String[2];
                Int32 TemporaryDaysValue;
                Int32 ConsolidatedHoursValue;
                Int32 TemporaryHoursValue;
                //Int32 TemporaryMinutesValue;

                /// This variable 'TemporaryDaysValue' holds the value of the +
                /// actual number of Days.

                TemporaryDaysValue = ConsolidatedMinutesValue / (24 * 60);
                DHM[0] = TemporaryDaysValue.ToString();

                /// The 'ConsolidatedHoursValue' holds the value of the +
                /// consolidated hours which include hours and minutes.
                /// Deducting the consolidated days value
                /// ('TemporaryDaysValue * 24 * 60') from the consolidated +
                /// minutes give the 'ConsolidatedHoursValue' value.
                /// The 'TemporaryHoursValue' holds the value of the +
                /// actual number of Hours

                ConsolidatedHoursValue = (ConsolidatedMinutesValue - (TemporaryDaysValue * 24 * 60));
                TemporaryHoursValue = ConsolidatedHoursValue / 60;
                DHM[1] = TemporaryHoursValue.ToString();

                /// The 'TemporaryMinutesValue' holds the value of the +
                /// actual number of Minutes. This is obtained by +
                /// deducting the Consolidated Hours Value +
                /// ('TemporaryHoursValue * 60') and the +
                /// Consolidated Days Value ('TemporaryDaysValue * 24 * 60') +
                /// from the Consolidated Minutes Value.

                //TemporaryMinutesValue = ConsolidatedMinutesValue - (TemporaryDaysValue * 24 * 60) - (TemporaryHoursValue * 60);
                //DHM[2] = TemporaryMinutesValue.ToString(); ;

                return DHM;

            }
        #endregion

No comments :

Post a Comment