Ejemplo n.º 1
0
        public void testSetGregorian_5argsBC()
        {
            int        day          = 20;
            string     month        = "Dec";
            int        year         = 1980;
            string     yearModifier = "";
            bool       yearBC       = true;
            GEDCOMDate instance     = new GEDCOMDate(null, null, "", "");

            instance.SetGregorian(day, month, year, yearModifier, yearBC);
            string result = instance.GetDisplayString(DateFormat.dfYYYY_MM_DD, true, false);

            Assert.AreEqual("BC 1980.12.20", result);
        }
Ejemplo n.º 2
0
        public void testSetDateHebrew()
        {
            GEDCOMCalendar calendar = GEDCOMCalendar.dcHebrew;
            int            day      = 20;
            int            month    = 12;
            int            year     = 1980;
            GEDCOMDate     instance = new GEDCOMDate(null, null, "", "");

            instance.SetDate(calendar, day, month, year);
            string result = instance.GetDisplayString(DateFormat.dfYYYY_MM_DD, false, false);

            Assert.AreEqual("1980.12.20", result);
            Assert.AreEqual("@#DHEBREW@ 20 AAV 1980", instance.StringValue);
        }
Ejemplo n.º 3
0
        public void testGetDisplayString_DateFormat()
        {
            GEDCOMDate instance  = GEDCOMDate.CreateByFormattedStr("20/12/1980", true);
            string     expResult = "1980.12.20";
            string     result    = instance.GetDisplayString(DateFormat.dfYYYY_MM_DD);

            Assert.AreEqual(expResult, result);

            result = instance.GetDisplayString(DateFormat.dfDD_MM_YYYY);
            Assert.AreEqual("20.12.1980", result);

            result = instance.GetDisplayString(DateFormat.dfYYYY);
            Assert.AreEqual("1980", result);
        }
Ejemplo n.º 4
0
        public void testSetFrench_4args()
        {
            int        day      = 1;
            string     month    = "VEND";
            int        year     = 1980;
            bool       yearBC   = false;
            GEDCOMDate instance = new GEDCOMDate(null, null, "", "");

            instance.SetFrench(day, month, year, yearBC);
            Assert.AreEqual(GEDCOMCalendar.dcFrench, instance.DateCalendar);
            Assert.AreEqual("@#DFRENCH R@ 01 VEND 1980", instance.StringValue);

            // Code coverage
            instance.SetHebrew(day, "", year, yearBC);
            Assert.AreEqual(GEDCOMCalendar.dcHebrew, instance.DateCalendar);
        }
Ejemplo n.º 5
0
        public void testSetHebrew_4args()
        {
            int        day      = 1;
            string     month    = "TSH";
            int        year     = 1980;
            bool       yearBC   = false;
            GEDCOMDate instance = new GEDCOMDate(null, null, "", "");

            instance.SetHebrew(day, month, year, yearBC);
            Assert.AreEqual(GEDCOMCalendar.dcHebrew, instance.DateCalendar);
            Assert.AreEqual("@#DHEBREW@ 01 TSH 1980", instance.StringValue);

            // Code coverage
            instance.SetHebrew(day, "", year, yearBC);
            Assert.AreEqual(GEDCOMCalendar.dcHebrew, instance.DateCalendar);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// This function transforms the string into a date. All components of
        /// the date's string must be given by numbers in order of day / month / year.
        /// </summary>
        /// <param name="strDate"></param>
        /// <param name="calendar"></param>
        /// <param name="aException"></param>
        /// <returns></returns>
        public static GEDCOMDate CreateByFormattedStr(string dateStr, GEDCOMCalendar calendar, bool aException)
        {
            if (string.IsNullOrEmpty(dateStr))
            {
                return(null);
            }

            if (dateStr.IndexOf("-") >= 0)
            {
                dateStr = dateStr.Replace("-", ".");
            }
            if (dateStr.IndexOf("/") >= 0)
            {
                dateStr = dateStr.Replace("/", ".");
            }
            if (dateStr.IndexOf("_") >= 0)
            {
                dateStr = dateStr.Replace("_", " ");
            }

            string[] dtParts = dateStr.Split('.');
            if (dtParts.Length < 3)
            {
                if (aException)
                {
                    throw new GEDCOMDateException(string.Format("GEDCOMDate.CreateByFormattedStr(): date format is invalid {0}", dateStr));
                }

                return(null);
            }

            string pd = dtParts[0].Trim();
            string pm = dtParts[1].Trim();
            string py = dtParts[2].Trim();

            int day   = (pd == "") ? 0 : SysUtils.ParseInt(pd, 0);
            int month = (pm == "") ? 0 : SysUtils.ParseInt(pm, 0);
            int year  = (py == "") ? UNKNOWN_YEAR : SysUtils.ParseInt(py, UNKNOWN_YEAR);

            var date = new GEDCOMDate(null, null, "", "");

            date.SetDate(calendar, day, month, year);
            return(date);
        }
Ejemplo n.º 7
0
        public void testGetDisplayStringExt()
        {
            DateFormat format       = DateFormat.dfYYYY_MM_DD;
            bool       showCalendar = true;
            GEDCOMDate instance     = new GEDCOMDate(null, null, "", "");

            instance.SetJulian(20, 12, 1980);
            instance.YearBC = true;
            string expResult = "BC 1980.12.20 [J]";
            bool   sign      = true;
            string result    = instance.GetDisplayStringExt(format, sign, showCalendar);

            Assert.AreEqual(expResult, result);

            instance.Approximated = GEDCOMApproximated.daEstimated;
            expResult             = "~ BC 1980.12.20 [J]";
            result = instance.GetDisplayStringExt(format, sign, showCalendar);
            Assert.AreEqual(expResult, result);
        }
Ejemplo n.º 8
0
        public override void Assign(GEDCOMTag source)
        {
            GEDCOMDate srcDate = source as GEDCOMDate;

            if (srcDate != null)
            {
                fCalendar     = srcDate.fCalendar;
                fYear         = srcDate.fYear;
                fYearBC       = srcDate.fYearBC;
                fYearModifier = srcDate.fYearModifier;
                fMonth        = srcDate.fMonth;
                fDay          = srcDate.fDay;

                DateChanged();
            }
            else
            {
                base.Assign(source);
            }
        }
Ejemplo n.º 9
0
        public void testGetDisplayString_3args()
        {
            DateFormat format       = DateFormat.dfYYYY_MM_DD;
            bool       includeBC    = true;
            bool       showCalendar = true;
            GEDCOMDate instance     = new GEDCOMDate(null, null, "", "");

            instance.SetJulian(20, 12, 1980);
            instance.YearBC = true;
            string expResult = "BC 1980.12.20 [J]";
            string result    = instance.GetDisplayString(format, includeBC, showCalendar);

            Assert.AreEqual(expResult, result);

            result = instance.GetDisplayString(DateFormat.dfDD_MM_YYYY, true, false);
            Assert.AreEqual("20.12.1980 BC", result);

            result = instance.GetDisplayString(DateFormat.dfYYYY, true, false);
            Assert.AreEqual("BC 1980", result);
        }
Ejemplo n.º 10
0
 protected override void CreateObj(GEDCOMTree owner, GEDCOMObject parent)
 {
     base.CreateObj(owner, parent);
     fDateFrom = new GEDCOMDate(owner, this, "", "");
     fDateTo   = new GEDCOMDate(owner, this, "", "");
 }
Ejemplo n.º 11
0
        public static GEDCOMDateRange CreateRange(GEDCOMTree owner, GEDCOMObject parent, GEDCOMDate dateAfter, GEDCOMDate dateBefore)
        {
            GEDCOMDateRange result = new GEDCOMDateRange(owner, parent, "", "");

            result.After.Assign(dateAfter);
            result.Before.Assign(dateBefore);
            return(result);
        }
Ejemplo n.º 12
0
        public static GEDCOMDatePeriod CreatePeriod(GEDCOMTree owner, GEDCOMObject parent, GEDCOMDate dateFrom, GEDCOMDate dateTo)
        {
            GEDCOMDatePeriod result = new GEDCOMDatePeriod(owner, parent, "", "");

            result.DateFrom.Assign(dateFrom);
            result.DateTo.Assign(dateTo);
            return(result);
        }
Ejemplo n.º 13
0
        public static GEDCOMDate CreateApproximated(GEDCOMTree owner, GEDCOMObject parent, GEDCOMDate date, GEDCOMApproximated approximated)
        {
            GEDCOMDate result = new GEDCOMDate(owner, parent, "", "");

            result.Assign(date);
            result.Approximated = approximated;
            return(result);
        }
Ejemplo n.º 14
0
        public static UDN GetUDNByFormattedStr(string dateStr, GEDCOMCalendar calendar, bool aException = false)
        {
            GEDCOMDate dtx = GEDCOMDate.CreateByFormattedStr(dateStr, calendar, aException);

            return((dtx != null) ? dtx.GetUDN() : UDN.CreateEmpty());
        }
Ejemplo n.º 15
0
 public void testCreateByFormattedStr_exception()
 {
     Assert.Throws(typeof(GEDCOMDateException), () => {
         GEDCOMDate.CreateByFormattedStr("1.2", true);
     });
 }
Ejemplo n.º 16
0
 protected override void CreateObj(GEDCOMTree owner, GEDCOMObject parent)
 {
     base.CreateObj(owner, parent);
     fDateAfter  = new GEDCOMDate(owner, parent, "", "");
     fDateBefore = new GEDCOMDate(owner, parent, "", "");
 }