Beispiel #1
0
        public string ToString(DateFormatTypes dateFormatType)
        {
            string format = string.Empty;

            switch (dateFormatType)
            {
            case DateFormatTypes.yyyyMMdd:
                format = "{0:0000}/{1:00}/{2:00}";
                break;

            case DateFormatTypes.ddMMyyyy:
                format = "{2:00}/{1:00}/{0:0000}";
                break;

            case DateFormatTypes.MMddyyyy:
                format = "{1:00}/{2:00}/{0:0000}";
                break;

            case DateFormatTypes.yyyyMM:
                format = "{0:0000}/{1:00}";
                break;
            }

            return(string.Format(format, _year, _month, _day));
        }
Beispiel #2
0
        private bool ConvertStringToNepaliDate(string nepaliDate, DateFormatTypes dateFormatType)
        {
            int tmp = 0;

            switch (dateFormatType)
            {
            case DateFormatTypes.yyyyMMdd:
                //convert the date in YYYY/MM/DD format eg. 2065/03/05 to day, month and year.
                if (nepaliDate.Trim().Length == 10)
                {
                    tmp = Conversion.ToInt32(nepaliDate.Substring(0, 4));

                    //extract year.
                    if (DateConvertor.IsValidYear(tmp, true))
                    {
                        _year = tmp;
                    }
                    else
                    {
                        throw new Exception("Date format must be YYYY/MM/DD. eg. 2065/03/05");
                    }

                    //extract month:
                    tmp = Conversion.ToInt32(nepaliDate.Substring(5, 2));
                    if (DateConvertor.GetDaysInNepaliMoth(_year, tmp) > 0)
                    {
                        _month = tmp;
                    }
                    else
                    {
                        throw new Exception("Date format must be YYYY/MM/DD. eg. 2065/03/05");
                    }

                    //extract day:
                    tmp = Conversion.ToInt32(nepaliDate.Substring(8, 2));
                    if (tmp > 0 &&
                        tmp <= DateConvertor.GetDaysInNepaliMoth(_year, _month))
                    {
                        _day = tmp;
                    }
                    else
                    {
                        _day = DateConvertor.GetDaysInNepaliMoth(_year, _month);     //current month days... if not exis
                    }
                    //throw new Exception("Date format must be YYYY/MM/DD. eg. 2065/03/05");
                    return(true);
                }
                else
                {
                    throw new Exception("Date format must be YYYY/MM/DD. eg. 2065/03/05");
                }

            //break;
            default:
                throw new Exception("Other date formats not supported");
            }
            //return false;
        }
Beispiel #3
0
        /// <summary>
        /// Check if the given date is nepali date or not and returns to if a valid date.
        /// </summary>
        /// <param name="nepaliDate"></param>
        /// <param name="dateFormatType"></param>
        /// <returns>Returns true if valid date else false.</returns>
        public static bool IsValidDate(string nepaliDate, DateFormatTypes dateFormatType)
        {
            int tmp = 0;

            switch (dateFormatType)
            {
            case DateFormatTypes.yyyyMMdd:
                //convert the date in YYYY/MM/DD format eg. 2065/03/05 to day, month and year.
                if (nepaliDate.Trim().Length == 10)
                {
                    tmp = Conversion.ToInt32(nepaliDate.Substring(0, 4));
                    int yr, mnth, days;
                    //extract year.
                    if (DateConvertor.IsValidYear(tmp, true))
                    {
                        yr = tmp;
                    }
                    else
                    {
                        return(false);
                    }

                    //extract month:
                    tmp = Conversion.ToInt32(nepaliDate.Substring(5, 2));
                    if (DateConvertor.GetDaysInNepaliMoth(yr, tmp) > 0)
                    {
                        mnth = tmp;
                    }
                    else
                    {
                        return(false);
                    }

                    //extract day:
                    tmp = Conversion.ToInt32(nepaliDate.Substring(8, 2));
                    if (tmp > 0 &&
                        tmp <= DateConvertor.GetDaysInNepaliMoth(yr, mnth))
                    {
                        days = tmp;
                    }
                    else
                    {
                        return(false);
                    }

                    return(true);
                }
                //throw new Exception("Date format must be YYYY/MM/DD. eg. 2065/03/05");
                break;

            default:
                throw new Exception("Other date formats not supported");
            }
            return(false);
        }