示例#1
0
        public void WithTemplateValue_PropertyFetch()
        {
            LocalTime newValue = new LocalTime(1, 23, 45);
            var       pattern  = LocalTimePattern.CreateWithInvariantCulture("HH").WithTemplateValue(newValue);

            Assert.AreEqual(newValue, pattern.TemplateValue);
        }
 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");
 }
示例#3
0
 public static LocalTime ParseIsoHhmmssToLocalTimeOrThrow(this string x)
 {
     return(LocalTimePattern
            .CreateWithInvariantCulture("HH':'mm':'ss")
            .Parse(x)
            .GetValueOrThrow());
 }
示例#4
0
 public static bool ParseProperty(Type type, string value, [NotNullWhen(returnValue: true)] out object?parsedValue)
 {
     if (type == typeof(DateTime) || type == typeof(DateTime?))
     {
         parsedValue = DateTime.Parse(value);
         return(true);
     }
     if (type == typeof(ZonedDateTime) || type == typeof(ZonedDateTime?))
     {
         parsedValue = LocalDateTimePattern.CreateWithInvariantCulture(DATETIME_PATTERN).Parse(value).GetValueOrThrow().InUtc();
         return(true);
     }
     if (type == typeof(LocalDateTime) || type == typeof(LocalDateTime?))
     {
         parsedValue = LocalDateTimePattern.CreateWithInvariantCulture(DATETIME_PATTERN).Parse(value).GetValueOrThrow();
         return(true);
     }
     if (type == typeof(LocalDate) || type == typeof(LocalDate?))
     {
         parsedValue = LocalDatePattern.CreateWithInvariantCulture(DATE_PATTERN).Parse(value).GetValueOrThrow();
         return(true);
     }
     if (type == typeof(LocalTime) || type == typeof(LocalTime?))
     {
         parsedValue = LocalTimePattern.CreateWithInvariantCulture(TIME_PATTERN).Parse(value).GetValueOrThrow();
         return(true);
     }
     parsedValue = null;
     return(false);
 }
示例#5
0
        private static JsonSerializerSettings JsonSettings()
        {
            var settings = new JsonSerializerSettings();
            var pattern  = new NodaPatternConverter <LocalTime>(LocalTimePattern.CreateWithInvariantCulture("HH':'mm"));

            settings.Converters.Add(pattern);
            return(settings);
        }
示例#6
0
        public void ToLocalTime_Valid(int hours, int minutes, int seconds, int nanos, string expectedResult)
        {
            var pattern   = LocalTimePattern.CreateWithInvariantCulture("HH:mm:ss.fffffffff");
            var timeOfDay = new TimeOfDay {
                Hours = hours, Minutes = minutes, Seconds = seconds, Nanos = nanos
            };
            var localTime = timeOfDay.ToLocalTime();

            Assert.AreEqual(expectedResult, pattern.Format(localTime));
        }
        public void ToTimeOfDay_Valid(string localTimeText, int expectedHours, int expectedMinutes, int expectedSeconds, int expectedNanos)
        {
            var pattern   = LocalTimePattern.CreateWithInvariantCulture("HH:mm:ss.fffffffff");
            var localTime = pattern.Parse(localTimeText).Value;
            var timeOfDay = localTime.ToTimeOfDay();

            Assert.AreEqual(expectedHours, timeOfDay.Hours);
            Assert.AreEqual(expectedMinutes, timeOfDay.Minutes);
            Assert.AreEqual(expectedSeconds, timeOfDay.Seconds);
            Assert.AreEqual(expectedNanos, timeOfDay.Nanos);
        }
 public TimeFormatSpecification(string format)
 {
     if (format == null)
     {
         throw new ArgumentNullException(nameof(format));
     }
     _hasOffset = HasOffset(format);
     if (_hasOffset)
     {
         _offsetPattern = OffsetTimePattern.CreateWithInvariantCulture(GetNodaTimePattern(format));
     }
     else
     {
         _localPattern = LocalTimePattern.CreateWithInvariantCulture(GetNodaTimePattern(format));
     }
 }
示例#9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="time"></param>
        /// <returns></returns>
        public static LocalTime Parse(string time)
        {
            try
            {
                var timePattern = LocalTimePattern.CreateWithInvariantCulture("h:mmtt");
                var parseResult = timePattern.Parse(time);
                if (parseResult.Success)
                {
                    return(parseResult.Value);
                }

                throw new InvalidOperationException("Time is in incorrect format (suggested:\"h:mmtt\" or 5:30PM)");
            }
            catch (Exception exception)
            {
                throw;
            }
        }
        /// <summary>
        /// Convert input data from json file to metrix of length VxV, where V is number of vertices in graph
        /// </summary>
        /// <param name="load">load is Data representation from json file</param>
        /// <returns></returns>
        public static Timetable[,] convert(Data load)
        {
            Timetable[,] finalData = new Timetable[load.nodeIndices.Length, load.nodeIndices.Length];
            foreach (Edge edge in load.edges)
            {
                if (edge.isTransfer)   //is transfer --> within town
                {
                    finalData[edge.from, edge.to] = new Timetable(true, LocalTimePattern.CreateWithInvariantCulture("HH:mm").Parse("00:00").Value);
                }
                else    //is not transfer --> must be edge between 2 towns
                //LocalTime duration = LocalTime.Parse(edge.duration);
                {
                    LocalTime   duration = LocalTimePattern.CreateWithInvariantCulture("HH:mm").Parse(edge.duration).Value;
                    int[]       lines    = new int[edge.timetable.Length];
                    LocalTime[] times    = new LocalTime[edge.timetable.Length];

                    for (int i = 0; i < edge.timetable.Length; i++)
                    {
                        int.TryParse(edge.timetable[i].line, out lines[i]);
                        times[i] = LocalTimePattern.CreateWithInvariantCulture("HH:mm").Parse(edge.timetable[i].departure).Value;
                    }

                    finalData[edge.from, edge.to] = new Timetable(duration, lines, times);
                }
            }

            for (int i = 0; i < load.nodeIndices.Length; i++)
            {
                for (int j = 0; j < load.nodeIndices.Length; j++)
                {
                    if (i == j)   //edge from town into that one town --> edge nullDistance set to true
                    {
                        finalData[i, j] = new Timetable(true);
                    }
                    else if (finalData[i, j] == null)
                    {
                        finalData[i, j] = new Timetable(false);
                    }
                }
            }

            return(finalData);
        }
        public static JsonSerializerOptions GetSerializerOptions()
        {
            var options = new JsonSerializerOptions
            {
                PropertyNameCaseInsensitive = true
            };

            var localTimeConverter = new NodaPatternConverter <LocalTime>(
                LocalTimePattern.CreateWithInvariantCulture("HH:mm"));
            var localDateConverter = new NodaPatternConverter <LocalDate>(
                LocalDatePattern.CreateWithInvariantCulture("yyyy-MM-dd"));

            options.Converters.Add(localTimeConverter);
            options.Converters.Add(localDateConverter);
            options.Converters.Add(new DecimalConverter());
            options.Converters.Add(new LongConverter());
            options.Converters.Add(new IntConverter());
            options.Converters.Add(new DateTimeConverter());
            options.Converters.Add(new JsonStringEnumConverter());

            return(options);
        }
示例#12
0
        public void TemplateValue_DefaultsToMidnight()
        {
            var pattern = LocalTimePattern.CreateWithInvariantCulture("HH");

            Assert.AreEqual(LocalTime.Midnight, pattern.TemplateValue);
        }
示例#13
0
 public void CreateWithInvariantCulture_NullPatternText()
 {
     Assert.Throws <ArgumentNullException>(() => LocalTimePattern.CreateWithInvariantCulture(null));
 }
示例#14
0
 internal override IPattern <LocalTime> CreatePattern() =>
 LocalTimePattern.CreateWithInvariantCulture(Pattern)
 .WithTemplateValue(Template)
 .WithCulture(Culture);
示例#15
0
 /// <summary>
 /// Auxiliar method for time parsing
 /// </summary>
 /// <param name="time"></param>
 /// <returns></returns>
 public LocalTime parseTime(string time)
 {
     return(LocalTimePattern.CreateWithInvariantCulture("HH:mm").Parse(time).Value);
 }
示例#16
0
 public static ParseResult <LocalTime> TryParseIsoHhmmssToLocalTime(this string x)
 {
     return(LocalTimePattern
            .CreateWithInvariantCulture("HH':'mm':'ss")
            .Parse(x));
 }