Exemple #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GeneaDate"/> class, based on year, month and day values and an accuracy.
 /// </summary>
 /// <param name="year">The year.</param>
 /// <param name="month">The month.</param>
 /// <param name="day">The day.</param>
 /// <param name="accuracy">The accuracy.</param>
 public GeneaDate(int year, int month, int day, DateAccuracy accuracy)
 {
     this.Year     = year;
     this.Month    = month;
     this.Day      = day;
     this.Accuracy = accuracy;
 }
Exemple #2
0
        public static bool Approximates(DateTime one, DateTime two, DateAccuracy accuracy = DateAccuracy.Day)
        {
            var approximate = (one.Year == two.Year);

            if (accuracy == DateAccuracy.Year)
            {
                return(approximate);
            }
            approximate = approximate && (one.Month == two.Month);
            if (accuracy == DateAccuracy.Month)
            {
                return(approximate);
            }
            approximate = approximate && (one.Day == two.Day);
            if (accuracy == DateAccuracy.Day)
            {
                return(approximate);
            }
            approximate = approximate && (one.Hour == two.Hour);
            if (accuracy == DateAccuracy.Hour)
            {
                return(approximate);
            }
            approximate = approximate && (one.Minute == two.Minute);
            if (accuracy == DateAccuracy.Minute)
            {
                return(approximate);
            }
            approximate = approximate && (one.Second == two.Second);
            if (accuracy == DateAccuracy.Second)
            {
                return(approximate);
            }
            approximate = approximate && (one.Millisecond == two.Millisecond);

            return(approximate);
        }
        /// <summary>
        /// Converts this to <see cref="GeneaDate"/>.
        /// </summary>
        /// <value>
        /// A genea date.
        /// </value>
        public GeneaDate ToGeneaDate()
        {
            if (this.Year <= 0)
            {
                this.Year     = 0;
                this.Accuracy = DateAccuracy.Unknown;
            }

            if (this.Month <= 0 || this.Month > 12)
            {
                this.Month    = 0;
                this.Accuracy = DateAccuracy.About;
            }

            if (this.Day <= 0 || this.Day > 31)
            {
                this.Day      = 0;
                this.Accuracy = DateAccuracy.About;
            }

            var gdate = new GeneaDate(this.Year, this.Month, this.Day, this.Accuracy);

            return(gdate);
        }