示例#1
0
        public static Offset FromInterval(Period interval, DayTypeEnum dayType)
        {
            if ((dayType != DayTypeEnum.Business) & (dayType != DayTypeEnum.Calendar))
            {
                throw new ArgumentOutOfRangeException("dayType", dayType, "Only 'DayTypeEnum.Business' and 'DayTypeEnum.Calendar' day types are currently supported.");
            }


            //  We can only use Business dayType for days intervals.
            //
            if ((dayType == DayTypeEnum.Business) & (interval.period != PeriodEnum.D))
            {
                throw new NotSupportedException();
            }

            Offset offset = new Offset();

            offset.period           = interval.period;
            offset.periodMultiplier = interval.periodMultiplier;

            offset.dayType          = dayType;
            offset.dayTypeSpecified = true;

            return(offset);
        }
        public static RelativeDateOffset Create(string period, DayTypeEnum dayType,
                                                string businessDayConventionAsString,
                                                BusinessCenters businessCenters,
                                                string dateRelativeTo)
        {
            var    result   = new RelativeDateOffset();
            Period interval = PeriodHelper.Parse(period);

            result.period           = interval.period;
            result.periodSpecified  = true;
            result.periodMultiplier = interval.periodMultiplier;
            result.dayType          = dayType;
            result.dayTypeSpecified = true;
            if (businessDayConventionAsString != null)
            {
                result.businessDayConvention          = BusinessDayConventionHelper.Parse(businessDayConventionAsString);
                result.businessDayConventionSpecified = true;
            }
            result.businessCenters = businessCenters;
            if (dateRelativeTo != null)
            {
                var dateReference = new DateReference {
                    href = dateRelativeTo
                };
                result.dateRelativeTo = dateReference;
            }
            return(result);
        }
 public Offset(XmlNode xmlNode)
 : base(xmlNode)
 {
     XmlNodeList dayTypeNodeList = xmlNode.SelectNodes("dayType");
     if (dayTypeNodeList.Count > 1 )
     {
             throw new Exception();
     }
     
     foreach (XmlNode item in dayTypeNodeList)
     {
         if (item.Attributes["href"] != null || item.Attributes["id"] == null) 
         {
             if (item.Attributes["id"] != null) 
             {
                 dayTypeIDRef = item.Attributes["id"].Name;
                 DayTypeEnum ob = DayTypeEnum();
                 IDManager.SetID(dayTypeIDRef, ob);
             }
             else if (item.Attributes.ToString() == "href")
             {
                 dayTypeIDRef = item.Attributes["href"].Name;
             }
             else
             {
                 dayType = new DayTypeEnum(item);
             }
         }
     }
     
 
 }
示例#4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DesignDay" /> class.
        /// </summary>
        /// <param name="name">Name of the object. Must use only ASCII characters and exclude (, ; ! \\n \\t). It cannot be longer than 100 characters. (required).</param>
        /// <param name="dayType">dayType (required).</param>
        /// <param name="dryBulbCondition">A DryBulbCondition describing temperature conditions on the design day. (required).</param>
        /// <param name="humidityCondition">A HumidityCondition describing humidity and precipitation conditions on the design day. (required).</param>
        /// <param name="windCondition">A WindCondition describing wind conditions on the design day. (required).</param>
        /// <param name="skyCondition">skyCondition (required).</param>
        /// <param name="type">type (default to &quot;DesignDay&quot;).</param>
        public DesignDay(string name, DayTypeEnum dayType, DryBulbCondition dryBulbCondition, HumidityCondition humidityCondition, WindCondition windCondition, AnyOf <ASHRAEClearSky, ASHRAETau> skyCondition, string type = "DesignDay")
        {
            // to ensure "name" is required (not null)
            if (name == null)
            {
                throw new InvalidDataException("name is a required property for DesignDay and cannot be null");
            }
            else
            {
                this.Name = name;
            }

            // to ensure "dayType" is required (not null)
            if (dayType == null)
            {
                throw new InvalidDataException("dayType is a required property for DesignDay and cannot be null");
            }
            else
            {
                this.DayType = dayType;
            }

            // to ensure "dryBulbCondition" is required (not null)
            if (dryBulbCondition == null)
            {
                throw new InvalidDataException("dryBulbCondition is a required property for DesignDay and cannot be null");
            }
            else
            {
                this.DryBulbCondition = dryBulbCondition;
            }

            // to ensure "humidityCondition" is required (not null)
            if (humidityCondition == null)
            {
                throw new InvalidDataException("humidityCondition is a required property for DesignDay and cannot be null");
            }
            else
            {
                this.HumidityCondition = humidityCondition;
            }

            // to ensure "windCondition" is required (not null)
            if (windCondition == null)
            {
                throw new InvalidDataException("windCondition is a required property for DesignDay and cannot be null");
            }
            else
            {
                this.WindCondition = windCondition;
            }

            // to ensure "skyCondition" is required (not null)
            if (skyCondition == null)
            {
                throw new InvalidDataException("skyCondition is a required property for DesignDay and cannot be null");
            }
            else
            {
                this.SkyCondition = skyCondition;
            }

            // use default value if no "type" provided
            if (type == null)
            {
                this.Type = "DesignDay";
            }
            else
            {
                this.Type = type;
            }
        }
示例#5
0
        /// <summary>
        /// Advances the given <see cref="DateTime"/> the given
        /// <paramref name="periodMultiplier"/> of time <paramref name="period"/>.
        /// </summary>
        /// <param name="date">The <see cref="DateTime"/> that is to be advanced.</param>
        /// <param name="periodMultiplier">The number of time period to advance.</param>
        /// <param name="period">The <see cref="PeriodEnum"/> used.</param>
        /// <param name="dayType">Type of the day.</param>
        /// <param name="businessDayConvention">The business day convention.</param>
        /// <returns>
        /// Returns the resulting <see cref="DateTime"/>.
        /// </returns>
        /// <overloads>
        /// Advances the given <see cref="DateTime"/>.
        /// </overloads>
        private DateTime Advance(DateTime date, int periodMultiplier, PeriodEnum period, DayTypeEnum dayType, BusinessDayConventionEnum businessDayConvention)
        {
            #region Assert validity of parameters

            if ((dayType != DayTypeEnum.Business) & (dayType != DayTypeEnum.Calendar))
            {
                throw new ArgumentOutOfRangeException(nameof(dayType), dayType, "Only 'DayTypeEnum.Business' and 'DayTypeEnum.Calendar' day types are currently supported.");
            }

            //  We can only use Business dayType for days intervals.
            //
            if ((dayType == DayTypeEnum.Business) & (period != PeriodEnum.D))
            {
                throw new NotSupportedException();
            }

            #endregion

            // handling the NONE day convention
            if (businessDayConvention == BusinessDayConventionEnum.NONE)
            {
                // No rolling if multiplier is zero
                if (periodMultiplier == 0)
                {
                    return(date);
                }
                BusinessDayConventionEnum advConvention = periodMultiplier > 0? BusinessDayConventionEnum.FOLLOWING: BusinessDayConventionEnum.PRECEDING;
                return(Advance(date, periodMultiplier, period, dayType, advConvention));
            }

            if (periodMultiplier == 0)
            {
                return(Roll(date, businessDayConvention));
            }
            if ((period == PeriodEnum.D) & DayTypeEnum.Business == dayType) //Business days
            {
                DateTime returnValue = date;
                if (periodMultiplier > 0)
                {
                    while (periodMultiplier > 0)
                    {
                        returnValue = returnValue.AddDays(1);
                        while (IsHoliday(returnValue))
                        {
                            returnValue = returnValue.AddDays(1);
                        }
                        periodMultiplier--;
                    }
                }
                else
                {
                    while (periodMultiplier < 0)
                    {
                        returnValue = returnValue.AddDays(-1);
                        while (IsHoliday(returnValue))
                        {
                            returnValue = returnValue.AddDays(-1);
                        }
                        periodMultiplier++;
                    }
                }

                return(returnValue);
            }
            var interval = new Period {
                period = period, periodMultiplier = periodMultiplier.ToString(CultureInfo.InvariantCulture)
            };
            return(Roll(Add(date, interval), businessDayConvention));
        }