Esempio n. 1
0
        public TimeSpan GetUTCOffsetFromLocalTime(DateTimeOffset localTime)
        {
            if (TimeChanges == null || (TimeChanges != null && TimeChanges.Count() == 0))
            {
                throw new MissingTimeChangesException("IncludeTimeChanges either set to false or no time changes for this location");
            }

            var firstNewLocalTime = TimeChanges.FirstOrDefault().NewLocalTime.Year;

            if (localTime.Year != firstNewLocalTime)
            {
                throw new QueriedDateOutOfRangeException("The year specified in localTime is outside the year available for this location");
            }

            TimeChange change;

            if (TimeChanges.Count() == 1)
            {
                change = TimeChanges.SingleOrDefault();
            }
            else
            {
                change = GetTimeChangeForLocalTime(TimeChanges.ToList(), localTime);
            }

            TimeSpan span;

            if (localTime.ToMinuteCompare(change.OldLocalTime.DateTime) < 0)
            {
                span = change.OldLocalTime.DateTime - change.UtcTime.DateTime;
            }
            else
            {
                span = TimeSpan.FromSeconds(change.NewTotalOffset);
            }

            return(span);
        }
Esempio n. 2
0
        private void AttributesChanged(AttributesMusicXML attributes, int cursorPosition, string measureNumber, bool firstMeasure = false)
        {
            ClefChanges clefs = new ClefChanges();
            KeyChanges  keys  = new KeyChanges();
            TimeChanges times = new TimeChanges();

            //! search for clefs
            if (attributes.Clef.Count == 0 && firstMeasure)
            {
                for (var i = 1; i <= _numberOfStaves; i++)
                {
                    clefs.Add(i.ToString(), cursorPosition, new ClefMusicXML()
                    {
                        Sign = ClefSignMusicXML.G, Line = 2.ToString()
                    });
                }
            }
            else
            {
                for (var i = 0; i < attributes.Clef.Count; i++)
                {
                    clefs.Add(attributes.Clef[i].Number, cursorPosition, attributes.Clef[i]);
                }
            }
            //! search for key signatures
            if (attributes.Key.Count == 0 && firstMeasure)
            {
                for (int i = 1; i <= _numberOfStaves; i++)
                {
                    keys.Add(i.ToString(), cursorPosition,
                             new KeyMusicXML {
                        Items = new object[] { 0.ToString() }, ItemsElementName = new[] { KeyChoiceTypes.fifths }
                    });
                }
            }
            else
            {
                for (int i = 0; i < attributes.Key.Count; i++)
                {
                    keys.Add(attributes.Key[i].Number, cursorPosition, attributes.Key[i]);
                }
            }
            //! search for time signatures
            if (attributes.Time.Count == 0 && firstMeasure)
            {
                for (int i = 1; i <= _numberOfStaves; i++)
                {
                    times.Add(i.ToString(), cursorPosition,
                              new TimeMusicXML
                    {
                        Items            = new object[] { "4", "4" },
                        ItemsElementName = new[] { TimeChoiceTypeMusicXML.beats, TimeChoiceTypeMusicXML.beattype }
                    });
                }
            }
            else
            {
                for (int i = 0; i < attributes.Time.Count; i++)
                {
                    times.Add(attributes.Time[i].Number, cursorPosition, attributes.Time[i]);
                }
            }

            if (clefs.AttributeChanges.Count != 0)
            {
                _clefChanges.Add(measureNumber, clefs);
            }

            if (keys.AttributeChanges.Count != 0)
            {
                _keyChanges.Add(measureNumber, keys);
            }

            if (times.AttributeChanges.Count != 0)
            {
                _timeChanges.Add(measureNumber, times);
            }
        }
 public Model(string id, TimeChanges timeChanges)
 {
     TimeChanges = timeChanges;
     Id          = id;
 }