public void SetDisplayedDateTo_SomeDateTime_ReturnsSameDateTime()
        {
            DateTime aDateTime = It.IsAny <DateTime>();

            DateUtilities.SetDisplayedDateTo(aDateTime);
            Assert.AreEqual(aDateTime, DateUtilities.DisplayedDate);
        }
예제 #2
0
        public static string GetSignature(long userId, DateTime entryDate)
        {
            var user  = BlUser.LoadSingle(userId);
            var label = BlDescription.GetDescription(Enumerations.DescriptionResources.Language, "lblSignature", user.LanguageId);

            return(string.Format(label, user.UserName, DateUtilities.FormatDateForDisplay(entryDate, true)));
        }
예제 #3
0
        /// <summary>
        /// User has changed the text
        /// </summary>
        /// <param name="sender">The sender object</param>
        /// <param name="e">Event arguments</param>
        private void OnTextHasChangedByUser(object sender, EventArgs e)
        {
            this.explorerPresenter.CommandHistory.ModelChanged -= this.OnModelChanged;
            List <Operation> operations = new List <Operation>();

            foreach (string line in this.view.Lines)
            {
                string currentLine = line;
                bool   isComment   = line.Trim().StartsWith("//");
                if (isComment)
                {
                    int index = line.IndexOf("//");
                    if (index >= 0)
                    {
                        currentLine = currentLine.Remove(index, 2).Trim();
                    }
                }

                int pos = currentLine.IndexOf(' ');
                if (pos != -1)
                {
                    Operation operation = new Operation();
                    operation.Date    = DateUtilities.validateDateString(currentLine.Substring(0, pos));
                    operation.Action  = currentLine.Substring(pos + 1);
                    operation.Enabled = !isComment;
                    operations.Add(operation);
                }
            }

            this.explorerPresenter.CommandHistory.Add(new Commands.ChangeProperty(this.operations, "Schedule", operations));
            this.explorerPresenter.CommandHistory.ModelChanged += this.OnModelChanged;
        }
예제 #4
0
        /// <summary>
        /// Calculate Loan.
        /// </summary>
        /// <returns>Calculated LoanEntity Object.</returns>
        public LoanEntity Calculate()
        {
            var IDate = this.loanEntity.CValueDate;

            for (int i = 0; i < this.loanEntity.CInstallmentCount; i++)
            {
                this.loanEntity.AmortizationSchedule.Add(new AmortizationScheduleRow
                {
                    IRowNumber    = i + 1,
                    IValueDate    = i == 0 ? this.loanEntity.CValueDate : DateUtilities.AddMonth(this.loanEntity.CFirstInstallmentDate, i - 1),
                    IMaturityDate = DateUtilities.AddMonth(this.loanEntity.CFirstInstallmentDate, i),
                    IProfitRate   = this.loanEntity.CProfitRate,
                    IBsmvRate     = this.loanEntity.CBsmvRate,
                    IKkdfRate     = this.loanEntity.CKkdfRate,
                    IKdvRate      = this.loanEntity.CKdvRate
                });
            }

            //this.loanEntity.AmortizationSchedule.FirstOrDefault(s => s.IRowNumber == 1).IFixity = FixityTypes.InstallmentAmount;
            //this.loanEntity.AmortizationSchedule.FirstOrDefault(s => s.IRowNumber == 1).IAmount = 500000;

            //Taksit Tarihlerini iş gününe geliyorsa ötele
            foreach (var row in this.loanEntity.AmortizationSchedule)
            {
                if (row.IRowNumber > 1)
                {
                    row.IValueDate = DateUtilities.GetBusinessDay(row.IValueDate, culture);
                }
                row.IMaturityDate = DateUtilities.GetBusinessDay(row.IMaturityDate, culture);
            }

            var installment = new Installment();

            return(installment.CalculateInstallments(this.loanEntity));
        }
예제 #5
0
 public AccrualLoan()
 {
     this.Amount            = (decimal)(new Random().Next(30, 70));
     this.ExpiryDate        = DateUtilities.GetFirstDayOfNextMonth().AddDays((double)(new Random().Next(4, 19)));
     this.CollectionRecords = new List <CollectionRecord>();
     this.RefNumber         = StringUtilities.GenerateKey(7).ToUpper();
 }
예제 #6
0
        public static void StopListening(string url, string agentId)
        {
            AgentInstructions instr = new AgentInstructions()
            {
                Id                          = Guid.NewGuid().ToString(),
                EntityName                  = "Stop Listening on " + url,
                MustBeCompletedBy           = DateUtilities.Now(),
                AgentInstructionHanlderType = "Decisions.OPC.Agent.StopListeningInstructionHandler",
                Data                        = new[]
                {
                    new DataPair("opcServerUrl", url),
                }
            };

            AgentService.Instance.InstructAgent(new SystemUserContext(), agentId, instr);

            string ignored; // Forget this instruction & refresh folder, so IsListening will immediately switch to false:

            pingInstructionIdPerAgent.TryRemove(url + agentId, out ignored);

            Folder configFolder = EntityCache <OPCServerFolderBehaviorData> .GetCache().AllEntities.FirstOrDefault(s => s.Url == url)?.GetEntity() as Folder;

            if (configFolder == null)
            {
                return;
            }
            ClientEventsService.SendEvent(FolderMessage.FolderChangeEventId, new FolderChangedMessage(configFolder.FolderID));
        }
예제 #7
0
        public static async Task <IGeneration> AdvanceGenerationAsync(this SQLiteDatabase database)
        {
            IGeneration generation = await database.GetCurrentGenerationOrNullAsync();

            if (generation != null)
            {
                // Update the end date of the current generation.

                generation.EndDate = DateUtilities.GetCurrentDateUtc();

                await database.UpdateGenerationAsync(generation);
            }

            // Create and add the next generation.

            generation = new Generation {
                Number    = generation is null ? 1 : generation.Number + 1,
                StartDate = generation is null ? DateTimeOffset.MinValue : DateUtilities.GetCurrentDateUtc(),
                EndDate   = DateTimeOffset.MaxValue
            };

            await database.AddGenerationAsync(generation);

            return(generation);
        }
예제 #8
0
        // 3. Public methods
        //-----------------------------------------------------------------------------------------------------------------

        /// <summary>Computes the phenological development during one time-step.</summary>
        /// <remarks>Returns true when target is met.</remarks>
        public bool DoTimeStep(ref double propOfDayToUse)
        {
            bool proceedToNextPhase = false;

            TTForTimeStep = phenology.thermalTime.Value() * propOfDayToUse;
            if (EmergenceDate != null)
            {
                Target = (DateUtilities.GetDate(EmergenceDate, clock.Today) - plant.SowingDate).TotalDays;
                ProgressThroughPhase += 1;
                if (DateUtilities.DatesEqual(EmergenceDate, clock.Today))
                {
                    proceedToNextPhase = true;
                }
            }
            else
            {
                ProgressThroughPhase += TTForTimeStep;
                if (ProgressThroughPhase > Target)
                {
                    if (TTForTimeStep > 0.0)
                    {
                        proceedToNextPhase = true;
                        propOfDayToUse     = (ProgressThroughPhase - Target) / TTForTimeStep;
                        TTForTimeStep     *= (1 - propOfDayToUse);
                    }
                    ProgressThroughPhase = Target;
                }
            }
            return(proceedToNextPhase);
        }
예제 #9
0
        private Student CreateStudentFromFields()
        {
            int      studentId   = Int32.Parse(txtStudentId.Text);
            DateTime dateOfBirth = DateUtilities.StringToDateTimeES(txtDateOfBirth.Text);

            return(new Student(studentId, txtName.Text, txtSurname.Text, dateOfBirth));
        }
예제 #10
0
        private void OnStartOfDay(object sender, EventArgs e)
        {
            if (ChildFunctions == null)
            {
                ChildFunctions = FindAllChildren <IFunction>().ToList();
            }

            if (DateUtilities.WithinDates(StartDate, clock.Today, EndDate))
            {
                //Accumulate values at the start of each day
                double DailyIncrement = 0.0;
                foreach (IFunction function in ChildFunctions)
                {
                    DailyIncrement += function.Value();
                }

                AccumulatedValue += DailyIncrement;
            }

            //Zero value if today is reset date
            if (DateUtilities.WithinDates(ResetDate, clock.Today, ResetDate))
            {
                AccumulatedValue = 0;
            }
        }
예제 #11
0
파일: Draft.cs 프로젝트: lie112/ApsimX
        private void OnDoManagement(object sender, EventArgs e)
        {
            if (DateUtilities.WithinDates(StartDate, clock.Today, EndDate))
            {
                if (TypeOfDraft == DraftType.Fixed)
                {
                    // Loop through all tag numbers.
                    for (int t = 0; t < TagNumbers.Length; t++)
                    {
                        // Find the animal groups that have the tag number and move them to the
                        // specified padock.
                        foreach (var group in stock.StockModel.Animals.Skip(1).Where(g => g.Tag == TagNumbers[t]))
                        {
                            group.MoveToPaddock(PaddockNames[t]);
                        }
                    }
                }
                else
                {
                    var fullStartDate = DateUtilities.GetDate(StartDate, clock.Today);
                    if (fullStartDate > clock.Today)
                    {
                        fullStartDate = fullStartDate.AddYears(-1);
                    }
                    var numDaysSinceStartDate = (clock.Today - fullStartDate).Days;

                    // Flexible grazing
                    // X day intervals from the start of the period - is this the check day or day one?
                    if (CheckEvery > 0 && numDaysSinceStartDate % CheckEvery == 0)
                    {
                        MoveAnimals();
                    }
                }
            }
        }
예제 #12
0
 public async Task <RecentDealResponse> GetRecentlyCreatedDealsAsync(DateTimeOffset greaterThanEpoch, int limit = 20, int offset = 0) =>
 await GetAsync <RecentDealResponse>("deals/v1/deal/recent/created", new List <QueryStringParameter>
 {
     new QueryStringParameter("offset", offset),
     new QueryStringParameter("limit", limit),
     new QueryStringParameter("since", DateUtilities.ConvertDatetimeToUnixTimeStamp(greaterThanEpoch))
 });
예제 #13
0
 public async Task <DomainResponse> GetDomainsAsync(DateTimeOffset greaterThanEpoch, int limit = 20, int offset = 0) =>
 await GetAsync <DomainResponse>("content/api/v4/domains", new List <QueryStringParameter>
 {
     new QueryStringParameter("offset", offset),
     new QueryStringParameter("limit", limit),
     new QueryStringParameter("created__gt", DateUtilities.ConvertDatetimeToUnixTimeStamp(greaterThanEpoch))
 });
예제 #14
0
 public async Task <UrlMappingResponse> GetUrlMappingsAsync(DateTimeOffset greaterThanEpoch, int limit = 100, int offset = 0) =>
 await GetAsync <UrlMappingResponse>("url-mappings/v3/url-mappings", new List <QueryStringParameter>
 {
     new QueryStringParameter("offset", offset),
     new QueryStringParameter("limit", limit),
     new QueryStringParameter("created__gt", DateUtilities.ConvertDatetimeToUnixTimeStamp(greaterThanEpoch))
 });
예제 #15
0
 public async Task <TopicResponse> GetBlogTopicsAsync(DateTimeOffset greaterThanEpoch, int limit = 20, int offset = 0) =>
 await GetAsync <TopicResponse>("blogs/v3/topics", new List <QueryStringParameter>
 {
     new QueryStringParameter("offset", offset),
     new QueryStringParameter("limit", limit),
     new QueryStringParameter("created__gt", DateUtilities.ConvertDatetimeToUnixTimeStamp(greaterThanEpoch))
 });
예제 #16
0
        // 4. Public method
        //-----------------------------------------------------------------------------------------------------------------

        /// <summary>Compute the phenological development during one time-step.</summary>
        /// <remarks>Returns true when target is met.</remarks>
        public bool DoTimeStep(ref double propOfDayToUse)
        {
            bool proceedToNextPhase = false;

            if (GerminationDate != null)
            {
                if (DateUtilities.DatesEqual(GerminationDate, clock.Today))
                {
                    proceedToNextPhase = true;
                    propOfDayToUse     = 1;
                }
            }

            else if (!phenology.OnStartDayOf("Sowing") && soil.Water[SowLayer] > soil.LL15mm[SowLayer])
            {
                // Invoke an AboutToSow event.
                if (SeedImbibed != null)
                {
                    SeedImbibed.Invoke(this, new EventArgs());
                }
                proceedToNextPhase = true;
                propOfDayToUse     = 1;
            }

            return(proceedToNextPhase);
        }
예제 #17
0
 public async Task <IList <BroadcastMessage> > GetBroadcastMessagesAsync(DateTimeOffset greaterThanEpoch, int limit = 100, int offset = 0) =>
 await GetAsync <IList <BroadcastMessage> >("broadcast/v1/broadcasts", new List <QueryStringParameter>
 {
     new QueryStringParameter("offset", offset),
     new QueryStringParameter("limit", limit),
     new QueryStringParameter("since", DateUtilities.ConvertDatetimeToUnixTimeStamp(greaterThanEpoch))
 });
예제 #18
0
        /// <summary>
        /// Sanitises the event names and removes duplicates/comments.
        /// </summary>
        /// <returns></returns>
        protected string[] TidyUpEventNames()
        {
            List <string> eventNames = new List <string>();

            for (int i = 0; i < EventNames?.Length; i++)
            {
                string eventName = EventNames[i];

                // If there is a comment in this line, ignore everything after (and including) the comment.
                int commentIndex = eventName.IndexOf("//");
                if (commentIndex >= 0)
                {
                    eventName = eventName.Substring(0, commentIndex);
                }

                if (!string.IsNullOrWhiteSpace(eventName))
                {
                    if (DateUtilities.validateDateString(eventName) != null)
                    {
                        dateStringsToReportOn.Add(eventName);
                    }
                    else
                    {
                        eventNames.Add(eventName.Trim());
                    }
                }
            }

            return(eventNames.ToArray());
        }
예제 #19
0
 public async Task <FileMetaDataResponse> GetFilesAsync(DateTimeOffset greaterThanEpoch, int limit = 20, int offset = 0) =>
 await GetAsync <FileMetaDataResponse>("filemanager/api/v2/files", new List <QueryStringParameter>
 {
     new QueryStringParameter("offset", offset),
     new QueryStringParameter("limit", limit),
     new QueryStringParameter("created__gt", DateUtilities.ConvertDatetimeToUnixTimeStamp(greaterThanEpoch))
 });
예제 #20
0
 private void OnStartOfDay(object sender, EventArgs e)
 {
     if ((Start) && (TypeOfInfestation == InfestationType.OnStart))
     {
         Infest();
         Start = false;
         return;
     }
     else if (TypeOfInfestation == InfestationType.OnDate)
     {
         if (DateUtilities.DatesEqual(InfestationDate, Clock.Today))
         {
             Infest();
         }
         return;
     }
     else if (TypeOfInfestation == InfestationType.BetweenDates)
     {
         if (DateUtilities.WithinDates(InfestationDate, Clock.Today, InfestationEndDate))
         {
             Infest();
         }
         return;
     }
     else if (TypeOfInfestation == InfestationType.Continious)
     {
         Infest();
         return;
     }
 }
예제 #21
0
        // Public members

        public static void SetHeader(this IHttpWebRequest httpWebRequest, string headerName, string value)
        {
            // A list of restricted headers can be found here: https://stackoverflow.com/a/4752359/5383169 (dubi)

            switch (headerName.ToLowerInvariant())
            {
            case "accept":
                httpWebRequest.Accept = value;
                break;

            case "connection":
                SetConnectionHeader(httpWebRequest, value);
                break;

            case "content-length":
                httpWebRequest.ContentLength = long.Parse(value, NumberStyles.Integer, CultureInfo.InvariantCulture);
                break;

            case "content-type":
                httpWebRequest.ContentType = value;
                break;

            case "date":
                httpWebRequest.Date = DateUtilities.ParseHttpHeader(value).DateTime;
                break;

            case "expect":
                httpWebRequest.Expect = value;
                break;

            case "host":
                httpWebRequest.Host = value;
                break;

            case "if-modified-since":
                httpWebRequest.IfModifiedSince = DateUtilities.ParseHttpHeader(value).DateTime;
                break;

            case "range":
                SetRangeHeader(httpWebRequest, value);
                break;

            case "referer":
                httpWebRequest.Referer = value;
                break;

            case "transfer-encoding":
                httpWebRequest.TransferEncoding = value;
                break;

            case "user-agent":
                httpWebRequest.UserAgent = value;
                break;

            default:
                httpWebRequest.Headers.Set(headerName, value);
                break;
            }
        }
예제 #22
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="stream"></param>
        private void LoadMetaData(Stream stream)
        {
            stream.Position = 0;
            using (var reader = new StreamReader(stream, Encoding.UTF8))
            {
                string line;
                bool   foundheader = false;
                while ((line = reader.ReadLine()) != null)
                {
                    List <String> items = new List <String>(line.Trim().Split(new string[] { " ", "\t", "," }, StringSplitOptions.RemoveEmptyEntries));
                    if (items[0] != "//")
                    {
                        if (foundheader == false)
                        {
                            //Parse the header

                            float lat;
                            float lon;
                            if (float.TryParse(items[0], out lat))
                            {
                                Latitude = lat;
                            }
                            if (float.TryParse(items[1], out lon))
                            {
                                Longitude = lon;
                            }

                            items.RemoveRange(0, 2);
                            Comments = String.Join(" ", items.ToArray());

                            foundheader = true;
                        }
                        else
                        {
                            if (items.Count() == 8)
                            {
                                var date = DateUtilities.TryParseDate(items[0]);
                                if (date != null)
                                {
                                    if (StartDate == null)
                                    {
                                        StartDate = date;
                                    }
                                    //Parse the met data
                                    EndDate = date;

                                    MaxT.Add(double.Parse(items[2]));
                                    MinT.Add(double.Parse(items[3]));
                                    Rain.Add(double.Parse(items[4]));
                                    PanEvap.Add(double.Parse(items[5]));
                                    Radiation.Add(double.Parse(items[6]));
                                    VP.Add(double.Parse(items[7]));
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #23
0
 public override string ToString()
 {
     return(StudentId + "," +
            Name + "," +
            Surname + "," +
            DateUtilities.DateTimeToStringES(DateOfBirth) +
            "\n");
 }
예제 #24
0
        private static int GetfirstDayGridColumnIndex()
        {
            DateTime displayedDate            = DateUtilities.DisplayedDate;
            DateTime firstDayOfDisplayedMonth = new DateTime(displayedDate.Year, displayedDate.Month, firstDayNumberInMonth);
            int      firstDayGridColumnIndex  = DateUtilities.GetDayNumberInWeek(firstDayOfDisplayedMonth) - gridColumnIndexOffset;

            return(firstDayGridColumnIndex);
        }
예제 #25
0
        /// <summary>An event handler called at the end of each day.</summary>
        /// <param name="sender">Event sender</param>
        /// <param name="e">Event arguments</param>
        private void OnDoReport(object sender, EventArgs e)
        {
            Clock clock = sender as Clock;

            if (DateUtilities.DatesAreEqual(dateString, clock.Today))
            {
                report.DoOutput();
            }
        }
예제 #26
0
 /// <summary>
 /// Try and parse a frequency line and return an instance of a IReportFrequency.
 /// </summary>
 /// <param name="line">The line to parse.</param>
 /// <param name="report">An instance of a report model.</param>
 /// <param name="events">An instance of an events publish/subcribe interface.</param>
 /// <returns>true if line was able to be parsed.</returns>
 public static bool TryParse(string line, Report report, IEvent events)
 {
     if (DateUtilities.validateDateString(line) != null)
     {
         new DateReportFrequency(report, events, line);
         return(true);
     }
     return(false);
 }
예제 #27
0
 public Week(YearWeek yearWeek, string alias)
 {
     this.PartitionKey = yearWeek.ToString();
     this.RowKey       = alias;
     this.Year         = yearWeek.Year;
     this.WeekNumber   = yearWeek.Week;
     this.WeekEndDate  = DateUtilities.DateOfWeek(yearWeek);
     this.Alias        = alias;
 }
예제 #28
0
 public async Task <List <CalendarEvent> > GetTaskCalendarEventsAsync(DateTimeOffset startDate, DateTimeOffset endDate, int limit = 20, int offset = 0) =>
 await GetAsync <List <CalendarEvent> >("calendar/v1/events/task", new List <QueryStringParameter>
 {
     new QueryStringParameter("offset", offset),
     new QueryStringParameter("limit", limit),
     new QueryStringParameter("startDate", DateUtilities.ConvertDatetimeToUnixTimeStamp(startDate)),
     new QueryStringParameter("endDate", DateUtilities.ConvertDatetimeToUnixTimeStamp(endDate)),
     new QueryStringParameter("includeNoCampaigns", true)
 });
예제 #29
0
        public void NumberOfWeekTest()
        {
            int week = DateUtilities.NumberOfWeek(new DateTime(2015, 12, 26));

            Assert.AreEqual(51, week);

            week = DateUtilities.NumberOfWeek(new DateTime(2015, 1, 3));
            Assert.AreEqual(52, week);
        }
예제 #30
0
        public void EndOfWeekTest()
        {
            var date = DateUtilities.EndOfWeek(new DateTime(2015, 1, 1));

            Assert.AreEqual(new DateTime(2015, 1, 3), date);

            date = DateUtilities.EndOfWeek(new DateTime(2015, 12, 25));
            Assert.AreEqual(new DateTime(2015, 12, 26), date);
        }