コード例 #1
0
ファイル: DateTimeParser.cs プロジェクト: cosullivan/Era
 /// <summary>
 /// Attempt to make a date & time.
 /// </summary>
 /// <param name="builder">The date builder that was used to build the date & time.</param>
 /// <returns>true if a date & time could be made, false if not.</returns>
 internal bool TryMake(IDateTimeBuilder builder)
 {
     return(TryMakeWithEnd(TryMakeDateTime, builder) ||
            TryMakeWithEnd(TryMakeDate, builder) ||
            TryMakeWithEnd(TryMakeTime, builder) ||
            TryMakeWithEnd(TryMakeSingleDay, builder) ||
            TryMakeWithEnd(TryMakeNow, builder));
 }
コード例 #2
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="builder">The date/time builder to initialize the context with.</param>
 internal ParseContext(IDateTimeBuilder builder)
 {
     Year   = builder.Year;
     Month  = builder.Month;
     Day    = builder.Day;
     Hour   = builder.Hour;
     Minute = builder.Minute;
     Second = builder.Second;
 }
コード例 #3
0
        public void SetUp()
        {
            _dateTimeBuilder = Substitute.For <IDateTimeBuilder>(); //skal evt være den rigtige, da man ellers ikke kan få konverteret dato
            _uut             = new TrackObjectifier(_dateTimeBuilder);

            _stringList = new List <string>()
            {
                "ATR423;39045;12932;14000;20151006213456789"
            };

            _dateTimeBuilder.Build("20151006213456789").Returns(new DateTime(2015, 10, 06, 21, 34, 56, 789));
        }
コード例 #4
0
        public void SetUp()
        {
            _transponderReceiver = Substitute.For <ITransponderReceiver>();
            _trackTransmitter    = Substitute.For <ITrackTransmitter>();
            _dateTimeBuilder     = Substitute.For <IDateTimeBuilder>();

            _uut = new TrackObjectifier(_dateTimeBuilder);

            _trackReciever = new TrackReciever(_transponderReceiver, _uut, _trackTransmitter);

            _dateTimeBuilder.Build("20151006213456000").Returns(new DateTime(2015, 10, 06, 21, 34, 56));
            _list = new List <string> {
                "ATR423;39045;12932;14000;20151006213456000"
            };
        }
コード例 #5
0
ファイル: DateTimeParser.cs プロジェクト: cosullivan/Era
        /// <summary>
        /// Attempt to make a top level match that includes the end of stream.
        /// </summary>
        /// <param name="tryMakeFunction">The function to perform the match.</param>
        /// <param name="builder">The builder to accept the changes on.</param>
        /// <returns>true if the function was matched successfully, false if not.</returns>
        bool TryMakeWithEnd(TryMakeDelegate1 <ParseContext> tryMakeFunction, IDateTimeBuilder builder)
        {
            var context = new ParseContext(builder);
            var index   = Enumerator.Index;

            Enumerator.TakeWhile(TokenKind.Space);

            if (tryMakeFunction(context) && TryMakeEnd())
            {
                builder.Year   = context.Year;
                builder.Month  = context.Month;
                builder.Day    = context.Day;
                builder.Hour   = context.Hour;
                builder.Minute = context.Minute;
                builder.Second = context.Second;

                return(true);
            }

            Enumerator.Index = index;
            return(false);
        }
コード例 #6
0
        public static DateTime BuildFrom(
            this IDateTimeBuilder self, DateTime i, DateTimeFormat frm)
        {
            switch (frm)
            {
            case DateTimeFormat.DateOnly:
                return(self.Build(i.Year, i.Month, i.Day));

            case DateTimeFormat.Y:
                return(self.Build(i.Year));

            case DateTimeFormat.YM:
                return(self.Build(i.Year, i.Month));

            case DateTimeFormat.YMDhm:
                return(self.Build(i.Year, i.Month, i.Day, i.Hour, i.Minute));

            case DateTimeFormat.YMDhms:
                return(self.Build(i.Year, i.Month, i.Day, i.Hour, i.Minute, i.Second));

            default: throw new Exception("unknown DateTimeFormat");
            }
        }
コード例 #7
0
 public void SetUp()
 {
     _uut = new DateTimeBuilder();
 }
コード例 #8
0
ファイル: Parser.cs プロジェクト: cosullivan/Era
        /// <summary>
        /// Attempt to parse the given input into a usable format.
        /// </summary>
        /// <typeparam name="T">The element type to parse the input to.</typeparam>
        /// <param name="input">The input string to attempt to parse.</param>
        /// <param name="builder">The date builder to build the date into.</param>
        /// <returns>true if the input could be parsed, false if not.</returns>
        public static bool TryParse <T>(string input, IDateTimeBuilder <T> builder)
        {
            var parser = new DateTimeParser(new TokenEnumerator(new StringTokenReader(input)));

            return(parser.TryMake(builder));
        }
コード例 #9
0
ファイル: Extensions.cs プロジェクト: guneysus/underscore.net
 public static DateTime build(this IDateTimeBuilder that) => that.Build();
コード例 #10
0
 public TrackObjectifier(IDateTimeBuilder dateTimeBuilder)
 {
     _dateTimeBuilder = dateTimeBuilder;
 }