Example #1
0
        /// <summary>
        /// Create by using a ISO 8601 complete string in Basic or Extended format
        /// </summary>
        /// <param name="ISO8601_string"></param>
        public CompleteDateTime(string ISO8601_string)
        {
            var parts = ISO8601_string.Split("T".ToCharArray());

            this.date = new CompleteDate(parts[0]);
            this.time = new CompleteTime(parts[1]);
            this.validate();
        }
Example #2
0
        public void create_and_parse_date_object()
        {
            date = new CompleteDate(2017, 10, 18);
            Assert.AreEqual("2017-10-18", date.ExtendedFormat);
            Assert.AreEqual("20171018", date.BasicFormat);

            date = new CompleteDate("2017-01-01");
            Assert.AreEqual("2017-01-01", date.ExtendedFormat);
            Assert.AreEqual("20170101", date.BasicFormat);
        }
Example #3
0
        public void create_and_parse_dateTime_object()
        {
            date     = new CompleteDate("1975-10-18");
            time     = new CompleteTime("12:30:00+03:00");
            dateTime = new CompleteDateTime(date, time);
            Assert.AreEqual("19751018T123000+0300", dateTime.BasicFormat);
            Assert.AreEqual("1975-10-18T12:30:00+03:00", dateTime.ExtendedFormat);

            dateTime = new CompleteDateTime("1975-10-18T12:30:00-03:00");
            Assert.AreEqual("19751018T123000-0300", dateTime.BasicFormat);
            Assert.AreEqual("1975-10-18T12:30:00-03:00", dateTime.ExtendedFormat);
        }
Example #4
0
        /// <summary>
        /// The truncated date is made into a complete date by adding the unspecified members from the given complete date.
        /// If the given date is within the period described by the Truncated date, the outcome of the operation will be the same date.
        /// </summary>
        /// <param name="date"></param>
        /// <returns>The same date as the input, if this falls within the period described by the Truncated date.</returns>
        public CompleteDate MakeCompleteUsing(CompleteDate date)
        {
            var y = (int)(Year ?? date.Year);
            var m = (int)(Month ?? date.Month);

            var last_day_in_month = DateTime.DaysInMonth(y, m);            //make sure day is never more than days in the current month
            var dateDay           = date.Day > last_day_in_month ? last_day_in_month : date.Day;

            var d = (int)(Day ?? dateDay);

            return(new CompleteDate(y, m, d));
        }
Example #5
0
        /// <summary>
        /// Returns true if the given date is Within the DateSpan.
        /// </summary>
        /// <param name="trd"></param>
        /// <returns></returns>
        public bool IsWithin(CompleteDate date)
        {
            var ds = dateStart.MakeCompleteUsing(date);
            var de = dateEnd.MakeCompleteUsing(date);

            //HACK String comparison of basic format
            if (String.Compare(ds.BasicFormat, date.BasicFormat) <= 0 && String.Compare(de.BasicFormat, date.BasicFormat) >= 0)
            {
                return(true);
            }
            return(false);
        }
Example #6
0
 public void test_exception_invalid_minute_in_dateTime()
 {
     time     = new CompleteTime("22:60:00Z");
     date     = new CompleteDate(2017, 10, 18);
     dateTime = new CompleteDateTime(date, time);
 }
Example #7
0
 public void test_exception_invalid_day_in_date()
 {
     date = new CompleteDate(2017, 10, -1);
 }
Example #8
0
 /// <summary>
 /// Create by using date and time objects
 /// </summary>
 /// <param name="date"></param>
 /// <param name="time"></param>
 public CompleteDateTime(CompleteDate date, CompleteTime time)
 {
     this.date = date;
     this.time = time;
     this.validate();
 }
Example #9
0
 /// <summary>
 /// Check whether the given date is within the period desribed by the truncated date
 /// </summary>
 /// <param name="date"></param>
 /// <returns></returns>
 public bool IsWithin(CompleteDate date)
 {
     return(date.BasicFormat.Equals(this.MakeCompleteUsing(date).BasicFormat));
 }
Example #10
0
 /// <summary>
 /// Create date range by using start and end dates.
 /// </summary>
 /// <param name="dateStart"></param>
 /// <param name="dateEnd"></param>
 public CompleteDateRange(CompleteDate dateStart, CompleteDate dateEnd)
 {
     this.dateStart = dateStart;
     this.dateEnd   = dateEnd;
 }