Ejemplo n.º 1
0
        public static void HijriTest()
        {
            HijriCalendar cal1 = new HijriCalendar();
            int           ad   = cal1.HijriAdjustment;

            Assert.True(ad >= -2 && ad <= 2);
        }
Ejemplo n.º 2
0
        public static DateTime?GetDate(string hijriOrGregDate)
        {
            HijriCalendar     hijriCal = new HijriCalendar();
            GregorianCalendar gregCal  = new GregorianCalendar();

            if (!string.IsNullOrEmpty(hijriOrGregDate))
            {
                string[] date = hijriOrGregDate.Split(',');

                if (date[3] == "H")
                {
                    DateTime persianDate = hijriCal.ToDateTime(int.Parse(date[2]), int.Parse(date[1]), int.Parse(date[0]), 0, 0, 0, 0);
                    persianDate = DateTime.ParseExact(date[2] + "/" + date[1] + "/" + date[0], "yyyy/MM/dd", new CultureInfo("ar-SA") /*, hijriCal*/);
                    return(persianDate);
                }
                else
                {
                    DateTime persianDate = gregCal.ToDateTime(int.Parse(date[2]), int.Parse(date[1]), int.Parse(date[0]), 0, 0, 0, 0);
                    persianDate = new DateTime(int.Parse(date[2]), int.Parse(date[1]), int.Parse(date[0]), gregCal);
                    return(persianDate);
                }
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 3
0
        public DateTime?GetDate(string hijriOrGregDate)
        {
            HijriCalendar     hijriCal = new HijriCalendar();
            GregorianCalendar gregCal  = new GregorianCalendar();

            if (!string.IsNullOrEmpty(hijriOrGregDate))
            {
                string[] date = hijriOrGregDate.Split(',');

                //var lastEnqueriesDate = new DateTime(int.Parse(date[2]), int.Parse(date[1]), int.Parse(date[0]), persianCal);
                if (date[3] == "H")
                {
                    DateTime persianDate = hijriCal.ToDateTime(int.Parse(date[2]), int.Parse(date[1]), int.Parse(date[0]), 0, 0, 0, 0);
                    persianDate = new DateTime(int.Parse(date[2]), int.Parse(date[1]), int.Parse(date[0]), hijriCal);
                    return(persianDate);
                }
                else
                {
                    DateTime persianDate = gregCal.ToDateTime(int.Parse(date[2]), int.Parse(date[1]), int.Parse(date[0]), 0, 0, 0, 0);
                    persianDate = new DateTime(int.Parse(date[2]), int.Parse(date[1]), int.Parse(date[0]), gregCal);
                    return(persianDate);
                }
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 4
0
        public static Calendar GetCalendar(CalendarTypes calendartype)
        {
            Calendar cal;

            switch (calendartype)
            {
            case CalendarTypes.Chinese:
                cal = new ChineseLunisolarCalendar();
                break;

            case CalendarTypes.Gregorian:
                cal = new GregorianCalendar();
                break;

            case CalendarTypes.Hebrew:
                cal = new HebrewCalendar();
                break;

            case CalendarTypes.Islamic:
                cal = new HijriCalendar();
                break;

            case CalendarTypes.Persian:
                cal = new PersianCalendar();
                break;

            default:
                throw new Exception("Calendar not Supported!");
            }
            return(cal);
        }
Ejemplo n.º 5
0
    public static string GregorianTo(string xCalendarType, string xDateTime)
    {
        string result = null;

        if (string.IsNullOrWhiteSpace(xDateTime))
        {
            return(null);
        }
        var _xDateTime = Convert.ToDateTime(xDateTime);
        var _xTime     = xDateTime.Split(' ');

        switch (xCalendarType.ToLower())
        {
        case "hijrishamsi":
            var pc = new PersianCalendar();
            result = pc.GetYear(_xDateTime).ToString("0000") + "/" + pc.GetMonth(_xDateTime).ToString("00") + "/" +
                     pc.GetDayOfMonth(_xDateTime).ToString("00") + (_xTime.Length == 2 ? " " + _xTime[1] : "");
            break;

        case "hijrighamari":
            var hc = new HijriCalendar();
            result = hc.GetYear(_xDateTime).ToString("0000") + "/" + hc.GetMonth(_xDateTime).ToString("00") + "/" +
                     hc.GetDayOfMonth(_xDateTime).ToString("00") + (_xTime.Length == 2 ? " " + _xTime[1] : "");
            break;

        default:
            return(null);
        }
        return(result);
    }
Ejemplo n.º 6
0
    public static void Main()
    {
        DateTime date1 = new DateTime(2011, 6, 20);

        DisplayCurrentInfo();
        // Display the date using the current culture and calendar.
        Console.WriteLine(date1.ToString("d"));
        Console.WriteLine();

        CultureInfo arSA = CultureInfo.CreateSpecificCulture("ar-SA");

        // Change the current culture to Arabic (Saudi Arabia).
        Thread.CurrentThread.CurrentCulture = arSA;
        // Display date and information about the current culture.
        DisplayCurrentInfo();
        Console.WriteLine(date1.ToString("d"));
        Console.WriteLine();

        // Change the calendar to Hijri.
        Calendar hijri = new HijriCalendar();

        if (CalendarExists(arSA, hijri))
        {
            arSA.DateTimeFormat.Calendar = hijri;
            // Display date and information about the current culture.
            DisplayCurrentInfo();
            Console.WriteLine(date1.ToString("d"));
        }
    }
Ejemplo n.º 7
0
        private void InvitationMap()
        {
            HijriCalendar hijriCal   = new HijriCalendar();
            CultureInfo   arProvider = CultureInfo.CreateSpecificCulture("ar-SA");

            CreateMap <Invitation, SupplierInvitationModel>()
            .ForMember(tm => tm.InvitationIdString, opt => opt.MapFrom(t => (Util.Encrypt(t.InvitationId))))
            .ForMember(tm => tm.TenderName, opt => opt.MapFrom(t => t.Tender.TenderName))
            .ForMember(tm => tm.CreatedAtHihri, opt => opt.MapFrom(t => t.Tender.CreatedAt.ToString("yyyy-MM-dd", arProvider)))
            .ForMember(tm => tm.TenderNumber, opt => opt.MapFrom(t => t.Tender.TenderNumber))
            .ForMember(tm => tm.CommericalRegisterName, opt => opt.MapFrom(t => t.Supplier.SelectedCrName))
            .ForMember(tm => tm.InvitationTypeId, opt => opt.MapFrom(t => t.InvitationTypeId))
            .ForMember(tm => tm.InvitationStatusId, opt => opt.MapFrom(t => t.InvitationStatus.InvitationStatusId));

            CreateMap <SupplierIntegrationModel, SupplierInvitationModel>().ForMember(dest => dest.CommericalRegisterName, opt => opt.MapFrom(src => src.supplierName))
            .ForMember(dest => dest.CommericalRegisterNo, opt => opt.MapFrom(src => src.supplierNumber))
            .ForMember(dest => dest.Email, opt => opt.MapFrom(src => src.Email))
            .ForMember(dest => dest.SupplierName, opt => opt.MapFrom(src => src.supplierName))
            .ForMember(dest => dest.SupplierMobileNo, opt => opt.MapFrom(src => src.contactOfficers.Select(c => c.mobile)))
            .ForMember(dest => dest.SupplierContactOfficersEmails, opt => opt.MapFrom(src => src.contactOfficers.Select(c => c.email)));

            CreateMap <SupplierInvitationModel, SupplierIntegrationModel>().ForMember(dest => dest.supplierName, opt => opt.MapFrom(src => src.CommericalRegisterName))
            .ForMember(dest => dest.supplierNumber, opt => opt.MapFrom(src => src.CommericalRegisterNo))
            .ForMember(dest => dest.supplierName, opt => opt.MapFrom(src => src.SupplierName));
        }
Ejemplo n.º 8
0
    public static void Main()
    {
        // Creates and initializes a HijriCalendar.
        HijriCalendar myCal = new HijriCalendar();

        // Displays the header.
        Console.Write("YEAR\t");
        for (int y = 1421; y <= 1425; y++)
        {
            Console.Write("\t{0}", y);
        }
        Console.WriteLine();

        // Displays the value of the CurrentEra property.
        Console.Write("CurrentEra:");
        for (int y = 1421; y <= 1425; y++)
        {
            Console.Write("\t{0}", myCal.GetDaysInMonth(y, 12, HijriCalendar.CurrentEra));
        }
        Console.WriteLine();

        // Displays the values in the Eras property.
        for (int i = 0; i < myCal.Eras.Length; i++)
        {
            Console.Write("Era {0}:\t", myCal.Eras[i]);
            for (int y = 1421; y <= 1425; y++)
            {
                Console.Write("\t{0}", myCal.GetDaysInMonth(y, 12, myCal.Eras[i]));
            }
            Console.WriteLine();
        }
    }
Ejemplo n.º 9
0
        public static void HijriTest()
        {
            HijriCalendar hCal  = new HijriCalendar();
            DateTime      dTest = hCal.ToDateTime(1008, 06, 15, 0, 0, 0, 0);

            Assert.Equal(dTest, new DateTime(1600, 1, 1).AddDays(hCal.HijriAdjustment));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Check if string is hijri date and then return true
        /// </summary>
        /// <PARAM name="hijri"></PARAM>
        /// <returns></returns>
        public static bool IsHijri(string hijri)
        {
            if (hijri.Length <= 0)
            {
                //cur.Trace.Warn("IsHijri Error: Date String is Empty");
                return(false);
            }

            try
            {
                CultureInfo   arCul = new CultureInfo("ar-SA");
                HijriCalendar h     = new HijriCalendar();
                arCul.DateTimeFormat.Calendar = h;

                DateTime tempDate = DateTime.ParseExact(hijri, "dd/MM/yyyy",
                                                        arCul.DateTimeFormat, DateTimeStyles.AllowWhiteSpaces);
                if (tempDate.Year >= 1800 && tempDate.Year <= 2500)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception)
            {
                //throw new Exception("لا يمكن التحقق من صحة التاريخ الهجري");
                //cur.Trace.Warn("IsHijri Error :" + hijri.ToString() + "\n" +  ex.Message);
                return(false);
            }
        }
Ejemplo n.º 11
0
        [Test, Timeout(180000)] // Can take a long time under NCrunch.
        public void BclThroughHistory()
        {
            var bcl  = new HijriCalendar();
            var noda = CalendarSystem.IslamicBcl;

            BclEquivalenceHelper.AssertEquivalent(bcl, noda, noda.MinYear, noda.MaxYear);
        }
Ejemplo n.º 12
0
    public static void Main()
    {
        // Creates and initializes a HijriCalendar.
        HijriCalendar myCal = new HijriCalendar();

        // Displays the header.
        Console.Write("YEAR\t");
        for (int y = 1421; y <= 1425; y++)
        {
            Console.Write("\t{0}", y);
        }
        Console.WriteLine();

        // Checks five years in the current era.
        Console.Write("CurrentEra:");
        for (int y = 1421; y <= 1425; y++)
        {
            Console.Write("\t{0}", myCal.IsLeapYear(y, HijriCalendar.CurrentEra));
        }
        Console.WriteLine();

        // Checks five years in each of the eras.
        for (int i = 0; i < myCal.Eras.Length; i++)
        {
            Console.Write("Era {0}:\t", myCal.Eras[i]);
            for (int y = 1421; y <= 1425; y++)
            {
                Console.Write("\t{0}", myCal.IsLeapYear(y, myCal.Eras[i]));
            }
            Console.WriteLine();
        }
    }
    public static void Main()
    {
        // Creates and initializes a HijriCalendar.
        HijriCalendar myCal = new HijriCalendar();

        // Creates a DateTime and initializes it to the second day of the first month of the year 1422.
        DateTime myDT = new DateTime(1422, 1, 2, myCal);

        // Displays the current values of the DateTime.
        Console.WriteLine("HijriAdjustment is {0}.", myCal.HijriAdjustment);
        Console.WriteLine("   Year is {0}.", myCal.GetYear(myDT));
        Console.WriteLine("   Month is {0}.", myCal.GetMonth(myDT));
        Console.WriteLine("   Day is {0}.", myCal.GetDayOfMonth(myDT));

        // Sets the HijriAdjustment property to 2.
        myCal.HijriAdjustment = 2;
        Console.WriteLine("HijriAdjustment is {0}.", myCal.HijriAdjustment);
        Console.WriteLine("   Year is {0}.", myCal.GetYear(myDT));
        Console.WriteLine("   Month is {0}.", myCal.GetMonth(myDT));
        Console.WriteLine("   Day is {0}.", myCal.GetDayOfMonth(myDT));

        // Sets the HijriAdjustment property to -2.
        myCal.HijriAdjustment = -2;
        Console.WriteLine("HijriAdjustment is {0}.", myCal.HijriAdjustment);
        Console.WriteLine("   Year is {0}.", myCal.GetYear(myDT));
        Console.WriteLine("   Month is {0}.", myCal.GetMonth(myDT));
        Console.WriteLine("   Day is {0}.", myCal.GetDayOfMonth(myDT));
    }
Ejemplo n.º 14
0
        public static bool CreateCalendar(string calendarName, out Calendar calendar)
        {
            calendar = null;
            bool result = false;

            if (Validator.CompareWithInvariantCulture(calendarName, "Gregorian Arabic"))
            {
                result   = true;
                calendar = new GregorianCalendar(GregorianCalendarTypes.Arabic);
            }
            else if (Validator.CompareWithInvariantCulture(calendarName, "Gregorian Middle East French"))
            {
                result   = true;
                calendar = new GregorianCalendar(GregorianCalendarTypes.MiddleEastFrench);
            }
            else if (Validator.CompareWithInvariantCulture(calendarName, "Gregorian Transliterated English"))
            {
                result   = true;
                calendar = new GregorianCalendar(GregorianCalendarTypes.TransliteratedEnglish);
            }
            else if (Validator.CompareWithInvariantCulture(calendarName, "Gregorian Transliterated French"))
            {
                result   = true;
                calendar = new GregorianCalendar(GregorianCalendarTypes.TransliteratedFrench);
            }
            else if (Validator.CompareWithInvariantCulture(calendarName, "Gregorian US English"))
            {
                result   = true;
                calendar = new GregorianCalendar(GregorianCalendarTypes.USEnglish);
            }
            else if (Validator.CompareWithInvariantCulture(calendarName, "Hebrew"))
            {
                calendar = new HebrewCalendar();
            }
            else if (Validator.CompareWithInvariantCulture(calendarName, "Hijri"))
            {
                calendar = new HijriCalendar();
            }
            else if (Validator.CompareWithInvariantCulture(calendarName, "Japanese"))
            {
                calendar = new JapaneseCalendar();
            }
            else if (Validator.CompareWithInvariantCulture(calendarName, "Korea"))
            {
                calendar = new KoreanCalendar();
            }
            else if (Validator.CompareWithInvariantCulture(calendarName, "Taiwan"))
            {
                calendar = new TaiwanCalendar();
            }
            else if (Validator.CompareWithInvariantCulture(calendarName, "Thai Buddhist"))
            {
                calendar = new ThaiBuddhistCalendar();
            }
            else if (Validator.CompareWithInvariantCulture(calendarName, "Gregorian"))
            {
                calendar = new GregorianCalendar();
            }
            return(result);
        }
Ejemplo n.º 15
0
        public void Can_Get_IndexOfDay_For_HijriCalendar_Using_CultureHelper()
        {
            var hc  = new HijriCalendar();
            var dt  = new DateTime(2009, 5, 11); //Should be Monday
            var dow = CultureHelper.GetDayOfWeek(dt, hc);

            Assert.AreEqual(1, dow);
        }
Ejemplo n.º 16
0
    protected void DoSave(object sender, ImageClickEventArgs e)
    {
        try
        {
            msgBox.Text = "";
            string strSelectedMonth = txtMonthNo.Text.ToString();
            string strSelectedDay   = txtDayNo.Text.ToString();
            int    SelectedMonth;
            int    SelectedDay;
            Int32.TryParse(strSelectedMonth, out SelectedMonth);
            Int32.TryParse(strSelectedDay, out SelectedDay);
            if (SelectedMonth == 0 || SelectedMonth > 12)
            {
                msgBox.MessageTextMode = AKP.Web.Controls.Common.MessageMode.Error;
                msgBox.Text            = "ماه معتبر نیست";
                return;
            }
            if (SelectedDay == 0 || SelectedDay > 31)
            {
                msgBox.MessageTextMode = AKP.Web.Controls.Common.MessageMode.Error;
                msgBox.Text            = "روز معتبر نیست";
                return;
            }

            int ReturnCode = SaveControls("~/Main/Default.aspx?BaseID=" + BaseID);
            if (NewMode && ReturnCode != -1)
            {
                NewMode = false;
                Code    = ReturnCode;
                ShowDetails();
            }
            if (ReturnCode != -1)
            {
                DateTime?EventDate = null;
                if (cboHCCalendarTypeCode.SelectedValue == "1")
                {
                    PersianCalendar PCalendar = new PersianCalendar();
                    EventDate = PCalendar.ToDateTime(1390, SelectedMonth, SelectedDay, 12, 1, 1, 1);
                }
                if (cboHCCalendarTypeCode.SelectedValue == "2")
                {
                    HijriCalendar HCalendar = new HijriCalendar();
                    EventDate = HCalendar.ToDateTime(1390, SelectedMonth, SelectedDay, 12, 1, 1, 1);
                }
                else
                {
                    EventDate = new DateTime(2011, SelectedMonth, SelectedDay, 12, 1, 1, 1);
                }

                BOLEvents EventsBOL = new BOLEvents();
                EventsBOL.SaveEventDate(ReturnCode, (DateTime)EventDate);
            }
        }
        catch
        {
        }
    }
Ejemplo n.º 17
0
        public BaseDateControl()
        {
            pc = new PersianCalendar();
            gc = new GregorianCalendar();
            hc = new HijriCalendar();

            SelectedDateTime = DateTime.Now.Date;
            ViewDateTime     = DateTime.Now.Date;
        }
Ejemplo n.º 18
0
        /// <summary>
        /// متد تبديل تاريخ ميلادي به قمري
        /// </summary>
        public void MiladiToGhamari()
        {
            HijriCalendar hc     = new HijriCalendar();
            DateTime      dt     = new DateTime(year: Year, month: Month, day: Day);
            string        result =
                $"Miladi To Ghamari:{ hc.GetYear(dt).ToString("0000/") } { hc.GetMonth(dt).ToString("00/") } { hc.GetDayOfMonth(dt).ToString("00") }";

            System.Console.Write(result);
        }
Ejemplo n.º 19
0
        static void Main(string[] args)
        {
            HijriCalendar hc = new HijriCalendar();

            string[] days = new string[] { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };

            DisplayValues(hc, DateTime.Now);
            Console.WriteLine(days[GetFirstDayOfMonth(7) - 1]);
            Console.ReadKey();
        }
Ejemplo n.º 20
0
        public static string Hijri(DateTime firstDayOfMonth, DateTime lastDayOfMonth)
        {
            var hijriCal             = new HijriCalendar();
            var firstDayOfMonthHijri = hijriCal.GetMonth(firstDayOfMonth);
            var lastDayOfMonthHijri  = hijriCal.GetMonth(lastDayOfMonth);

            return(firstDayOfMonthHijri.Equals(lastDayOfMonthHijri)
                ? $"{MonthsName.Hijri(firstDayOfMonthHijri)} {ArabicDigits.Convert(hijriCal.GetYear(firstDayOfMonth).ToString())}"
                : $"{MonthsName.Hijri(firstDayOfMonthHijri)} — {MonthsName.Hijri(lastDayOfMonthHijri)} {ArabicDigits.Convert(hijriCal.GetYear(firstDayOfMonth).ToString())}");
        }
Ejemplo n.º 21
0
    public static void Main()
    {
        GregorianCalendar grCal = new GregorianCalendar();
        HijriCalendar     hiCal = new HijriCalendar();
        JapaneseLunisolarCalendar
            jaCal = new JapaneseLunisolarCalendar();

        Display(grCal);
        Display(hiCal);
        Display(jaCal);
    }
        public void SampleDateBclCompatibility()
        {
            Calendar hijri     = new HijriCalendar();
            DateTime bclDirect = new DateTime(1302, 10, 15, 0, 0, 0, 0, hijri, DateTimeKind.Unspecified);

            CalendarSystem islamicCalendar = CalendarSystem.GetIslamicCalendar(IslamicLeapYearPattern.Base16, IslamicEpoch.Astronomical);
            LocalDate      iso             = new LocalDate(1302, 10, 15, islamicCalendar);
            DateTime       bclFromNoda     = iso.AtMidnight().ToDateTimeUnspecified();

            Assert.AreEqual(bclDirect, bclFromNoda);
        }
Ejemplo n.º 23
0
        public void SampleDateBclCompatibility()
        {
            Calendar hijri     = new HijriCalendar();
            DateTime bclDirect = new DateTime(1302, 10, 15, 0, 0, 0, 0, hijri, DateTimeKind.Unspecified);

            CalendarSystem islamicCalendar = CalendarSystem.IslamicBcl;
            LocalDate      iso             = new LocalDate(1302, 10, 15, islamicCalendar);
            DateTime       bclFromNoda     = iso.AtMidnight().ToDateTimeUnspecified();

            Assert.AreEqual(bclDirect, bclFromNoda);
        }
        public static Calendar CalendarFromString(
            string name
            )
        {
            Calendar c;

            if (name == null)
            {
                name = String.Empty;
            }

            switch (name.ToLower())
            {
            case "hebrew":
                c = new HebrewCalendar();
                break;

            case "hijri":
                c = new HijriCalendar();
                break;

            case "japanese":
                c = new JapaneseCalendar();
                break;

            case "korean":
                c = new KoreanCalendar();
                break;

            case "taiwan":
                c = new TaiwanCalendar();
                break;

            case "thaibuddhist":
                c = new ThaiBuddhistCalendar();
                break;

            case "umalqura":
                c = new UmAlQuraCalendar();
                break;

#if !SILVERLIGHT
            case "persian":
                c = new PersianCalendar();
                break;
#endif
            default:
                c = new GregorianCalendar();
                break;
            }

            return(c);
        }
Ejemplo n.º 25
0
    public Dates()
    {
        cur = HttpContext.Current;

        arCul = new CultureInfo("ar-SA");
        enCul = new CultureInfo("en-US");

        h = new HijriCalendar();
        g = new GregorianCalendar(GregorianCalendarTypes.USEnglish);

        arCul.DateTimeFormat.Calendar = h;
    }
    public static void Main()
    {
        Console.WriteLine("Using the Persian Calendar:");
        PersianCalendar persian = new PersianCalendar();
        DateTime        date1   = new DateTime(1389, 5, 27, 16, 32, 18, 500,
                                               persian, DateTimeKind.Local);

        Console.WriteLine("{0:M/dd/yyyy h:mm:ss.fff tt} {1}", date1, date1.Kind);
        Console.WriteLine("{0}/{1}/{2} {3}{8}{4:D2}{8}{5:D2}.{6:G3} {7}\n",
                          persian.GetMonth(date1),
                          persian.GetDayOfMonth(date1),
                          persian.GetYear(date1),
                          persian.GetHour(date1),
                          persian.GetMinute(date1),
                          persian.GetSecond(date1),
                          persian.GetMilliseconds(date1),
                          date1.Kind,
                          DateTimeFormatInfo.CurrentInfo.TimeSeparator);

        Console.WriteLine("Using the Hijri Calendar:");
        // Get current culture so it can later be restored.
        CultureInfo dftCulture = Thread.CurrentThread.CurrentCulture;

        // Define strings for use in composite formatting.
        string dFormat;
        string fmtString;
        // Define Hijri calendar.
        HijriCalendar hijri = new HijriCalendar();

        // Make ar-SY the current culture and Hijri the current calendar.
        Thread.CurrentThread.CurrentCulture = new CultureInfo("ar-SY");
        CultureInfo current = CultureInfo.CurrentCulture;

        current.DateTimeFormat.Calendar = hijri;
        dFormat = current.DateTimeFormat.ShortDatePattern;
        // Ensure year is displayed as four digits.
        dFormat   = Regex.Replace(dFormat, "/yy$", "/yyyy") + " H:mm:ss.fff";
        fmtString = "{0} culture using the {1} calendar: {2:" + dFormat + "} {3}";
        DateTime date2 = new DateTime(1431, 9, 9, 16, 32, 18, 500,
                                      hijri, DateTimeKind.Local);

        Console.WriteLine(fmtString, current, GetCalendarName(hijri),
                          date2, date2.Kind);

        // Restore previous culture.
        Thread.CurrentThread.CurrentCulture = dftCulture;
        dFormat   = DateTimeFormatInfo.CurrentInfo.ShortDatePattern + " H:mm:ss.fff";
        fmtString = "{0} culture using the {1} calendar: {2:" + dFormat + "} {3}";
        Console.WriteLine(fmtString,
                          CultureInfo.CurrentCulture,
                          GetCalendarName(CultureInfo.CurrentCulture.Calendar),
                          date2, date2.Kind);
    }
        public void BclUsesAstronomicalEpoch()
        {
            Calendar hijri     = new HijriCalendar();
            DateTime bclDirect = new DateTime(1, 1, 1, 0, 0, 0, 0, hijri, DateTimeKind.Unspecified);

            CalendarSystem julianCalendar     = CalendarSystem.GetJulianCalendar(4);
            LocalDate      julianIslamicEpoch = new LocalDate(622, 7, 15, julianCalendar);
            LocalDate      isoIslamicEpoch    = julianIslamicEpoch.WithCalendar(CalendarSystem.Iso);
            DateTime       bclFromNoda        = isoIslamicEpoch.AtMidnight().ToDateTimeUnspecified();

            Assert.AreEqual(bclDirect, bclFromNoda);
        }
Ejemplo n.º 28
0
        public DateConvertor()
        {
            //cur = HttpContext.Current;

            arCul = new CultureInfo("ar-SA");
            enCul = new CultureInfo("en-US");

            h = new  HijriCalendar();
            g = new GregorianCalendar(GregorianCalendarTypes.USEnglish);

            arCul.DateTimeFormat.Calendar = h;
        }
Ejemplo n.º 29
0
        static FAMonthView()
        {
            MonthViewEventDayRender        = GetEventReference("EventDayRender");
            MonthViewEventSelectionChanged = GetEventReference("EventSelectionChanged");

            DefaultForeColor = Color.Black;
            baseDate         = new DateTime(2000, 1, 1);
            persianCulture   = new PersianCultureInfo();
            pc            = new PersianCalendar();
            gc            = new GregorianCalendar();
            hc            = new HijriCalendar();
            cachedNumbers = new[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" };
        }
Ejemplo n.º 30
0
        public Dates()
        {
            _cur = HttpContext.Current;

            _arCul = new CultureInfo("ar-SA");
            _enCul = new CultureInfo("en-US");

            var h = new HijriCalendar();

            _g = new GregorianCalendar(GregorianCalendarTypes.USEnglish);

            _arCul.DateTimeFormat.Calendar = h;
        }
Ejemplo n.º 31
0
        // Calculates the exact gregorian date for the given holiday using only gregorian year and exact hijri date
        public static DateObject IslamicHoliday(int year, IslamicHolidayType holidayType)
        {
            int y = 0;
            int m = 0;
            int d = 0;

            int hijriDay   = 1;
            int hijriMonth = 1;
            int hijriYear  = 1;

            var gregorian = new GregorianCalendar();
            var hijri     = new HijriCalendar();

            switch (holidayType)
            {
            case IslamicHolidayType.Ramadan:
                hijriDay   = 1;
                hijriMonth = 9;
                break;

            case IslamicHolidayType.Sacrifice:
                hijriDay   = 10;
                hijriMonth = 12;
                break;

            case IslamicHolidayType.EidAlFitr:
                hijriDay   = 1;
                hijriMonth = 10;
                break;

            case IslamicHolidayType.NewYear:
                hijriDay   = 1;
                hijriMonth = 1;
                break;
            }

            for (hijriYear = 1; hijriYear <= 9999; hijriYear++)
            {
                var hijriDate = new DateObject(hijriYear, hijriMonth, hijriDay, hijri);
                y = gregorian.GetYear(hijriDate);
                m = gregorian.GetMonth(hijriDate);
                d = gregorian.GetDayOfMonth(hijriDate);

                if (y == year)
                {
                    break;
                }
            }

            return(DateObject.MinValue.SafeCreateFromValue(y, m, d));
        }
Ejemplo n.º 32
0
 public bool runTest()
   {
   Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
   String strLoc = "Loc_000oo";
   String strValue = String.Empty;
   int iCountErrors = 0;
   int iCountTestcases = 0;
   try
     {
     DateTime dTest;
     HebrewCalendar hCal = new HebrewCalendar();
     JulianCalendar jCal = new JulianCalendar();
     HijriCalendar hiCal = new HijriCalendar ();
     GregorianCalendar gCal = new GregorianCalendar ();
     JapaneseCalendar jaCal = new JapaneseCalendar ();
     KoreanCalendar kCal = new KoreanCalendar ();
     ThaiBuddhistCalendar tCal = new ThaiBuddhistCalendar ();
     strLoc = "Loc_100vy";
     iCountTestcases++;
     dTest = new DateTime(5360,04,14,hCal); 	
     if (dTest.Year != 1600)
       {
       ++iCountErrors;	
       printerr( "Error_100aa! DateTime object was not set correctly");
       }
     if (dTest.Month != 1)
       {
       ++iCountErrors;	
       printerr( "Error_100bb! DateTime object was not set correctly");
       }
     if (dTest.Day != 1)
       {
       ++iCountErrors;	
       printerr( "Error_100cc! DateTime object was not set correctly");
       }
     if (dTest.Hour != 0)
       {
       ++iCountErrors;	
       printerr( "Error_100dd! DateTime object was not set correctly");
       }
     if (dTest.Minute != 0)
       {
       ++iCountErrors;	
       printerr( "Error_100ee! DateTime object was not set correctly");
       }
     if (dTest.Second != 0)
       {
       ++iCountErrors;	
       printerr( "Error_100ff! DateTime object was not set correctly");
       }
     if (dTest.Millisecond != 0)
       {
       ++iCountErrors;	
       printerr( "Error_100gg! DateTime object was not set correctly");
       }
     strLoc = "Loc_101vy";
     iCountTestcases++;
     dTest = new DateTime(1599,12,22,jCal); 	
     if (dTest.Year != 1600)
       {
       ++iCountErrors;	
       printerr( "Error_101aa! DateTime object was not set correctly");
       }
     if (dTest.Month != 1)
       {
       ++iCountErrors;	
       printerr( "Error_101bb! DateTime object was not set correctly");
       }
     if (dTest.Day != 1)
       {
       ++iCountErrors;	
       printerr( "Error_101cc! DateTime object was not set correctly");
       }
     if (dTest.Hour != 0)
       {
       ++iCountErrors;	
       printerr( "Error_101dd! DateTime object was not set correctly");
       }
     if (dTest.Minute != 0)
       {
       ++iCountErrors;	
       printerr( "Error_101ee! DateTime object was not set correctly");
       }
     if (dTest.Second != 0)
       {
       ++iCountErrors;	
       printerr( "Error_101ff! DateTime object was not set correctly");
       }
     if (dTest.Millisecond != 0)
       {
       ++iCountErrors;	
       printerr( "Error_101gg! DateTime object was not set correctly");
       }
     strLoc = "Loc_102vy";
     iCountTestcases++;
     dTest = new DateTime(1008,06,15,hiCal); 	
     if (dTest.Year != 1600)
       {
       ++iCountErrors;	
       printerr( "Error_102aa! DateTime object was not set correctly");
       }
     if (dTest.Month != 1)
       {
       ++iCountErrors;	
       printerr( "Error_102bb! DateTime object was not set correctly");
       }
     if (dTest.Day != 1)
       {
       ++iCountErrors;	
       printerr( "Error_102cc! DateTime object was not set correctly");
       }
     if (dTest.Hour != 0)
       {
       ++iCountErrors;	
       printerr( "Error_102dd! DateTime object was not set correctly");
       }
     if (dTest.Minute != 0)
       {
       ++iCountErrors;	
       printerr( "Error_102ee! DateTime object was not set correctly");
       }
     if (dTest.Second != 0)
       {
       ++iCountErrors;	
       printerr( "Error_102ff! DateTime object was not set correctly");
       }
     if (dTest.Millisecond != 0)
       {
       ++iCountErrors;	
       printerr( "Error_102gg! DateTime object was not set correctly");
       }
     strLoc = "Loc_103vy";
     iCountTestcases++;
     dTest = new DateTime(1600,1,1,gCal); 	
     if (dTest.Year != 1600)
       {
       ++iCountErrors;	
       printerr( "Error_103aa! DateTime object was not set correctly");
       }
     if (dTest.Month != 1)
       {
       ++iCountErrors;	
       printerr( "Error_103bb! DateTime object was not set correctly");
       }
     if (dTest.Day != 1)
       {
       ++iCountErrors;	
       printerr( "Error_103cc! DateTime object was not set correctly");
       }
     if (dTest.Hour != 0)
       {
       ++iCountErrors;	
       printerr( "Error_103dd! DateTime object was not set correctly");
       }
     if (dTest.Minute != 0)
       {
       ++iCountErrors;	
       printerr( "Error_103ee! DateTime object was not set correctly");
       }
     if (dTest.Second != 0)
       {
       ++iCountErrors;	
       printerr( "Error_103ff! DateTime object was not set correctly");
       }
     if (dTest.Millisecond != 0)
       {
       ++iCountErrors;	
       printerr( "Error_103gg! DateTime object was not set correctly");
       }
     strLoc = "Loc_104vy";
     iCountTestcases++;
     dTest = new DateTime(1,1,8,jaCal); 	
     if (dTest.Year != 1989)
       {
       ++iCountErrors;	
       printerr( "Error_104aa! DateTime object was not set correctly");
       }
     if (dTest.Month != 1)
       {
       ++iCountErrors;	
       printerr( "Error_104bb! DateTime object was not set correctly");
       }
     if (dTest.Day != 8)
       {
       ++iCountErrors;	
       printerr( "Error_104cc! DateTime object was not set correctly");
       }
     if (dTest.Hour != 0)
       {
       ++iCountErrors;	
       printerr( "Error_104dd! DateTime object was not set correctly");
       }
     if (dTest.Minute != 0)
       {
       ++iCountErrors;	
       printerr( "Error_104ee! DateTime object was not set correctly");
       }
     if (dTest.Second != 0)
       {
       ++iCountErrors;	
       printerr( "Error_104ff! DateTime object was not set correctly");
       }
     if (dTest.Millisecond != 0)
       {
       ++iCountErrors;	
       printerr( "Error_104gg! DateTime object was not set correctly");
       }
     strLoc = "Loc_105vy";
     iCountTestcases++;
     dTest = new DateTime(3933,1,1,kCal); 	
     if (dTest.Year != 1600)
       {
       ++iCountErrors;	
       printerr( "Error_105aa! DateTime object was not set correctly");
       }
     if (dTest.Month != 1)
       {
       ++iCountErrors;	
       printerr( "Error_105bb! DateTime object was not set correctly");
       }
     if (dTest.Day != 1)
       {
       ++iCountErrors;	
       printerr( "Error_105cc! DateTime object was not set correctly");
       }
     if (dTest.Hour != 0)
       {
       ++iCountErrors;	
       printerr( "Error_105dd! DateTime object was not set correctly");
       }
     if (dTest.Minute != 0)
       {
       ++iCountErrors;	
       printerr( "Error_105ee! DateTime object was not set correctly");
       }
     if (dTest.Second != 0)
       {
       ++iCountErrors;	
       printerr( "Error_105ff! DateTime object was not set correctly");
       }
     if (dTest.Millisecond != 0)
       {
       ++iCountErrors;	
       printerr( "Error_105gg! DateTime object was not set correctly");
       }
     strLoc = "Loc_106vy";
     iCountTestcases++;
     dTest = new DateTime(2143,1,1,tCal); 	
     if (dTest.Year != 1600)
       {
       ++iCountErrors;	
       printerr( "Error_106aa! DateTime object was not set correctly");
       }
     if (dTest.Month != 1)
       {
       ++iCountErrors;	
       printerr( "Error_106bb! DateTime object was not set correctly");
       }
     if (dTest.Day != 1)
       {
       ++iCountErrors;	
       printerr( "Error_106cc! DateTime object was not set correctly");
       }
     if (dTest.Hour != 0)
       {
       ++iCountErrors;	
       printerr( "Error_106dd! DateTime object was not set correctly");
       }
     if (dTest.Minute != 0)
       {
       ++iCountErrors;	
       printerr( "Error_106ee! DateTime object was not set correctly");
       }
     if (dTest.Second != 0)
       {
       ++iCountErrors;	
       printerr( "Error_106ff! DateTime object was not set correctly");
       }
     if (dTest.Millisecond != 0)
       {
       ++iCountErrors;	
       printerr( "Error_106gg! DateTime object was not set correctly");
       }
     strLoc = "Loc_524vy";
     iCountTestcases++;
     try
       {
       dTest = new DateTime(0,03,25,hCal);
       iCountErrors++;
       printerr( "Error_200bb! No exception thrown");
       }
     catch (ArgumentOutOfRangeException argexc)
       {
       printinfo( "Info_512ad! Caught ArguementOutOfRangeException");
       }
     catch (Exception e)
       {
       ++iCountErrors;	
       printerr( "Error_200aa! Wrong exception thrown: " + e.ToString());
       }
     strLoc = "Loc_333vy";
     iCountTestcases++;
     try
       {
       dTest = new DateTime(10000,03,25,hCal);
       iCountErrors++;
       printerr( "Error_300bb! No exception thrown");
       }
     catch (ArgumentOutOfRangeException argexc)
       {
       printinfo( "Info_333ad! Caught ArguementOutOfRangeException");
       }
     catch (Exception e)
       {
       ++iCountErrors;	
       printerr( "Error_300aa! Wrong exception thrown: " + e.ToString());
       }
     strLoc = "Loc_444vy";
     iCountTestcases++;
     try
       {
       dTest = new DateTime(5000,0,25,hCal);
       iCountErrors++;
       printerr( "Error_400bb! No exception thrown");
       }
     catch (ArgumentOutOfRangeException argexc)
       {
       printinfo( "Info_444ad! Caught ArguementOutOfRangeException");
       }
     catch (Exception e)
       {
       ++iCountErrors;	
       printerr( "Error_400aa! Wrong exception thrown: " + e.ToString());
       }
     strLoc = "Loc_555vy";
     iCountTestcases++;
     try
       {
       dTest = new DateTime(5000,13,25,jCal);
       iCountErrors++;
       printerr( "Error_500bb! No exception thrown");
       }
     catch (ArgumentOutOfRangeException argexc)
       {
       printinfo( "Info_555ad! Caught ArguementOutOfRangeException");
       }
     catch (Exception e)
       {
       ++iCountErrors;	
       printerr( "Error_500aa! Wrong exception thrown: " + e.ToString());
       }
     strLoc = "Loc_665vy";
     iCountTestcases++;
     try
       {
       dTest = new DateTime(2000,03,0,jCal);
       iCountErrors++;
       printerr( "Error_600bb! No exception thrown");
       }
     catch (ArgumentOutOfRangeException argexc)
       {
       printinfo( "Info_665ad! Caught ArguementOutOfRangeException");
       }
     catch (Exception e)
       {
       ++iCountErrors;	
       printerr( "Error_600aa! Wrong exception thrown: " + e.ToString());
       }
     strLoc = "Loc_777vy";
     iCountTestcases++;
     try
       {
       dTest = new DateTime(2000,03,32,jCal);
       iCountErrors++;
       printerr( "Error_700bb! No exception thrown");
       }
     catch (ArgumentOutOfRangeException argexc)
       {
       printinfo( "Info_775ad! Caught ArguementOutOfRangeException");
       }
     catch (Exception e)
       {
       ++iCountErrors;	
       printerr( "Error_700aa! Wrong exception thrown: " + e.ToString());
       }
     strLoc = "Loc_888vy";
     iCountTestcases++;
     try
       {
       dTest = new DateTime(2000,03,14,null);
       iCountErrors++;
       printerr( "Error_800bb! No exception thrown");
       }
     catch (ArgumentNullException argexc)
       {
       printinfo( "Info_885ad! Caught ArguementNullException");
       }
     catch (Exception e)
       {
       ++iCountErrors;	
       printerr( "Error_800aa! Wrong exception thrown: " + e.ToString());
       }
     } catch (Exception exc_general ) {
     ++iCountErrors;
     Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy!  strLoc=="+ strLoc +", exc_general=="+exc_general.ToString());
     }
   if ( iCountErrors == 0 )
     {
     Console.WriteLine( "paSs. "+s_strTFName+" ,iCountTestcases=="+iCountTestcases.ToString());
     return true;
     }
   else
     {
     Console.WriteLine("FAiL! "+s_strTFName+" ,iCountErrors=="+iCountErrors.ToString()+" , BugNums?: "+s_strActiveBugNums );
     return false;
     }
   }
Ejemplo n.º 33
0
 public static void HijriTest()
 {
     HijriCalendar cal1 = new HijriCalendar();
     int ad = cal1.HijriAdjustment;
     Assert.True(ad >= -2 && ad <= 2);
 }
Ejemplo n.º 34
0
 public static void HijriTest()
 {
     HijriCalendar hCal = new HijriCalendar();
     DateTime dTest = hCal.ToDateTime(1008, 06, 15, 0, 0, 0, 0);
     Assert.Equal(dTest, new DateTime(1600, 1, 1).AddDays(hCal.HijriAdjustment));
 }