Exemplo n.º 1
0
        /// <summary>Creates an <c>XMPDateTime</c>-instance from a calendar.</summary>
        /// <param name="calendar">a <c>Calendar</c></param>
        public XmpDateTime(Calendar calendar)
        {
            // extract the date and timezone from the calendar provided
            var date = calendar.GetTime();
            var zone = calendar.GetTimeZone();
            // put that date into a calendar the pretty much represents ISO8601
            // I use US because it is close to the "locale" for the ISO8601 spec
            var intCalendar = (GregorianCalendar)Calendar.GetInstance(CultureInfo.InvariantCulture);

            intCalendar.SetGregorianChange(UnixTimeToDateTime(long.MinValue));
            intCalendar.SetTimeZone(zone);
            intCalendar.SetTime(date);
            _year  = intCalendar.Get(CalendarEnum.Year);
            _month = intCalendar.Get(CalendarEnum.Month) + 1;
            // cal is from 0..12
            _day         = intCalendar.Get(CalendarEnum.DayOfMonth);
            _hour        = intCalendar.Get(CalendarEnum.HourOfDay);
            _minute      = intCalendar.Get(CalendarEnum.Minute);
            _second      = intCalendar.Get(CalendarEnum.Second);
            _nanoseconds = intCalendar.Get(CalendarEnum.Millisecond) * 1000000;
            _timeZone    = intCalendar.GetTimeZone();
            // object contains all date components
            HasDate = HasTime = HasTimeZone = true;
        }
Exemplo n.º 2
0
        private DateTime ConvertResult(Match data)
        {
            Calendar result = Calendar.GetInstance(Culture);

            if (data.Groups[FIELD_YEAR].Success)
            {
                result.Set(CalendarEnum.Year, int.Parse(data.Groups[FIELD_YEAR].Value));
            }
            else
            {
                result.Set(CalendarEnum.Year, 1);
            }

            if (data.Groups[FIELD_MONTH].Success)
            {
                result.Set(CalendarEnum.MonthOneBased, int.Parse(data.Groups[FIELD_MONTH].Value));
            }
            else
            {
                result.Set(CalendarEnum.MonthOneBased, 1);
            }

            if (data.Groups[FIELD_DAY].Success)
            {
                result.Set(CalendarEnum.DayOfMonth, int.Parse(data.Groups[FIELD_DAY].Value));
            }
            else
            {
                result.Set(CalendarEnum.DayOfMonth, 0);
            }

            if (data.Groups[FIELD_HOUR].Success)
            {
                result.Set(CalendarEnum.HourOfDay, int.Parse(data.Groups[FIELD_HOUR].Value));
            }
            else
            {
                result.Set(CalendarEnum.HourOfDay, 0);
            }

            if (data.Groups[FIELD_MINUTE].Success)
            {
                result.Set(CalendarEnum.Minute, int.Parse(data.Groups[FIELD_MINUTE].Value));
            }
            else
            {
                result.Set(CalendarEnum.Minute, 0);
            }

            if (data.Groups[FIELD_SECOND].Success)
            {
                result.Set(CalendarEnum.Second, int.Parse(data.Groups[FIELD_SECOND].Value));
            }
            else
            {
                result.Set(CalendarEnum.Second, 0);
            }

            result.Set(CalendarEnum.Millisecond, 0);

            return(result.GetTime());
        }