Beispiel #1
0
        /// <summary>
        /// Calculates the start and end dates based on the currently
        /// selected ComboBox item
        /// </summary>
        private void CalculateDates()
        {
            if (!_dateRangePairs.ContainsValue(this._comboBox.Text))
            {
                _range = new DateRange(DateTime.MinValue, DateTime.MaxValue);
                return;
            }

            DateRangeOptions option = DateRangeOptions.Today;
            bool             found  = false;

            foreach (KeyValuePair <DateRangeOptions, string> pair in _dateRangePairs)
            {
                if (pair.Value == (string)_comboBox.SelectedItem)
                {
                    option = pair.Key;
                    found  = true;
                    break;
                }
            }

            if (!found)
            {
                _range = new DateRange(DateTime.MinValue, DateTime.MaxValue);
                return;
            }
            _dateRangeConverter.SetNow(Now);
            _range = _dateRangeConverter.ConvertDateRange(option);
        }
Beispiel #2
0
 public DateRangeTestCase(DateRangeOptions dateRange, string currentDateStr, string expectedStartDateStr, string expectedEndDateStr)
 {
     DateRangeOptions  = dateRange;
     CurrectDate       = DateTimeUtilities.ParseToDate(currentDateStr);
     ExpectedStartDate = DateTimeUtilities.ParseToDate(expectedStartDateStr);
     ExpectedEndDate   = DateTimeUtilities.ParseToDate(expectedEndDateStr);
 }
Beispiel #3
0
 public DateRangeTestCase(DateRangeOptions dateRange, DateTime currentDate, DateTime expectedStartDate, DateTime expectedEndDate)
 {
     DateRangeOptions  = dateRange;
     CurrectDate       = currentDate;
     ExpectedStartDate = expectedStartDate;
     ExpectedEndDate   = expectedEndDate;
 }
Beispiel #4
0
 public DateRangeTestCaseWithOffSet(DateRangeOptions dateRange, DateTime currentDate, DateTime expectedStartDate, DateTime expectedEndDate, TimeSpan midNightOffset, int weekOffSet, int monthOffSet, int yearOffSet)
     : base(dateRange, currentDate, expectedStartDate, expectedEndDate)
 {
     MidNightOffset = midNightOffset;
     WeekOffSet     = weekOffSet;
     MonthOffSet    = monthOffSet;
     YearOffSet     = yearOffSet;
 }
Beispiel #5
0
 /// <summary>
 /// Adds a date range option to the current list of options available
 /// </summary>
 /// <param name="option">The date range option to add</param>
 public void AddDateOption(DateRangeOptions option)
 {
     if (!_optionsToDisplay.Contains(option))
     {
         _optionsToDisplay.Add(option);
         _comboBox.Items.Add(_dateRangePairs[option]);
     }
 }
Beispiel #6
0
 /// <summary>
 /// Removes a date range option from the current list of options available
 /// </summary>
 /// <param name="option">The date range option to remove</param>
 public void RemoveDateOption(DateRangeOptions option)
 {
     if (_optionsToDisplay.Contains(option))
     {
         _optionsToDisplay.Remove(option);
         _comboBox.Items.Remove(_dateRangePairs[option]);
     }
 }
Beispiel #7
0
 public DateRangeTestCaseWithOffSet(DateRangeOptions dateRange, string currentDateStr, string expectedStartDateStr, string expectedEndDateStr, TimeSpan midNightOffset, int weekOffSet, int monthOffSet, int yearOffSet)
     : base(dateRange, currentDateStr, expectedStartDateStr, expectedEndDateStr)
 {
     WeekOffSet     = weekOffSet;
     MonthOffSet    = monthOffSet;
     YearOffSet     = yearOffSet;
     MidNightOffset = midNightOffset;
 }
Beispiel #8
0
 /// <summary>
 /// Returns the display string for the date range option supplied
 /// </summary>
 /// <param name="option">The date range enumeration</param>
 /// <returns>Returns the string if found, otherwise throws an
 /// ArgumentException</returns>
 public string GetDateRangeString(DateRangeOptions option)
 {
     if (_dateRangePairs.ContainsKey(option))
     {
         return(_dateRangePairs[option]);
     }
     throw new ArgumentException("A date range option string is being " +
                                 "accessed, but the given date range option does not exist.");
 }
        private List <Payment> ExportPayment(DateTime start)
        {
            var range = new DateRangeOptions
            {
                GreaterThanOrEqual = start,
            };

            return(_ExportPayment(range));
        }
Beispiel #10
0
 /// <summary>
 /// Amends the display string for a given date option
 /// </summary>
 /// <param name="option">The date option to amend</param>
 /// <param name="newDisplayString">The display string to apply</param>
 public void SetDateRangeString(DateRangeOptions option, string newDisplayString)
 {
     if (_optionsToDisplay.Contains(option))
     {
         if (_dateRangePairs.ContainsValue(newDisplayString) &&
             _dateRangePairs[option] != newDisplayString)
         {
             throw new ArgumentException("A date range display string " +
                                         "is being assigned, but that display string has already " +
                                         "been used.");
         }
         int comboBoxPos = _comboBox.Items.IndexOf(_dateRangePairs[option]);
         _comboBox.Items[comboBoxPos] = newDisplayString;
         _dateRangePairs[option]      = newDisplayString;
     }
     else
     {
         throw new ArgumentException("A date range string is being changed, " +
                                     "but the given option does not exist in the collection " +
                                     "of date options.");
     }
 }
Beispiel #11
0
        ///<summary>
        /// Using the Current Date Time <see cref="DateTimeNow"/> and the <see cref="DateRangeOptions"/>
        /// returns an appropriate <see cref="DateRange"/>.
        ///</summary>
        ///<param name="dateRangeOptions">A date range option e.g. Yesterday</param>
        ///<returns></returns>
        public DateRange ConvertDateRange(DateRangeOptions dateRangeOptions)
        {
            var currentDateTime = _dateTimeNow.ResolveToValue();

            switch (dateRangeOptions)
            {
                case DateRangeOptions.ThisHour:
                    {
                        return new DateRange(HourStart(currentDateTime), HourEnd(currentDateTime));
                    }
                case DateRangeOptions.Current24Hours:
                    {
                        return new DateRange(currentDateTime.AddDays(-1), currentDateTime);
                    }
                case DateRangeOptions.PreviousHour:
                    {
                        var previousHour = currentDateTime.AddHours(-1);
                        return new DateRange(HourStart(previousHour), HourEnd(previousHour));
                    }
                case DateRangeOptions.Current60Minutes:
                    {
                        return new DateRange(currentDateTime.AddHours(-1), currentDateTime);
                    }
                case DateRangeOptions.Today:
                    {
                        return new DateRange(DayStart(currentDateTime), DayEnd(currentDateTime));
                    }
                case DateRangeOptions.Yesterday:
                    {
                        return new DateRange(DayStart(currentDateTime).AddDays(-1), DayEnd(currentDateTime).AddDays(-1));
                    }
                case DateRangeOptions.ThisWeek:
                    {
                        return new DateRange(WeekStart(currentDateTime), WeekEnd(currentDateTime));
                    }
                case DateRangeOptions.PreviousWeek:
                    {
                        var lastWeekDate = currentDateTime.AddDays(-7);
                        return new DateRange(WeekStart(lastWeekDate), WeekEnd(lastWeekDate));
                    }
                case DateRangeOptions.Previous7Days:
                    {
                        return new DateRange(DayStart(currentDateTime.AddDays(-7)), currentDateTime);
                    }
                case DateRangeOptions.MonthToDate:
                    {
                        return new DateRange(MonthStart(currentDateTime), currentDateTime);
                    }
                case DateRangeOptions.WeekToDate:
                    {
                        return new DateRange(WeekStart(currentDateTime), currentDateTime);
                    }

                case DateRangeOptions.ThisMonth:
                    {
                        return new DateRange(MonthStart(currentDateTime), MonthEnd(currentDateTime));
                    }
                case DateRangeOptions.PreviousMonth:
                    {
                        var previousMonthDate = currentDateTime.AddMonths(-1);
                        return new DateRange(MonthStart(previousMonthDate), MonthEnd(previousMonthDate));
                    }
                case DateRangeOptions.Previous30Days:
                    {
                        var startTime = currentDateTime.AddDays(-30);
                        var endTime = currentDateTime;
                        return new DateRange(DayStart(startTime), endTime);
                    }
                case DateRangeOptions.Previous31Days:
                    {
                        var startTime = currentDateTime.AddDays(-31);
                        var endTime = currentDateTime;
                        return new DateRange(DayStart(startTime), endTime);
                    }
                case DateRangeOptions.YearToDate:
                    {
                        return new DateRange(YearStart(currentDateTime), currentDateTime);
                    }
                case DateRangeOptions.Previous365Days:
                    {
                        return new DateRange(DayStart(currentDateTime.AddDays(-365)), currentDateTime);
                    }

                case DateRangeOptions.Current2Years:
                    {
                        return new DateRange(currentDateTime.AddYears(-2), currentDateTime);
                    }
                case DateRangeOptions.Current3Years:
                    {
                        return new DateRange(currentDateTime.AddYears(-3), currentDateTime);
                    }
                case DateRangeOptions.Current5Years:
                    {
                        return new DateRange(currentDateTime.AddYears(-5), currentDateTime);
                    }

                case DateRangeOptions.ThisYear:
                    {
                        return new DateRange(YearStart(currentDateTime), YearEnd(currentDateTime));
                    }
                case DateRangeOptions.PreviousYear:
                    {
                        DateTime previousYear = currentDateTime.AddYears(-1);
                        return new DateRange(YearStart(previousYear), YearEnd(previousYear));
                    }

                case DateRangeOptions.Previous2Years:
                    {
                        DateTime twoYearsAgo = currentDateTime.AddYears(-2);
                        return new DateRange(YearStart(twoYearsAgo), YearEnd(twoYearsAgo.AddYears(1)));
                    }

                case DateRangeOptions.Previous3Years:
                    {
                        DateTime threeYearsAgo = currentDateTime.AddYears(-3);
                        return new DateRange(YearStart(threeYearsAgo), YearEnd(threeYearsAgo).AddYears(2));
                    }
                case DateRangeOptions.Previous5Years:
                    {
                        DateTime fiveYearsAgo = currentDateTime.AddYears(-5);
                        return new DateRange(YearStart(fiveYearsAgo), YearEnd(fiveYearsAgo).AddYears(4));
                    }
                case DateRangeOptions.Tommorrow:
                    {
                        return new DateRange(DayStart(currentDateTime.AddDays(1)), DayEnd(currentDateTime.AddDays(1)));
                    }
                case DateRangeOptions.Next24Hours:
                    {
                        return new DateRange(currentDateTime, currentDateTime.AddHours(24).AddMilliseconds(-1));
                    }
                case DateRangeOptions.Next7Days:
                    {
                        return new DateRange(currentDateTime, DayEnd(currentDateTime.AddDays(7)));
                    }
                case DateRangeOptions.Next30Days:
                    {
                        return new DateRange(currentDateTime, DayEnd(currentDateTime.AddDays(30)));
                    }
                default:
                    {
                        return new DateRange(DateTime.MinValue, DateTime.MaxValue);
                    }
            } 
        }
 /// <summary>
 /// Removes a date range option from the current list of options available
 /// </summary>
 /// <param name="option">The date range option to remove</param>
 public void RemoveDateOption(DateRangeOptions option)
 {
     if (_optionsToDisplay.Contains(option))
     {
         _optionsToDisplay.Remove(option);
         _comboBox.Items.Remove(_dateRangePairs[option]);
     }
 }
 /// <summary>
 /// Adds a date range option to the current list of options available
 /// </summary>
 /// <param name="option">The date range option to add</param>
 public void AddDateOption(DateRangeOptions option)
 {
     if (!_optionsToDisplay.Contains(option))
     {
         _optionsToDisplay.Add(option);
         _comboBox.Items.Add(_dateRangePairs[option]);
     }
 }
 /// <summary>
 /// Returns the display string for the date range option supplied
 /// </summary>
 /// <param name="option">The date range enumeration</param>
 /// <returns>Returns the string if found, otherwise throws an
 /// ArgumentException</returns>
 public string GetDateRangeString(DateRangeOptions option)
 {
     if (_dateRangePairs.ContainsKey(option))
     {
         return _dateRangePairs[option];
     }
     throw new ArgumentException("A date range option string is being " +
                                 "accessed, but the given date range option does not exist.");
 }
 public DateRangeTestCase(DateRangeOptions dateRange, DateTime currentDate, DateTime expectedStartDate, DateTime expectedEndDate)
 {
     DateRangeOptions = dateRange;
     CurrectDate = currentDate;
     ExpectedStartDate = expectedStartDate;
     ExpectedEndDate = expectedEndDate;
 }
 /// <summary>
 /// Removes a date range option from the current list of options available
 /// </summary>
 /// <param name="option">The date range option to remove</param>
 public void RemoveDateOption(DateRangeOptions option)
 {
     _manager.RemoveDateOption(option);
 }
        private List <Payment> _ExportPayment(DateRangeOptions range)
        {
            var payments = new List <Payment>();

            try
            {
                var options = new PaymentIntentListOptions
                {
                    Limit   = 100,
                    Created = range,
                };
                var paymentIntentService = new PaymentIntentService();
                var transactionService   = new BalanceTransactionService();
                var customerService      = new CustomerService();
                var chargeService        = new ChargeService();

                StripeList <PaymentIntent> pis = paymentIntentService.List(options);

                for (int i = 0; i < pis.Data.Count; i++)
                {
                    var pi = pis.Data[i];

                    var payment = new Payment()
                    {
                        Description         = pi.Description,
                        Created             = pi.Created,
                        Amount              = Convert.ToDecimal(pi.Amount) / 100,
                        Currency            = pi.Currency,
                        Status              = pi.Status,
                        StatementDescriptor = pi.StatementDescriptor,
                        CustomerId          = pi.CustomerId,
                        CardId              = pi.PaymentMethodId,
                        InvoiceId           = pi.InvoiceId
                    };

                    if (pi.Charges.Data.Count > 0)
                    {
                        var charge = pi.Charges.Data[0];
                        try
                        {
                            charge.BalanceTransaction = transactionService.Get(charge.BalanceTransactionId);
                            payment.Id = charge.Id;
                            payment.ConvertedAmount   = Convert.ToDecimal(charge.BalanceTransaction.Amount) / 100;
                            payment.AmountRefunded    = Convert.ToDecimal(charge.AmountRefunded) / 100;
                            payment.Fee               = Convert.ToDecimal(charge.BalanceTransaction.Fee) / 100;
                            payment.ConvertedCurrency = charge.BalanceTransaction.Currency;
                            payment.Tax               = 0;
                            payment.Captured          = charge.Captured;
                            payment.Transfer          = charge.TransferId;
                            try
                            {
                                if (charge.Refunds.Data.Count > 0)
                                {
                                    var refundTx = transactionService.Get(charge.Refunds.Data[0].BalanceTransactionId);
                                    payment.ConvertedAmountRefunded = Convert.ToDecimal(refundTx.Amount) / 100;
                                }
                            }
                            catch (Exception) { }
                        }
                        catch (Exception) { }
                    }

                    try
                    {
                        pi.Customer = customerService.Get(pi.CustomerId);
                        payment.CustomerDescription = pi.Customer.Description;
                        payment.CustomerEmail       = pi.Customer.Email;
                    }
                    catch (Exception) { }


                    payment.Description = pi.Description;
                    payments.Add(payment);
                }

                var optionsC = new ChargeListOptions
                {
                    Limit   = 100,
                    Created = range,
                };
                StripeList <Charge> chs = chargeService.List(optionsC);
                for (int i = 0; i < chs.Data.Count; i++)
                {
                    var ch = chs.Data[i];
                    if (FindPayment(payments, ch.Id))
                    {
                        continue;
                    }

                    var payment = new Payment()
                    {
                        Id                  = ch.Id,
                        Description         = ch.Description,
                        Created             = ch.Created,
                        Amount              = Convert.ToDecimal(ch.Amount) / 100,
                        Currency            = ch.Currency,
                        Status              = ch.Status,
                        StatementDescriptor = ch.StatementDescriptor,
                        CustomerId          = ch.CustomerId,
                        Captured            = ch.Captured,
                        CardId              = ch.PaymentMethod,
                        InvoiceId           = ch.InvoiceId,
                        Transfer            = ch.TransferId
                    };
                    try
                    {
                        ch.BalanceTransaction     = transactionService.Get(ch.BalanceTransactionId);
                        payment.ConvertedAmount   = Convert.ToDecimal(ch.BalanceTransaction.Amount) / 100;
                        payment.AmountRefunded    = Convert.ToDecimal(ch.AmountRefunded) / 100;
                        payment.Fee               = Convert.ToDecimal(ch.BalanceTransaction.Fee) / 100;
                        payment.ConvertedCurrency = ch.BalanceTransaction.Currency;
                        payment.Tax               = 0;
                    }
                    catch (Exception) { }
                    try
                    {
                        ch.Customer = customerService.Get(ch.CustomerId);
                        payment.CustomerDescription = ch.Customer.Description;
                        payment.CustomerEmail       = ch.Customer.Email;
                    }
                    catch (Exception) { }

                    payments.Add(payment);
                }
            }
            catch (Exception) { }

            payments.Sort(
                delegate(Payment a, Payment b)
            {
                return(b.Created.CompareTo(a.Created));
            }
                );
            return(payments);
        }
 public DateRangeTestCaseWithOffSet(DateRangeOptions dateRange, string currentDateStr, string expectedStartDateStr, string expectedEndDateStr, TimeSpan midNightOffset, int weekOffSet, int monthOffSet, int yearOffSet)
     : base(dateRange, currentDateStr, expectedStartDateStr, expectedEndDateStr)
 {
     WeekOffSet = weekOffSet;
     MonthOffSet = monthOffSet;
     YearOffSet = yearOffSet;
     MidNightOffset = midNightOffset;
 }
Beispiel #19
0
        /// <summary><![CDATA[
        /// Returns a struct with a start and end date for a given start date and interval.
        /// ]]></summary>
        /// <example>
        /// If you pass the current date, and wish to know the first
        /// and last days of the week based on the current day:
        /// <code><![CDATA[
        /// DateRangeStruct result = DateTime.Now.DateRange(TemporalHelpers.DateRangeOptions.Week);
        /// Response.Write ("The first day of the week is " + result.startDate.ToString() +
        /// ", and the last day of the week is " + result.endDate.ToString());
        /// ]]></code>
        /// </example>
        /// <param name="relativeDate">Date to use as the basis for calculating the start and end date of the range.</param>
        /// <param name="dateRangeOptions">Enumeration value specifying which abstracted date range to evaluate. Note, weeks begin on Sunday and end on Saturday.</param>
        /// <returns>DateTimeStruct with the start and end date of the range.</returns>
        public static DateRangeStruct DateRange(this DateTime relativeDate, DateRangeOptions dateRangeOptions)
        {
            DateTime[] dates  = { DateTime.Today, DateTime.Today };
            DateTime   myDate = relativeDate;

            switch (dateRangeOptions)
            {
            case DateRangeOptions.Week:

                if (myDate.DayOfWeek > 0)
                {
                    myDate = myDate.AddDays(-1 * Convert.ToInt32(myDate.DayOfWeek));
                }

                dates[0] = myDate;
                dates[1] = myDate.AddDays(6);

                break;

            case DateRangeOptions.Month:

                if (myDate.Day > 1)
                {
                    myDate = myDate.AddDays(-1 * (myDate.Day - 1));
                }

                dates[0] = myDate;
                dates[1] = myDate.AddMonths(1);
                dates[1] = dates[1].AddDays(-1);

                break;

            case DateRangeOptions.Quarter:

                if (myDate.Month < 4)
                {
                    dates[0] = Convert.ToDateTime("1/1/" + myDate.Year.ToString());
                }
                if (myDate.Month > 3 && myDate.Month < 7)
                {
                    dates[0] = Convert.ToDateTime("4/1/" + myDate.Year.ToString());
                }
                if (myDate.Month > 6 && myDate.Month < 10)
                {
                    dates[0] = Convert.ToDateTime("7/1/" + myDate.Year.ToString());
                }
                if (myDate.Month > 9)
                {
                    dates[0] = Convert.ToDateTime("10/1/" + myDate.Year.ToString());
                }

                dates[1] = dates[0].AddMonths(3);
                dates[1] = dates[1].AddDays(-1);

                break;

            case DateRangeOptions.Year:

                dates[0] = Convert.ToDateTime("1/1/" + myDate.Year.ToString());
                dates[1] = Convert.ToDateTime("12/31/" + myDate.Year.ToString());

                break;
            }

            DateRangeStruct result = new DateRangeStruct();

            result.startDate = dates[0];
            result.endDate   = dates[1];

            return(result);
        }
 /// <summary>
 /// Amends the display string for a given date option
 /// </summary>
 /// <param name="option">The date option to amend</param>
 /// <param name="newDisplayString">The display string to apply</param>
 public void SetDateRangeString(DateRangeOptions option, string newDisplayString)
 {
     _manager.SetDateRangeString(option, newDisplayString);
 }
 /// <summary>
 /// Returns the display string for the date range option supplied
 /// </summary>
 /// <param name="option">The date range enumeration</param>
 /// <returns>Returns the string if found, otherwise throws an
 /// ArgumentException</returns>
 public string GetDateRangeString(DateRangeOptions option)
 {
     return _manager.GetDateRangeString(option);
 }
 public DateRangeTestCaseWithOffSet(DateRangeOptions dateRange, DateTime currentDate, DateTime expectedStartDate, DateTime expectedEndDate, TimeSpan midNightOffset, int weekOffSet, int monthOffSet, int yearOffSet)
     : base(dateRange, currentDate, expectedStartDate, expectedEndDate)
 {
     MidNightOffset = midNightOffset;
     WeekOffSet = weekOffSet;
     MonthOffSet = monthOffSet;
     YearOffSet = yearOffSet;
 }
Beispiel #23
0
 /// <summary><![CDATA[
 /// Returns a struct with a start and end date for a given start date and interval.
 /// ]]></summary>
 /// <example>
 /// If you pass the current date, and wish to know the first
 /// and last days of the week based on the current day:
 /// <code><![CDATA[
 /// DateRangeStruct result = DateTime.Now.DateRange(TemporalHelpers.DateRangeOptions.Week);
 /// Response.Write ("The first day of the week is " + result.startDate.ToString() +
 /// ", and the last day of the week is " + result.endDate.ToString());
 /// ]]></code>
 /// </example>
 /// <param name="relativeDate">Date to use as the basis for calculating the start and end date of the range.</param>
 /// <param name="dateRangeOptions">Enumeration value specifying which abstracted date range to evaluate. Note, weeks begin on Sunday and end on Saturday.</param>
 /// <returns>DateTimeStruct with the start and end date of the range.</returns>
 public static DateRangeStruct DateRange(this string relativeDate, DateRangeOptions dateRangeOptions)
 {
     return(DateRange(Convert.ToDateTime(relativeDate), dateRangeOptions));
 }
Beispiel #24
0
        /// <summary>
        /// Returns a string array with start and end dates for a given range.
        /// </summary>
        /// <example>
        /// If you pass the current date, and wish to know the first
        /// and last days of the week based on the current day:
        /// <code>
        /// using Mezzocode.Halide3;
        /// ...
        /// DateRangeStruct result = h3Temporal.DateRange(
        ///		h3Temporal.DateRangeOptions.Week,
        ///		DateTime.Now
        ///		);
        ///		
        /// Response.Write ("The first day of the week is " + result.startDate.ToString() + 
        /// ", and the last day of the week is " + result.endDate.ToString());
        /// </code>
        /// </example>
        /// <param name="DRO">Enumeration value specifying which abstracted date range to evaluate. Note, weeks begin on Sunday and end on Saturday.</param>
        /// <param name="relativeDate">Date to use as the basis for calculating the start and end date of the range.</param>
        /// <returns>DateTimeStruct with the start and end date of the range.</returns>
        public static DateRangeStruct DateRange(DateRangeOptions DRO, DateTime relativeDate)
        {
            DateTime[] retValue = { DateTime.Today, DateTime.Today };
            DateTime myDate = relativeDate;

            switch (DRO)
            {
                case DateRangeOptions.Week:

                    if (myDate.DayOfWeek > 0) myDate = myDate.AddDays(-1 * Convert.ToInt32(myDate.DayOfWeek));

                    retValue[0] = myDate;
                    retValue[1] = myDate.AddDays(6);

                    break;

                case DateRangeOptions.Month:

                    if (myDate.Day > 1) myDate = myDate.AddDays(-1 * (myDate.Day - 1));

                    retValue[0] = myDate;
                    retValue[1] = myDate.AddMonths(1);
                    retValue[1] = retValue[1].AddDays(-1);

                    break;

                case DateRangeOptions.Quarter:

                    if (myDate.Month < 4) retValue[0] = Convert.ToDateTime("1/1/" + myDate.Year.ToString());
                    if (myDate.Month > 3 && myDate.Month < 7) retValue[0] = Convert.ToDateTime("4/1/" + myDate.Year.ToString());
                    if (myDate.Month > 6 && myDate.Month < 10) retValue[0] = Convert.ToDateTime("7/1/" + myDate.Year.ToString());
                    if (myDate.Month > 9) retValue[0] = Convert.ToDateTime("10/1/" + myDate.Year.ToString());

                    retValue[1] = retValue[0].AddMonths(3);
                    retValue[1] = retValue[1].AddDays(-1);

                    break;

                case DateRangeOptions.Year:

                    retValue[0] = Convert.ToDateTime("1/1/" + myDate.Year.ToString());
                    retValue[1] = Convert.ToDateTime("12/31/" + myDate.Year.ToString());

                    break;
            }

            DateRangeStruct retVal;
            retVal.startDate = retValue[0];
            retVal.endDate = retValue[1];

            return retVal;
        }
 /// <summary>
 /// Removes a date range option from the current list of options available
 /// </summary>
 /// <param name="option">The date range option to remove</param>
 public void RemoveDateOption(DateRangeOptions option)
 {
     _manager.RemoveDateOption(option);
 }
 /// <summary>
 /// Returns the display string for the date range option supplied
 /// </summary>
 /// <param name="option">The date range enumeration</param>
 /// <returns>Returns the string if found, otherwise throws an
 /// ArgumentException</returns>
 public string GetDateRangeString(DateRangeOptions option)
 {
     return(_manager.GetDateRangeString(option));
 }
 /// <summary>
 /// Adds a date range option to the current list of options available
 /// </summary>
 /// <param name="option">The date range option to add</param>
 public void AddDateOption(DateRangeOptions option)
 {
     _manager.AddDateOption(option);
 }
Beispiel #28
0
 public static DateRangeStruct DateRange(DateRangeOptions DRO, string relativeDate)
 {
     return(DateRange(DRO, Convert.ToDateTime(relativeDate)));
 }
Beispiel #29
0
 /// <summary>
 /// Returns a string array with start and end dates for a given range.
 /// </summary>
 /// <example>
 /// If you pass the current date, and wish to know the first
 /// and last days of the week based on the current day:
 /// <code>
 /// using Mezzocode.Halide3;
 /// ...
 /// DateRangeStruct result = h3Temporal.DateRange(
 ///		h3Temporal.DateRangeOptions.Week,
 ///		DateTime.Now
 ///		);
 ///		
 /// Response.Write ("The first day of the week is " + result.startDate.ToString() + 
 /// ", and the last day of the week is " + result.endDate.ToString());
 /// </code>
 /// </example>
 /// <param name="DRO">Enumeration value specifying which abstracted date range to evaluate. Note, weeks begin on Sunday and end on Saturday.</param>
 /// <param name="relativeDate">Date to use as the basis for calculating the start and end date of the range.</param>
 /// <returns>DateTimeStruct with the start and end date of the range.</returns>
 public static DateRangeStruct DateRange(DateRangeOptions DRO, string relativeDate)
 {
     return DateRange(DRO, Convert.ToDateTime(relativeDate));
 }
Beispiel #30
0
    /// <summary>
    /// Returns a string array with start and end dates for a given range.
    /// </summary>
    /// <param name="range">Enumeration value specifying which
    /// abstracted date range to evaluate. Note, weeks begin on Sunday
    /// and end on Saturday.</param>
    /// <param name="relativeDate">Date to use as the basis for
    /// calculating the start and end date of the range.</param>
    /// <returns>DateTimeStruct</returns>
    public static DateRangeStruct DateRange(DateRangeOptions DRO, DateTime relativeDate)
    {
        DateTime[] retValue = { DateTime.Today, DateTime.Today };
        DateTime   myDate   = relativeDate;

        switch (DRO)
        {
        case DateRangeOptions.Week:

            if (myDate.DayOfWeek > 0)
            {
                myDate = myDate.AddDays(-1 * Convert.ToInt32(myDate.DayOfWeek));
            }

            retValue[0] = myDate;
            retValue[1] = myDate.AddDays(6);

            break;

        case DateRangeOptions.Month:

            if (myDate.Day > 1)
            {
                myDate = myDate.AddDays(-1 * (myDate.Day - 1));
            }

            retValue[0] = myDate;
            retValue[1] = myDate.AddMonths(1);
            retValue[1] = retValue[1].AddDays(-1);

            break;

        case DateRangeOptions.Quarter:

            if (myDate.Month < 4)
            {
                retValue[0] = Convert.ToDateTime("1/1/" +
                                                 myDate.Year.ToString());
            }
            if (myDate.Month > 3 && myDate.Month < 7)
            {
                retValue[0] =
                    Convert.ToDateTime("4/1/" + myDate.Year.ToString());
            }
            if (myDate.Month > 6 && myDate.Month < 10)
            {
                retValue[0] =
                    Convert.ToDateTime("7/1/" + myDate.Year.ToString());
            }
            if (myDate.Month > 9)
            {
                retValue[0] = Convert.ToDateTime("10/1/" +
                                                 myDate.Year.ToString());
            }

            retValue[1] = retValue[0].AddMonths(3);
            retValue[1] = retValue[1].AddDays(-1);

            break;

        case DateRangeOptions.Year:

            retValue[0] = Convert.ToDateTime("1/1/" + myDate.Year.ToString());
            retValue[1] = Convert.ToDateTime("12/31/" + myDate.Year.ToString());

            break;
        }

        DateRangeStruct retVal;

        retVal.startDate = retValue[0];
        retVal.endDate   = retValue[1];

        return(retVal);
    }
 /// <summary>
 /// Amends the display string for a given date option
 /// </summary>
 /// <param name="option">The date option to amend</param>
 /// <param name="newDisplayString">The display string to apply</param>
 public void SetDateRangeString(DateRangeOptions option, string newDisplayString)
 {
     _manager.SetDateRangeString(option, newDisplayString);
 }
 /// <summary>
 /// Amends the display string for a given date option
 /// </summary>
 /// <param name="option">The date option to amend</param>
 /// <param name="newDisplayString">The display string to apply</param>
 public void SetDateRangeString(DateRangeOptions option, string newDisplayString)
 {
     if (_optionsToDisplay.Contains(option))
     {
         if (_dateRangePairs.ContainsValue(newDisplayString)
             && _dateRangePairs[option] != newDisplayString)
         {
             throw new ArgumentException("A date range display string " +
                 "is being assigned, but that display string has already " +
                 "been used.");
         }
         int comboBoxPos = _comboBox.Items.IndexOf(_dateRangePairs[option]);
         _comboBox.Items[comboBoxPos] = newDisplayString;
         _dateRangePairs[option] = newDisplayString;
     }
     else
     {
         throw new ArgumentException("A date range string is being changed, " +
             "but the given option does not exist in the collection " +
             "of date options.");
     }
 }
 /// <summary>
 /// Adds a date range option to the current list of options available
 /// </summary>
 /// <param name="option">The date range option to add</param>
 public void AddDateOption(DateRangeOptions option)
 {
     _manager.AddDateOption(option);
 }
 public DateRangeTestCase(DateRangeOptions dateRange, string currentDateStr, string expectedStartDateStr, string expectedEndDateStr)
 {
     DateRangeOptions = dateRange;
     CurrectDate = DateTimeUtilities.ParseToDate(currentDateStr);
     ExpectedStartDate = DateTimeUtilities.ParseToDate(expectedStartDateStr);
     ExpectedEndDate = DateTimeUtilities.ParseToDate(expectedEndDateStr);
 }