Ejemplo n.º 1
0
    public void DateMask_TwoDigitYear()
    {
        var mask = new DateMask("MM/dd/yy");

        // input invalid month and day, simple cases
        mask.Insert("9999");
        mask.ToString().Should().Be("09/09/99|");
        mask.Clear();
        mask.Insert("2 4 22");
        mask.ToString().Should().Be("02/04/22|");
        mask.Clear();
        // special cases that need awareness about the days in a month
        mask.Clear();
        mask.Insert("01 32");
        mask.ToString().Should().Be("01/31/|");
        mask.Clear();
        // invalid feb
        mask.Clear();
        mask.Insert("02 3 00");
        mask.ToString().Should().Be("02/03/00|");
        // year 0000 was a leap year
        mask.Clear();
        mask.Insert("02 29");
        mask.ToString().Should().Be("02/29/|");
        // year is at the back so it should correct feb 29th to 28th once it is entered
        mask.Clear();
        mask.Insert("02 29 0");
        mask.ToString().Should().Be("02/29/0|");
        mask.Insert("1");
        mask.ToString().Should().Be("02/28/01|");
    }
        // for existing request
        public RequestViewModel(Request request) : base(request)
        {
            InitializeCommands();
            Vehicle   = new VehicleViewModel(Model.getVehicle());
            VinNumber = Vehicle.VinNumber;
            Requestor = new UserViewModel(Model.getRequestor());
            if (Model.isApproved())
            {
                Approver = new UserViewModel(Model.getApprover());
            }
            Driver        = new UserViewModel(Model.getDriver());
            DriverLicense = Requestor.DriverLicense;
            var start = Model.getPlannedTripStart();
            var end   = Model.getPlannedTripEnd();

            this.plannedStartDate = start.ToString("MM/dd/yyyy");
            this.plannedEndDate   = end.ToString("MM/dd/yyyy");
            PlannedStartHour      = start.Hour;
            PlannedEndHour        = end.Hour;
            PlannedStartDateMask  = new DateMask();
            PlannedEndDateMask    = new DateMask();
            foreach (var passenger in Model.getPassengers())
            {
                Passengers.Add(new Tuple <string, Person>(passenger.getFullName(), passenger));
            }
        }
Ejemplo n.º 3
0
    public void DateMask_UpdateFrom()
    {
        var mask = new DateMask("MM/dd/yyyy");

        mask.UpdateFrom(new DateMask("jjjj-mm-tt", 'j', 'm', 't'));
        mask.Insert("2222 2 4");
        mask.ToString().Should().Be("2222-02-04|");
    }
 public TripViewModel() : base(new Trip(), isNew: true)
 {
     StartedOn       = DateTime.Today.ToString("MM/dd/yyyy");
     StartedAtHour   = DateTime.Now.Hour;
     GarageAttendant = new UserViewModel(ClientSecurityContext.CurrentUser);
     StartDateMask   = new DateMask();
     EndDateMask     = new DateMask();
 }
Ejemplo n.º 5
0
    public void DateMask_WithPlaceholder()
    {
        var mask = new DateMask("yyyy-MM-dd")
        {
            Placeholder = '_'
        };

        // input invalid text
        mask.ToString().Should().Be("|");
        mask.Insert("?asdfqa vyczlausdhf!°§$\"%\"$\"&\"");
        mask.ToString().Should().Be("|");
        // input invalid month and day, simple cases
        mask.Insert("9999");
        mask.ToString().Should().Be("9999-|__-__");
        mask.Insert("9");
        mask.ToString().Should().Be("9999-09-|__");
        mask.Insert("9");
        mask.ToString().Should().Be("9999-09-09|");
        mask.Clear();
        mask.Insert("2222 2 4");
        mask.ToString().Should().Be("2222-02-04|");
        mask.Clear();
        // month and day must be > 0
        mask.Insert("2222 00 00");
        mask.ToString().Should().Be("2222-01-01|");
        mask.Clear();
        // month must be < 13
        mask.Insert("0000 13");
        mask.ToString().Should().Be("0000-12-|__");
        mask.Clear();
        // special cases that need awareness about the days in a month
        mask.Clear();
        mask.Insert("0000 01 32");
        mask.ToString().Should().Be("0000-01-31|");
        mask.Clear();
        // year 0000 was a leap year
        mask.Clear();
        mask.Insert("0000 02 3");
        mask.ToString().Should().Be("0000-02-03|");
        // try to paste invalid day
        mask.Selection = (8, 10);
        mask.ToString().Should().Be("0000-02-[03]");
        mask.Insert("44");
        mask.ToString().Should().Be("0000-02-04|");
        // ordinary feb
        mask.Clear();
        mask.Insert("0001 02 29");
        mask.ToString().Should().Be("0001-02-28|");
        mask.Selection = (8, 10);
        mask.ToString().Should().Be("0001-02-[28]");
        mask.Insert("29");
        mask.ToString().Should().Be("0001-02-28|");
        // mar
        mask.Clear();
        mask.Insert("0000 03 33");
        mask.ToString().Should().Be("0000-03-31|");
        mask.Clear();
    }
Ejemplo n.º 6
0
    public void DateMask_CustomChars()
    {
        var mask = new DateMask("jjjj-mm-tt", 'j', 'm', 't');

        mask.Insert("2222 2 4");
        mask.ToString().Should().Be("2222-02-04|");
        mask = new DateMask("tt.mm.jjjj", 'j', 'm', 't');
        mask.Insert("421999");
        mask.ToString().Should().Be("04.02.1999|");
    }
Ejemplo n.º 7
0
        protected void ReadIndex(ITextualReader reader)
        {
            string line = NextLine(reader);

            while (!String.IsNullOrEmpty(line))
            {
                string field = ReadField(ref line);
                Names.Add(field);

                if (DateMask.Match(field))
                {
                    Index.Add(CsvHeadersEnum.FIELD_DATE);
                }
                else if (DateAuxMask.Match(field))
                {
                    Index.Add(CsvHeadersEnum.FIELD_DATE_AUX);
                }
                else if (CodeMask.Match(field))
                {
                    Index.Add(CsvHeadersEnum.FIELD_CODE);
                }
                else if (PayeeMask.Match(field))
                {
                    Index.Add(CsvHeadersEnum.FIELD_PAYEE);
                }
                else if (AmountMask.Match(field))
                {
                    Index.Add(CsvHeadersEnum.FIELD_AMOUNT);
                }
                else if (CostMask.Match(field))
                {
                    Index.Add(CsvHeadersEnum.FIELD_COST);
                }
                else if (TotalMask.Match(field))
                {
                    Index.Add(CsvHeadersEnum.FIELD_TOTAL);
                }
                else if (NoteMask.Match(field))
                {
                    Index.Add(CsvHeadersEnum.FIELD_NOTE);
                }
                else
                {
                    Index.Add(CsvHeadersEnum.FIELD_UNKNOWN);
                }

                Logger.Current.Debug("csv.parse", () => String.Format("Header field: {0}", field));
            }
        }
 // for new request
 public RequestViewModel() : base(new Request(), isNew: true)
 {
     InitializeCommands();
     Model.setRequestId(GenerateRequestId());
     Model.setPlannedTripStart(DateTime.Today);
     Model.setPlannedTripEnd(DateTime.Today);
     Model.setRequestor(ClientSecurityContext.CurrentUser);
     Requestor            = new UserViewModel(ClientSecurityContext.CurrentUser);
     DriverLicense        = Requestor.DriverLicense;
     PlannedTripStart     = PlannedTripEnd = DateTime.Today.ToString("MM/dd/yyyy");
     PlannedStartHour     = 8;
     PlannedEndHour       = 9;
     PlannedStartDateMask = new DateMask();
     PlannedEndDateMask   = new DateMask();
 }
Ejemplo n.º 9
0
    public void DateMask_Backspace()
    {
        var mask = new DateMask("MM/dd/yy");

        mask.Insert("12/31/99");
        // backspace creates invalid day 39
        mask.CaretPos = 5;
        mask.ToString().Should().Be("12/31|/99");
        mask.Backspace();
        mask.ToString().Should().Be("12/3|1/9");
        // backspace creates invalid month 13
        mask.CaretPos = 2;
        mask.ToString().Should().Be("12|/31/9");
        mask.Backspace();
        mask.ToString().Should().Be("1|2/19/");
    }
Ejemplo n.º 10
0
    public void DateMask_Delete()
    {
        var mask = new DateMask("MM/dd/yy");

        mask.Insert("12/31/99");
        // delete creates invalid day 39
        mask.CaretPos = 4;
        mask.ToString().Should().Be("12/3|1/99");
        mask.Delete();
        mask.ToString().Should().Be("12/3|1/9");
        // delete creates invalid month 13
        mask.CaretPos = 1;
        mask.ToString().Should().Be("1|2/31/9");
        mask.Delete();
        mask.ToString().Should().Be("1|2/19/");
    }
Ejemplo n.º 11
0
    public void DateMask_WithoutDay()
    {
        var mask = new DateMask("yy/MM");

        // input invalid month and day, simple cases
        mask.Insert("9999");
        mask.ToString().Should().Be("99/09|");
        mask.Clear();
        mask.Insert("02 4");
        mask.ToString().Should().Be("02/04|");
        mask.Clear();
        // month check
        mask.Clear();
        mask.Insert("01 13");
        mask.ToString().Should().Be("01/12|");
        mask.Clear();
        mask.Insert("00 00");
        mask.ToString().Should().Be("00/01|");
    }
        public TripViewModel(Trip trip) : base(trip)
        {
            Request         = new RequestViewModel(Model.getRequest());
            RequestId       = Request.RequestId;
            GarageAttendant = new UserViewModel(ClientSecurityContext.CurrentUser);

            var start = Model.getStartedAt();

            StartedOn     = start.ToString("MM/dd/yyyy");
            StartedAtHour = start.Hour;

            var end = Model.getFinishedAt();

//         if(end == null && IsEnabled)
//            end = DateTime.Now;

            FinishedOn     = end?.ToString("MM/dd/yyyy");
            FinishedAtHour = end?.Hour ?? DateTime.Now.Hour;

            StartDateMask = new DateMask();
            EndDateMask   = new DateMask();
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Ported from draft_t::parse_args
        /// </summary>
        protected void ParseArgs(Value args)
        {
            Match what         = Match.Empty;
            bool  checkForDate = true;

            Tmpl = new DraftXactTemplate();

            DayOfWeek?            weekday;
            DraftXactPostTemplate post = null;

            IList <Value> argsSequence = args.AsSequence;
            Value         endVal       = argsSequence.LastOrDefault();

            for (int index = 0; index < argsSequence.Count; index++)
            {
                Value val = argsSequence[index];

                if (checkForDate && (what = DateMask.Match(val.AsString)).Length > 0)
                {
                    Tmpl.Date    = TimesCommon.Current.ParseDate(what.Value);
                    checkForDate = false;
                }
                else if (checkForDate && (weekday = DateParserLexer.StringToDayOfWeek(what.Value)).HasValue)
                {
                    Date date = TimesCommon.Current.CurrentDate.AddDays(-1);
                    while (date.DayOfWeek != weekday)
                    {
                        date = date.AddDays(-1);
                    }
                    Tmpl.Date    = date;
                    checkForDate = false;
                }
                else
                {
                    string arg = val.AsString;

                    if (arg == "at")
                    {
                        if (val == endVal)
                        {
                            throw new RuntimeError(RuntimeError.ErrorMessageInvalidXactCommandArguments);
                        }
                        Tmpl.PayeeMask = new Mask(argsSequence[++index].AsString);
                    }
                    else if (arg == "to" || arg == "from")
                    {
                        if (post == null || post.AccountMask != null)
                        {
                            Tmpl.Posts.Add(post = new DraftXactPostTemplate());
                        }
                        if (val == endVal)
                        {
                            throw new RuntimeError(RuntimeError.ErrorMessageInvalidXactCommandArguments);
                        }
                        post.AccountMask = new Mask(argsSequence[++index].AsString);
                        post.From        = arg == "from";
                    }
                    else if (arg == "on")
                    {
                        if (val == endVal)
                        {
                            throw new RuntimeError(RuntimeError.ErrorMessageInvalidXactCommandArguments);
                        }
                        Tmpl.Date    = TimesCommon.Current.ParseDate(argsSequence[++index].AsString);
                        checkForDate = false;
                    }
                    else if (arg == "code")
                    {
                        if (val == endVal)
                        {
                            throw new RuntimeError(RuntimeError.ErrorMessageInvalidXactCommandArguments);
                        }
                        Tmpl.Code = argsSequence[++index].AsString;
                    }
                    else if (arg == "note")
                    {
                        if (val == endVal)
                        {
                            throw new RuntimeError(RuntimeError.ErrorMessageInvalidXactCommandArguments);
                        }
                        Tmpl.Note = argsSequence[++index].AsString;
                    }
                    else if (arg == "rest")
                    {
                        // just ignore this argument
                    }
                    else if (arg == "@" || arg == "@@")
                    {
                        Amount cost = new Amount();
                        post.CostOperator = arg;
                        if (val == endVal)
                        {
                            throw new RuntimeError(RuntimeError.ErrorMessageInvalidXactCommandArguments);
                        }
                        arg = argsSequence[++index].AsString;
                        if (!cost.Parse(ref arg, AmountParseFlagsEnum.PARSE_SOFT_FAIL | AmountParseFlagsEnum.PARSE_NO_MIGRATE))
                        {
                            throw new RuntimeError(RuntimeError.ErrorMessageInvalidXactCommandArguments);
                        }
                        post.Cost = cost;
                    }
                    else
                    {
                        // Without a preposition, it is either:
                        //
                        //  A payee, if we have not seen one
                        //  An account or an amount, if we have
                        //  An account if an amount has just been seen
                        //  An amount if an account has just been seen

                        if (Tmpl.PayeeMask == null)
                        {
                            Tmpl.PayeeMask = new Mask(arg);
                        }
                        else
                        {
                            Amount amt     = new Amount();
                            Mask   account = null;

                            string argToParse = arg;
                            if (!amt.Parse(ref argToParse, AmountParseFlagsEnum.PARSE_SOFT_FAIL | AmountParseFlagsEnum.PARSE_NO_MIGRATE))
                            {
                                account = new Mask(arg);
                            }

                            if (post == null || (account != null && post.AccountMask != null) || (account == null && post.Amount != null))
                            {
                                Tmpl.Posts.Add(post = new DraftXactPostTemplate());
                            }

                            if (account != null)
                            {
                                post.AccountMask = account;
                            }
                            else
                            {
                                post.Amount = amt;
                                post        = null; // an amount concludes this posting
                            }
                        }
                    }
                }
            }

            if (Tmpl.Posts.Any())
            {
                // A single account at the end of the line is the "from" account
                if (Tmpl.Posts.Count > 1 && Tmpl.Posts.Last().AccountMask != null && !(bool)Tmpl.Posts.Last().Amount)
                {
                    Tmpl.Posts.Last().From = true;
                }

                bool hasOnlyFrom = !Tmpl.Posts.Any(p => !p.From);
                bool hasOnlyTo   = !Tmpl.Posts.Any(p => p.From);

                if (hasOnlyFrom)
                {
                    Tmpl.Posts.Insert(0, new DraftXactPostTemplate());
                }
                else if (hasOnlyTo)
                {
                    Tmpl.Posts.Add(new DraftXactPostTemplate()
                    {
                        From = true
                    });
                }
            }
        }