public void testDayNumberFromConvertedDateToBS()
        {
            NepaliDate nepali_date = new NepaliDate();

            nepali_date = dc.ToBS(new DateTime(2018, 03, 03));
            Assert.AreEqual(7, nepali_date.dayNumber);

            nepali_date = dc.ToBS(new DateTime(2018, 03, 06));
            Assert.AreEqual(3, nepali_date.dayNumber);

            nepali_date = dc.ToBS(new DateTime(2000, 01, 04));
            Assert.AreEqual(3, nepali_date.dayNumber);

            nepali_date = dc.ToBS(new DateTime(1946, 12, 16));
            Assert.AreEqual(2, nepali_date.dayNumber);

            nepali_date = dc.ToBS(new DateTime(1996, 08, 15));
            Assert.AreEqual(5, nepali_date.dayNumber);

            nepali_date = dc.ToBS(new DateTime(1973, 08, 15));
            Assert.AreEqual(4, nepali_date.dayNumber);

            nepali_date = dc.ToBS(new DateTime(1980, 08, 15));
            Assert.AreEqual(6, nepali_date.dayNumber);
        }
예제 #2
0
        /// <summary>
        /// constructor
        /// </summary>
        /// <param name="fiscalyear">Fiscal year in the format yyyy/yyyy, eg 2064/2065</param>
        public FiscalYear(string fiscalyear)
        {
            if (fiscalyear == null)
            {
                throw new Exception("Invalid fiscal year passed. passed value = " + fiscalyear);
            }

            if (fiscalyear.Trim().Length == 0)
            {
                return;
            }

            if (!(fiscalyear.Trim().Length == 9 || fiscalyear.Trim().Length == 7))
            {
                throw new Exception("Invalid fiscal year passed. passed value = " + fiscalyear);
            }
            string[] years = fiscalyear.Split(new char[] { '/' });

            if (years.Length != 2)
            {
                throw new Exception("Invalid fiscal year passed. passed value = " + fiscalyear);
            }

            NepaliDate fromNepaliDate = new NepaliDate(years[0] + "/04/01");

            if (years[1].Length == 2)
            {
                years[1] = "20" + years[1];
            }
            NepaliDate toNepaliDate = new NepaliDate(years[1] + "/04/01");

            toNepaliDate = toNepaliDate.AddDays(-1);

            InitializeClass(fromNepaliDate, toNepaliDate, -1);
        }
예제 #3
0
 private void InitializeClass(NepaliDate fromNepaliDate, NepaliDate toNepaliDate, int fiscalYearID)
 {
     _fromNepaliDate = fromNepaliDate;
     _toNepaliDate   = toNepaliDate;
     _fiscalYearID   = fiscalYearID;
     //now convert the Nepali Date to english date
     _fromEnglishDate = DateConvertor.GetEnglishDate(_fromNepaliDate.ToString());
     _toEnglishDate   = DateConvertor.GetEnglishDate(_toNepaliDate.ToString());
 }
예제 #4
0
        public static NepaliDate GetNepaliDate(DateTime enDate)
        {
            #region Core Algorithm for Nepali date conversion
            //Getting Nepali date data for Nepali date calculation
            int[] npDateData = NepaliDateDataArray.GetNepaliDateDataArray(enDate.Year);

            //Getting English day of the year
            int enDayOfYear = enDate.DayOfYear;

            //Initializing Nepali Year from the data
            int npYear = npDateData[0];

            //Initializing Nepali month to Poush (9)
            //This is because English date Jan 1 always fall in Poush month of Nepali Calendar, which is 9th month of Nepali calendar
            int npMonth = 9;

            //Initializing Nepali DaysInMonth with total days in the month of Poush
            int npDaysInMonth = npDateData[2];

            //Initializing temp nepali days
            //This is sum of total days in each Nepali month starting Jan 1 in Nepali month Poush
            //Note: for the month Poush, only counting days after Jan 1
            //***** This is the key field to calculate Nepali date *****
            int npTempDays = npDateData[2] - npDateData[1] + 1;

            //Looping through Nepali date data array to get exact Nepali month, Nepali year & Nepali daysInMonth information
            for (int i = 3; enDayOfYear > npTempDays; i++)
            {
                npTempDays   += npDateData[i];
                npDaysInMonth = npDateData[i];
                npMonth++;

                if (npMonth > 12)
                {
                    npMonth -= 12;
                    npYear++;
                }
            }

            //Calculating Nepali day
            int npDay = npDaysInMonth - (npTempDays - enDayOfYear);

            #endregion

            #region Constructing and returning NepaliDate object
            //Returning back NepaliDate object with all the date details
            NepaliDate npDate = new NepaliDate();
            npDate.npDate        = String.Format("{0}/{1}/{2}", npYear, npMonth, npDay);
            npDate.npYear        = npYear;
            npDate.npMonth       = npMonth;
            npDate.npDay         = npDay;
            npDate.npDaysInMonth = npDaysInMonth;

            return(npDate);

            #endregion
        }
예제 #5
0
        public void LeaveYearCreate(LeaveYearsDTOs Record)
        {
            LeaveYear Data = LeaveYearsMapper.LeaveYearsDtoToLeaveYears(Record);

            Data.YearCurrent = Record.Isactive;
            NepaliDate StartNepali = GeneralServices.GetNepaliDate(Convert.ToDateTime(Data.YearStartDate));
            NepaliDate EndNepali   = GeneralServices.GetNepaliDate(Convert.ToDateTime(Data.YearEndDate));

            Data.YearStartDateNp = StartNepali.npDate;
            Data.YearEndDateNp   = EndNepali.npDate;
            _unitOfWork.LeaveYearRepository.Create(Data);
        }
        public ActionResult Index(string Date)
        {
            NepaliDate nDate   = new NepaliDate();
            string     nepDate = "";

            if (Date != null && Date.Length > 0)
            {
                DateTime engDate = Convert.ToDateTime(Date);
                nepDate = nDate.getNepaliDate(engDate);
            }
            ViewBag.NepaliDate  = nepDate;
            ViewBag.EnglishDate = Date;
            return(View());
        }
        public void testDayNameFromConvertedDateToBS()
        {
            NepaliDate nepali_date = new NepaliDate();

            nepali_date = dc.ToBS(new DateTime(2018, 03, 06));
            Assert.AreEqual("tuesday", nepali_date.dayName.ToLower());
            nepali_date = dc.ToBS(new DateTime(2000, 01, 04));
            Assert.AreEqual("tuesday", nepali_date.dayName.ToLower());

            nepali_date = dc.ToBS(new DateTime(1946, 12, 16));
            Assert.AreEqual("monday", nepali_date.dayName.ToLower());

            nepali_date = dc.ToBS(new DateTime(1996, 08, 15));
            Assert.AreEqual("thursday", nepali_date.dayName.ToLower());

            nepali_date = dc.ToBS(new DateTime(1973, 08, 15));
            Assert.AreEqual("wednesday", nepali_date.dayName.ToLower());

            nepali_date = dc.ToBS(new DateTime(1980, 08, 15));
            Assert.AreEqual("friday", nepali_date.dayName.ToLower());
        }
예제 #8
0
        public int getFiscalYear(DateTime givenDate)
        {
            // first find year
            if ((givenDate == null))
            {
                givenDate = DateTime.Now;
            }

            NepaliDate nepaliDate = dateConverter.ToBS(givenDate);
            int        Month      = nepaliDate.npMonth;
            int        Day        = nepaliDate.npDay;
            int        Year       = nepaliDate.npYear;

            if ((Month >= 4))
            {
                return(Year);
            }
            else
            {
                return(Year - 1);
            }
        }
예제 #9
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="fromNepaliDate">Nepali Date from which the fiscal year starts.</param>
 /// <param name="toNepaliDate">Nepali Date in which the fiscal year ends.</param>
 /// <param name="fiscalYearID">Fiscal year ID</param>
 public FiscalYear(NepaliDate fromNepaliDate, NepaliDate toNepaliDate, int fiscalYearID)
 {
     InitializeClass(fromNepaliDate, toNepaliDate, fiscalYearID);
 }
예제 #10
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="fromNepaliDate">Nepali Date from which the fiscal year starts.</param>
 /// <param name="toNepaliDate">Nepali Date in which the fiscal year ends.</param>
 public FiscalYear(NepaliDate fromNepaliDate, NepaliDate toNepaliDate)
 {
     InitializeClass(fromNepaliDate, toNepaliDate, 0);
 }
 public void setup()
 {
     nepaliDate = new NepaliDate();
 }
예제 #12
0
        public NepaliDate ToBS(DateTime gDate, NepaliDate.DateFormats date_format = NepaliDate.DateFormats.yMd)
        {
            gDate = gDate.Date;

            //Breaking given english date
            int yy = 0;
            int mm = 0;
            int dd = 0;

            yy = gDate.Year;
            mm = gDate.Month;
            dd = gDate.Day;

            //English month data
            int[] month = new int[] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

            int[] lmonth = new int[] { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

            int def_eyy     = 0;
            int def_nyy     = 0;
            int def_nmm     = 0;
            int def_ndd     = 0;
            int total_eDays = 0;
            int total_nDays = 0;
            int a           = 0;
            int m           = 0;
            int y           = 0;
            int i           = 0;
            int j           = 0;

            //Initialize english date
            Tuple <int[], int[], int> initializationDates = conversionStartDateData.getClosestEnglishDateAndNepaliDate(gDate);

            int[] english_init_date = initializationDates.Item1;
            int[] nepali_init_date  = initializationDates.Item2;
            // def_eyy = 1944;
            def_eyy = english_init_date[0];

            //Equivalent nepali date
            def_nyy = nepali_init_date[0];
            def_nmm = nepali_init_date[1];
            def_ndd = nepali_init_date[2];

            //Initializations
            total_eDays = 0;
            total_nDays = 0;
            a           = 0;
            m           = 0;
            i           = 0;
            j           = 0;

            //count total number of english days using standard date functions

            total_eDays = Convert.ToInt32((gDate - new DateTime(def_eyy, 01, 01)).TotalDays) + 1;

            //below i is the starting nepali year, used in looping to loop through years above the specified year
            i           = def_nyy;
            j           = def_nmm;
            total_nDays = def_ndd;
            m           = def_nmm;
            y           = def_nyy;

            //Count nepali date from array
            while ((!(total_eDays == 0)))
            {
                a            = nepaliDateData.getLastDayOfMonthNep(i, j);
                total_nDays += 1;

                if ((total_nDays > a))
                {
                    m          += 1;
                    total_nDays = 1;
                    j          += 1;
                }
                if ((m > 12))
                {
                    y += 1;
                    m  = 1;
                }

                if ((j > 12))
                {
                    j  = 1;
                    i += 1;
                }
                total_eDays -= 1;
            }

            NepaliDate nep_date = new NepaliDate();

            nep_date.npDay         = total_nDays;
            nep_date.npDaysInMonth = a;
            nep_date.npMonth       = m;
            nep_date.npYear        = y;
            //1 is added since we are using Sunday as 1 although it is 0
            nep_date.dayNumber = (int)gDate.DayOfWeek + 1;
            nep_date.dayName   = gDate.DayOfWeek.ToString();
            nep_date.setFormattedDate(y, m, total_nDays, date_format);
            return(nep_date);
        }
        static void Main(string[] args)
        {
            var yearObject = new Dictionary <string, object>();

            var dateConverterService = DateConverter.Core.Service_Factory.DateConverterFactory.getDateConverterService();

            DateTime englishStartDate = dateConverterService.ToAD("01/01/2002").getFormattedDate();

            Console.WriteLine($"Starting English Date: {englishStartDate}");

            List <int> yearsList  = new List <int>();
            List <int> monthsList = new List <int>();

            var monthDaysData = new List <DayObjectDataModel>();

            while (englishStartDate <= new DateTime(2033, 12, 12))
            {
                NepaliDate nepaliDate   = dateConverterService.ToBS(englishStartDate);
                bool       isMonthEnded = monthsList.Contains(nepaliDate.npMonth - 1);

                bool isYearEnded = yearsList.Contains(nepaliDate.npYear - 1);
                if (isYearEnded)
                {
                    yearsList.Remove(nepaliDate.npYear - 1);
                    string jsonData = JsonConvert.SerializeObject(yearObject);
                    //create a text file
                    string path = @"G:\YearDatas\" + nepaliDate.npYear + ".json";
                    if (!File.Exists(path))
                    {
                        File.Create(path).Dispose();

                        using (TextWriter tw = new StreamWriter(path))
                        {
                            tw.WriteLine(jsonData);
                        }
                    }

                    //   Console.WriteLine($"Year: {nepaliDate.npYear - 1} : {jsonData}");
                }

                if (isMonthEnded)
                {
                    yearObject.Add((nepaliDate.npMonth - 1).getMonthName(), monthDaysData);
                    monthsList.Remove(nepaliDate.npMonth - 1);
                    monthDaysData.Clear();
                }
                if (!yearsList.Contains(nepaliDate.npYear))
                {
                    yearObject = new Dictionary <string, object>();

                    //add an object
                    yearsList.Add(nepaliDate.npYear);
                }

                if (!monthsList.Contains(nepaliDate.npMonth))
                {
                    monthsList.Add(nepaliDate.npMonth);
                }

                monthDaysData.Add(new DayObjectDataModel()
                {
                    np      = nepaliDate.npDay.ToString(),
                    en      = englishStartDate.Day.ToString(),
                    bar     = nepaliDate.dayNumber.getBarName(),
                    day     = nepaliDate.dayNumber.getDayName(),
                    holiday = nepaliDate.dayNumber == 7,
                });


                englishStartDate = englishStartDate.AddDays(1);
            }
            Console.WriteLine("Finished");
        }