<commit_before>using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Text;

namespace DDay.iCal.DataTypes
{
    /// <summary>
    /// Represents an iCalendar period of time.
    /// </summary>
    [DebuggerDisplay("Period ( {StartTime} - {EndTime} )")]
    public class Period : iCalDataType, IComparable
    {
        #region Private Fields

        private Date_Time m_StartTime = new Date_Time();        
        private Date_Time m_EndTime;        
        private Duration m_Duration;
        private bool m_MatchesDateOnly = false;

        #endregion

        #region Public Properties

        public Date_Time StartTime
        {
            get { return m_StartTime; }
            set { m_StartTime = value; }
        }

        public Date_Time EndTime
        {
            get { return m_EndTime; }
            set { m_EndTime = value; }
        }

        public Duration Duration
        {
            get { return m_Duration; }
            set { m_Duration = value; }
        }
        
        /// <summary>
        /// When true, comparisons between this and other <see cref="Period"/>
        /// objects are matched against the date only, and
        /// not the date-time combination.
        /// </summary>
        public bool MatchesDateOnly
        {
            get { return m_MatchesDateOnly; }
            set { m_MatchesDateOnly = value; }
        }

        #endregion

        #region Constructors

        public Period() { }
        public Period(Date_Time occurs) : this(occurs, null) { }
        public Period(Date_Time start, Date_Time end)
            : this()
        {
            StartTime = start.Copy();
            if (end != null)
            {
                EndTime = end.Copy();
                Duration = new Duration(end.Value - start.Value);
            }
            else
            {
                EndTime = StartTime;
                Duration = new Duration(new TimeSpan(0));
            }
        }
        public Period(Date_Time start, TimeSpan duration)
            : this()
        {
            StartTime = start.Copy();
            if (duration != TimeSpan.MinValue)
            {
                Duration = new Duration(duration);
                EndTime = start + duration;
            }
            else
            {
                Duration = new Duration(new TimeSpan(0));
                EndTime = StartTime;                
            }
        }
        public Period(string value)
            : this()
        {
            CopyFrom((Period)Parse(value));
        }

        #endregion

        #region Overrides
        
        public override bool Equals(object obj)
        {
            if (obj is Period)
            {
                Period p = (Period)obj;
                if (MatchesDateOnly || p.MatchesDateOnly)
                {
                    return
                        StartTime.Value.Date == p.StartTime.Value.Date &&
                        (
                            EndTime == null ||
                            p.EndTime == null ||<commit_msg>Fixed a bug that caused equivalent periods to compare unequally (due to improper initialization in constructor)<commit_after>using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Text;

namespace DDay.iCal.DataTypes
{
    /// <summary>
    /// Represents an iCalendar period of time.
    /// </summary>
    [DebuggerDisplay("Period ( {StartTime} - {EndTime} )")]
    public class Period : iCalDataType, IComparable
    {
        #region Private Fields

        private Date_Time m_StartTime = new Date_Time();        
        private Date_Time m_EndTime;        
        private Duration m_Duration;
        private bool m_MatchesDateOnly = false;

        #endregion

        #region Public Properties

        public Date_Time StartTime
        {
            get { return m_StartTime; }
            set { m_StartTime = value; }
        }

        public Date_Time EndTime
        {
            get { return m_EndTime; }
            set { m_EndTime = value; }
        }

        public Duration Duration
        {
            get { return m_Duration; }
            set { m_Duration = value; }
        }
        
        /// <summary>
        /// When true, comparisons between this and other <see cref="Period"/>
        /// objects are matched against the date only, and
        /// not the date-time combination.
        /// </summary>
        public bool MatchesDateOnly
        {
            get { return m_MatchesDateOnly; }
            set { m_MatchesDateOnly = value; }
        }

        #endregion

        #region Constructors

        public Period() { }
        public Period(Date_Time occurs) : this(occurs, null) { }
        public Period(Date_Time start, Date_Time end)
            : this()
        {
            StartTime = start.Copy();
            if (end != null)
            {
                EndTime = end.Copy();
                Duration = new Duration(end.Value - start.Value);
            }            
        }
        public Period(Date_Time start, TimeSpan duration)
            : this()
        {
            StartTime = start.Copy();
            if (duration != TimeSpan.MinValue)
            {
                Duration = new Duration(duration);
                EndTime = start + duration;
            }            
        }
        public Period(string value)
            : this()
        {
            CopyFrom((Period)Parse(value));
        }

        #endregion

        #region Overrides
        
        public override bool Equals(object obj)
        {
            if (obj is Period)
            {
                Period p = (Period)obj;
                if (MatchesDateOnly || p.MatchesDateOnly)
                {
                    return
                        StartTime.Value.Date == p.StartTime.Value.Date &&
                        (
                            EndTime == null ||
                            p.EndTime == null ||
{'fraction_non_alphanumeric': 0.08547579298831386, 'fraction_numerical': 0.000333889816360601, 'mean_word_length': 1.2693181818181818, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6860781', 'n_tokens_mistral': 1526, 'n_tokens_neox': 1469, 'n_words': 391}