public ChangeFeedController(IClock clock)
 {
     _clock                 = clock ?? throw new ArgumentNullException(nameof(clock));
     _localTimeZone         = DateTimeZoneProviders.Tzdb["Europe/Brussels"];
     _localMonthPattern     = LocalDatePattern.Create("MMM", new CultureInfo("nl-BE"));
     _localTimeOfDayPattern = LocalTimePattern.CreateWithInvariantCulture("HH':'mm");
 }
        private void AssertBclNodaEquality(CultureInfo culture, string patternText)
        {
            // The BCL never seems to use abbreviated month genitive names.
            // I think it's reasonable that we do. Hmm.
            // See https://github.com/nodatime/nodatime/issues/377
            if (patternText.Contains("MMM") && !patternText.Contains("MMMM") &&
                culture.DateTimeFormat.AbbreviatedMonthGenitiveNames[SampleLocalDate.Month - 1] != culture.DateTimeFormat.AbbreviatedMonthNames[SampleLocalDate.Month - 1])
            {
                return;
            }

            var pattern        = LocalDatePattern.Create(patternText, culture);
            var calendarSystem = BclCalendars.CalendarSystemForCalendar(culture.Calendar);

            if (calendarSystem == null)
            {
                // We can't map this calendar system correctly yet; the test would be invalid.
                return;
            }

            var sampleDateInCalendar = SampleLocalDate.WithCalendar(calendarSystem);
            // To construct a DateTime, we need a time... let's give a non-midnight one to catch
            // any unexpected uses of time within the date patterns.
            DateTime sampleDateTime = (SampleLocalDate + new LocalTime(2, 3, 5)).ToDateTimeUnspecified();

            Assert.AreEqual(sampleDateTime.ToString(patternText, culture), pattern.Format(sampleDateInCalendar));
        }
Beispiel #3
0
        public static bool ParseDate(this string text, DateTimeZone zone, string cultureTab, bool longFormat, out Instant result)
        {
            var rc = false;

            result = InstantError;

            if ((zone != null) && (String.IsNullOrEmpty(cultureTab) == false))
            {
                try
                {
                    var culture = MxCultureInfo.Instance.GetCultureInfo(cultureTab);
                    if (culture != null)
                    {
                        var parseResult = LocalDatePattern.Create(MxCultureInfo.GetFormatSpecifier(MxCultureInfo.FormatType.Date, longFormat), MxCultureInfo.Instance.GetCultureInfo(cultureTab)).Parse(text);
                        if (parseResult.Success)
                        {
                            var instant = parseResult.Value.AtMidnight().InZoneStrictly(zone).ToInstant();
                            var local   = instant.InZone(zone).LocalDateTime;
                            if (zone.IsDaylightSavingsTime(instant))
                            {
                                local = local.PlusSeconds(zone.GetZoneInterval(instant).Savings.Seconds);
                            }
                            result = local.InZoneStrictly(zone).ToInstant();
                            rc     = true;
                        }
                    }
                }
                catch (Exception)
                {
                    //ignore
                }
            }
            return(rc);
        }
Beispiel #4
0
            static bool IsCorrectInputFile(FileEntry file, LocalDate date)
            {
                var isoParsed     = LocalDatePattern.Iso.Parse(file.NameWithoutExtension);
                var yearDayParsed = LocalDatePattern.Create("uuuu-dd", CultureInfo.InvariantCulture, date).Parse(file.NameWithoutExtension);

                return(file.NameWithoutExtension.Equals($"day-{date.Day}", StringComparison.OrdinalIgnoreCase) ||
                       file.NameWithoutExtension.Equals($"day-{date.Year}-{date.Day}") ||
                       isoParsed.Success && isoParsed.Value == date ||
                       yearDayParsed.Success && yearDayParsed.Value == date);
            }
        public ConveyancingMatter MapFromActionstepTypes(
            GetActionResponse actionResponse,
            ListActionParticipantsResponse participantsResponse,
            ListDataCollectionRecordValuesResponse dataCollectionsResponse)
        {
            if (actionResponse is null)
            {
                throw new ArgumentNullException(nameof(actionResponse));
            }

            var wCAConveyancingMatter = new ConveyancingMatter();

            var action = actionResponse.Action;

            wCAConveyancingMatter.Id            = action.Id;
            wCAConveyancingMatter.Name          = action.Name;
            wCAConveyancingMatter.ActionType    = actionResponse.ActionTypeName;
            wCAConveyancingMatter.FileReference = action.Reference;
            wCAConveyancingMatter.Conveyancers.AddRange(GetParticipants(participantsResponse, "Conveyancer"));
            wCAConveyancingMatter.Buyers.AddRange(GetParticipants(participantsResponse, "Buyer"));
            wCAConveyancingMatter.IncomingBanks.AddRange(GetParticipants(participantsResponse, "Bank_Incoming"));
            wCAConveyancingMatter.OthersideSolicitor.AddRange(GetParticipants(participantsResponse, "Otherside_Solicitor"));
            wCAConveyancingMatter.OthersideSolicitorPrimaryContact.AddRange(GetParticipants(participantsResponse, "Otherside_Solicitor_Primary_Contact"));

            wCAConveyancingMatter.PropertyDetails = new PropertyDetails
            {
                TitleReference = dataCollectionsResponse?["property", "titleref"],
                LotNo          = dataCollectionsResponse["property", "lotno"]
            };

            ConveyancingType conveyancingType;
            var isConveyancingTypeParseSuccess = Enum.TryParse <ConveyancingType>(dataCollectionsResponse["convdet", "ConveyType"], out conveyancingType);

            if (!isConveyancingTypeParseSuccess)
            {
                conveyancingType = ConveyancingType.None;
            }
            wCAConveyancingMatter.ConveyancingType = conveyancingType;

            var stringSettlementDate = dataCollectionsResponse["keydates", "smtdateonly"];

            if (!String.IsNullOrEmpty(stringSettlementDate))
            {
                var pattern = LocalDatePattern.Create("yyyy-MM-dd", CultureInfo.InvariantCulture);
                wCAConveyancingMatter.SettlementDate = pattern.Parse(stringSettlementDate).Value;
            }

            wCAConveyancingMatter.SettlementBookingTime = dataCollectionsResponse["convdet", "smttime"];

            return(wCAConveyancingMatter);
        }
        private void AssertBclNodaEquality(CultureInfo culture, string patternText)
        {
            var pattern        = LocalDatePattern.Create(patternText, culture);
            var calendarSystem = CalendarSystemForCalendar(culture.Calendar);

            if (calendarSystem == null)
            {
                // We can't map this calendar system correctly yet; the test would be invalid.
                return;
            }

            var sampleDateInCalendar = SampleLocalDate.WithCalendar(calendarSystem);
            // To construct a DateTime, we need a time... let's give a non-midnight one to catch
            // any unexpected uses of time within the date patterns.
            DateTime sampleDateTime = (SampleLocalDate + new LocalTime(2, 3, 5)).ToDateTimeUnspecified();

            Assert.AreEqual(sampleDateTime.ToString(patternText, culture), pattern.Format(sampleDateInCalendar));
        }
Beispiel #7
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
        }
    }
Beispiel #8
0
        internal void AddEmbeddedDatePattern(
            char characterInPattern,
            string embeddedPatternText,
            Func <TBucket, LocalDatePatternParser.LocalDateParseBucket> dateBucketExtractor,
            Func <TResult, LocalDate> dateExtractor)
        {
            var templateDate = dateBucketExtractor(CreateSampleBucket()).TemplateValue;

            AddField(PatternFields.EmbeddedDate, characterInPattern);
            AddEmbeddedPattern(
                LocalDatePattern.Create(embeddedPatternText, FormatInfo, templateDate).UnderlyingPattern,
                (bucket, value) =>
            {
                var dateBucket                = dateBucketExtractor(bucket);
                dateBucket.Calendar           = value.Calendar;
                dateBucket.Year               = value.Year;
                dateBucket.MonthOfYearNumeric = value.Month;
                dateBucket.DayOfMonth         = value.Day;
            },
                dateExtractor);
        }
Beispiel #9
0
        /// <summary>
        /// Handles date, time and date/time embedded patterns.
        /// </summary>
        internal void AddEmbeddedLocalPartial(
            PatternCursor pattern,
            Func <TBucket, LocalDatePatternParser.LocalDateParseBucket> dateBucketExtractor,
            Func <TBucket, LocalTimePatternParser.LocalTimeParseBucket> timeBucketExtractor,
            Func <TResult, LocalDate> dateExtractor,
            Func <TResult, LocalTime> timeExtractor,
            // null if date/time embedded patterns are invalid
            Func <TResult, LocalDateTime> dateTimeExtractor)
        {
            // This will be d (date-only), t (time-only), or < (date and time)
            // If it's anything else, we'll see the problem when we try to get the pattern.
            var patternType = pattern.PeekNext();

            if (patternType == 'd' || patternType == 't')
            {
                pattern.MoveNext();
            }
            string embeddedPatternText = pattern.GetEmbeddedPattern();
            var    sampleBucket        = CreateSampleBucket();
            var    templateTime        = timeBucketExtractor(sampleBucket).TemplateValue;
            var    templateDate        = dateBucketExtractor(sampleBucket).TemplateValue;

            switch (patternType)
            {
            case '<':
                if (dateTimeExtractor == null)
                {
                    throw new InvalidPatternException(Messages.Parse_InvalidEmbeddedPatternType);
                }
                AddField(PatternFields.EmbeddedDate, 'l');
                AddField(PatternFields.EmbeddedTime, 'l');
                AddEmbeddedPattern(
                    LocalDateTimePattern.Create(embeddedPatternText, FormatInfo, templateDate + templateTime).UnderlyingPattern,
                    (bucket, value) =>
                {
                    var dateBucket                = dateBucketExtractor(bucket);
                    var timeBucket                = timeBucketExtractor(bucket);
                    dateBucket.Calendar           = value.Calendar;
                    dateBucket.Year               = value.Year;
                    dateBucket.MonthOfYearNumeric = value.Month;
                    dateBucket.DayOfMonth         = value.Day;
                    timeBucket.Hours24            = value.Hour;
                    timeBucket.Minutes            = value.Minute;
                    timeBucket.Seconds            = value.Second;
                    timeBucket.FractionalSeconds  = value.NanosecondOfSecond;
                },
                    dateTimeExtractor);
                break;

            case 'd':
                AddField(PatternFields.EmbeddedDate, 'l');
                AddEmbeddedPattern(
                    LocalDatePattern.Create(embeddedPatternText, FormatInfo, templateDate).UnderlyingPattern,
                    (bucket, value) =>
                {
                    var dateBucket                = dateBucketExtractor(bucket);
                    dateBucket.Calendar           = value.Calendar;
                    dateBucket.Year               = value.Year;
                    dateBucket.MonthOfYearNumeric = value.Month;
                    dateBucket.DayOfMonth         = value.Day;
                },
                    dateExtractor);
                break;

            case 't':
                AddField(PatternFields.EmbeddedTime, 'l');
                AddEmbeddedPattern(
                    LocalTimePattern.Create(embeddedPatternText, FormatInfo, templateTime).UnderlyingPattern,
                    (bucket, value) =>
                {
                    var timeBucket               = timeBucketExtractor(bucket);
                    timeBucket.Hours24           = value.Hour;
                    timeBucket.Minutes           = value.Minute;
                    timeBucket.Seconds           = value.Second;
                    timeBucket.FractionalSeconds = value.NanosecondOfSecond;
                },
                    timeExtractor);
                break;

            default:
                throw new InvalidOperationException("Bug in Noda Time: embedded pattern type wasn't date, time, or date+time");
            }
        }