コード例 #1
0
        public void IsLeapYear()
        {
            var bcl  = new PersianCalendar();
            var noda = CalendarSystem.GetPersianCalendar();

            for (int year = 1; year < 9379; year++)
            {
                Assert.AreEqual(bcl.IsLeapYear(year), noda.IsLeapYear(year));
            }
        }
コード例 #2
0
    static void Main()
    {
        var persianCalendar = CalendarSystem.GetPersianCalendar();
        var pattern         = LocalDatePattern.CreateWithInvariantCulture("yyyy-MM-dd")
                              .WithTemplateValue(new LocalDate(1393, 1, 1, persianCalendar));
        LocalDate result   = pattern.Parse("1393-02-29").Value;
        DateTime  dateTime = result.AtMidnight().ToDateTimeUnspecified();

        Console.WriteLine(dateTime);     // 19th May 2014 (Gregorian)
    }
コード例 #3
0
        public void ConvertsToIsoCalendarWhenSerializing()
        {
            var obj = new Test {
                LocalDate = new LocalDate(2015, 1, 1).WithCalendar(CalendarSystem.GetPersianCalendar())
            };

            obj.ToTestJson().Should().Contain("'LocalDate' : '2015-01-01'");

            obj = BsonSerializer.Deserialize <Test>(obj.ToBson());
            obj.LocalDate.Should().Be(obj.LocalDate.WithCalendar(CalendarSystem.Iso));
        }
コード例 #4
0
    public static void Main()
    {
        // Providing the sample date to the pattern tells it which
        // calendar to use.
        // Noda Time 2.0 uses a property instead of a method.
        // var calendar = CalendarSystem.Persian;           // 2.0+
        var       calendar   = CalendarSystem.GetPersianCalendar(); // 1.x
        LocalDate sampleDate = new LocalDate(1392, 10, 12, calendar);
        var       pattern    = LocalDatePattern.Create(
            "yyyy/M/d", CultureInfo.InvariantCulture, sampleDate);
        string text = "1393/04/31";
        ParseResult <LocalDate> parseResult = pattern.Parse(text);

        if (parseResult.Success)
        {
            LocalDate date = parseResult.Value;
            // Use the date
        }
    }
コード例 #5
0
        [Test, Timeout(300000)] // Can take a long time under NCrunch.
        public void BclThroughHistory()
        {
            Calendar       bcl  = new PersianCalendar();
            CalendarSystem noda = CalendarSystem.GetPersianCalendar();

            for (int year = 1; year < 9378; year++)
            {
                for (int month = 1; month < 13; month++)
                {
                    Assert.AreEqual(bcl.GetDaysInMonth(year, month), noda.GetDaysInMonth(year, month),
                                    "Year: {0}; Month: {1}", year, month);
                    for (int day = 1; day < bcl.GetDaysInMonth(year, month); day++)
                    {
                        DateTime  bclDate  = new DateTime(year, month, day, bcl);
                        LocalDate nodaDate = new LocalDate(year, month, day, noda);
                        Assert.AreEqual(bclDate, nodaDate.AtMidnight().ToDateTimeUnspecified());
                        Assert.AreEqual(nodaDate, LocalDateTime.FromDateTime(bclDate).WithCalendar(noda).Date);
                        Assert.AreEqual(year, nodaDate.Year);
                        Assert.AreEqual(month, nodaDate.Month);
                        Assert.AreEqual(day, nodaDate.Day);
                    }
                }
            }
        }
コード例 #6
0
        public void ConvertsToIsoCalendarWhenSerializing()
        {
            var obj = new Test {
                OffsetDateTime = new LocalDateTime(2015, 1, 2, 3, 4, 5).WithOffset(Offset.FromHours(1)).WithCalendar(CalendarSystem.GetPersianCalendar())
            };

            obj.ToTestJson().Should().Contain("'OffsetDateTime' : '2015-01-02T03:04:05+01'");

            obj = BsonSerializer.Deserialize <Test>(obj.ToBson());
            obj.OffsetDateTime.Should().Be(obj.OffsetDateTime.WithCalendar(CalendarSystem.Iso));
        }