Esempio n. 1
0
        private string CalculateDifferenceWithOtherResults(string valueOfFirstComponent, string valueOfOtherComponent)
        {
            TimeDifferenceFormatter formatter = new TimeDifferenceFormatter();
            DateTime dateOfFirstComponent     = formatter.GetDateInFormat(valueOfFirstComponent, this.timeDifferenceFunctionType.format_1);
            DateTime dateOfOtherComponent     = formatter.GetDateInFormat(valueOfOtherComponent, this.timeDifferenceFunctionType.format_2);
            TimeSpan difference = dateOfOtherComponent - dateOfFirstComponent;

            return(difference.TotalSeconds.ToString());
        }
        public void Should_be_possible_to_calculate_the_difference_between_dates_with_literal_Component_with_seconds_since_epoch()
        {
            VariablesTypeVariableLocal_variable localVariable =
                LocalVariableBuilder
                    .CreateTheLocalVariable()
                        .WithTimeDifference()
                            .WithFirstFormat(DateTimeFormatEnumeration.year_month_day)
                            .WithSecondFormat(DateTimeFormatEnumeration.seconds_since_epoch)
                            .AddLiteralComponent("2009-09-03 17:43:12")
                            .AddLiteralComponent("1251996192")
                            .SetInLocalVariable()
                    .Build();

            LocalVariableComponentsFactory factory = new LocalVariableComponentsFactory(systemCharacteristics, definitions.variables);
            LocalVariableComponent component = factory.GetLocalVariableComponent(localVariable);
            IEnumerable<string> values = component.GetValue();
            
            TimeDifferenceFormatter formatter = new TimeDifferenceFormatter();
            DateTime dateFromSeconds = formatter.GetDateInFormat("1251996192", DateTimeFormatEnumeration.seconds_since_epoch);
            DateTime firstDate = new DateTime(2009, 09, 03, 17, 43, 12);
            TimeSpan difference = dateFromSeconds - firstDate;


            Assert.IsTrue(values.Count() > 0, "the quantity is not expected");
            Assert.IsTrue(values.ElementAt(0) == difference.TotalSeconds.ToString()); // in seconds

        }
 public void Should_be_possible_to_get_a_date_given_seconds_since_epoch()
 {
     string secondsSinceEpoch = "10";
     TimeDifferenceFormatter formatter = new TimeDifferenceFormatter();
     DateTime formattedDate = formatter.GetDateInFormat(secondsSinceEpoch, DateTimeFormatEnumeration.seconds_since_epoch);
     // the unix epoch is 01/01/1970 00:00:00
     DateTime expectedDate = new DateTime(1970, 01, 01, 00, 00,10);
     Assert.AreEqual(expectedDate, formattedDate, "the date format is no expected.");
 }
        public void Should_be_possible_to_get_a_date_in_year_month_day_format()
        {
            string aDate = "2009/09/28 00:00:00";

            TimeDifferenceFormatter formatter = new TimeDifferenceFormatter();
            DateTime formattedDate = formatter.GetDateInFormat(aDate,DateTimeFormatEnumeration.year_month_day);
            DateTime expectedDate = new DateTime(2009, 09, 28);
            Assert.AreEqual(expectedDate,formattedDate, "the date format is no expected.");

            aDate = "2009-09-03 17:43:12";
            formattedDate = formatter.GetDateInFormat(aDate, DateTimeFormatEnumeration.year_month_day);
            expectedDate = new DateTime(2009, 09, 03, 17,43,12);
            Assert.AreEqual(expectedDate, formattedDate, "the date format is no expected.");

            aDate = "2009-09-28";
            formattedDate = formatter.GetDateInFormat(aDate, DateTimeFormatEnumeration.year_month_day);
            expectedDate = new DateTime(2009, 09, 28);
            Assert.AreEqual(expectedDate, formattedDate, "the date format is no expected.");

            aDate = "2009/09/28";
            formattedDate = formatter.GetDateInFormat(aDate, DateTimeFormatEnumeration.year_month_day);
            expectedDate = new DateTime(2009, 09, 28);
            Assert.AreEqual(expectedDate, formattedDate, "the date format is no expected.");
        }
        public void Should_be_possible_to_get_a_date_in_month_day_year()
        {
            string aDate = "09/29/2009 12:05:15";
            TimeDifferenceFormatter formatter = new TimeDifferenceFormatter();
            DateTime formattedDate = formatter.GetDateInFormat(aDate, DateTimeFormatEnumeration.month_day_year);
            DateTime expectedDate = new DateTime(2009, 09, 29,12,05,15);
            Assert.AreEqual(expectedDate, formattedDate, "the date format is no expected.");

            aDate = "09/29/2009";
            formattedDate = formatter.GetDateInFormat(aDate, DateTimeFormatEnumeration.month_day_year);
            expectedDate = new DateTime(2009, 09, 29);
            Assert.AreEqual(expectedDate, formattedDate, "the date format is no expected.");

            aDate = "09-29-2009";
            formattedDate = formatter.GetDateInFormat(aDate, DateTimeFormatEnumeration.month_day_year);
            expectedDate = new DateTime(2009, 09, 29);
            Assert.AreEqual(expectedDate, formattedDate, "the date format is no expected.");

            aDate = "09-29-2009 15:10:10";
            formattedDate = formatter.GetDateInFormat(aDate, DateTimeFormatEnumeration.month_day_year);
            expectedDate = new DateTime(2009, 09, 29,15,10,10);
            Assert.AreEqual(expectedDate, formattedDate, "the date format is no expected.");
        }
 public void Should_be_possible_to_get_a_date_given_win_filetime()
 {
     string fileTime = "99900000000";
     //string fileTime = "111900000000";
     TimeDifferenceFormatter formatter = new TimeDifferenceFormatter();
     DateTime formattedDate = formatter.GetDateInFormat(fileTime, DateTimeFormatEnumeration.win_filetime);
     // the win_FileTime is 01/01/1601 00:00:00
     DateTime expectedDate = new DateTime(1601, 01, 01, 00, 46, 30);
     //DateTime expectedDate = new DateTime(1601, 01, 01, 00, 06, 30);
     Assert.AreEqual(expectedDate, formattedDate, "the date format is no expected.");
 }
        private string CalculateDifferenceWithOtherResults(string valueOfFirstComponent, string valueOfOtherComponent)
        {
            TimeDifferenceFormatter formatter = new TimeDifferenceFormatter();
            DateTime dateOfFirstComponent = formatter.GetDateInFormat(valueOfFirstComponent, this.timeDifferenceFunctionType.format_1);
            DateTime dateOfOtherComponent = formatter.GetDateInFormat(valueOfOtherComponent, this.timeDifferenceFunctionType.format_2);
            TimeSpan difference =  dateOfOtherComponent - dateOfFirstComponent;

            return difference.TotalSeconds.ToString();
        }