Пример #1
0
        protected override BaseDialogFragment.Builder Build(BaseDialogFragment.Builder builder)
        {
            string title = Title;

            if (!TextUtils.IsEmpty(title))
            {
                builder.SetTitle(title);
            }

            string positiveButtonText = PositiveButtonText;

            if (!TextUtils.IsEmpty(positiveButtonText))
            {
                builder.SetPositiveButton(positiveButtonText, new PositiveButtonClickListener(this));
            }

            string negativeButtonText = NegativeButtonText;

            if (!TextUtils.IsEmpty(negativeButtonText))
            {
                builder.SetNegativeButton(negativeButtonText, new NegativeButtonClickListener(this));
            }
            mDatePicker = (DatePicker)LayoutInflater.From(Activity).Inflate(Resource.Layout.sdl_datepicker, null);
            builder.SetView(mDatePicker);

            Java.Util.TimeZone zone = Java.Util.TimeZone.GetTimeZone(Arguments.GetString(ARG_ZONE));
            mCalendar = Calendar.GetInstance(zone);
            mCalendar.TimeInMillis = Arguments.GetLong(ARG_DATE, JavaSystem.CurrentTimeMillis());
            mDatePicker.UpdateDate(mCalendar.Get(CalendarField.Year), mCalendar.Get(CalendarField.Month), mCalendar.Get(CalendarField.Date));

            return(builder);
        }
Пример #2
0
        public static DateTime Parse(string s, IFormatProvider provider, DateTimeStyles style)
        {
            if (s == null)
            {
                throw new ArgumentNullException("s");
            }

            s = s.Trim();

            // try all .NET date time formats
            // Note: the Date/Time handling in java is just broken, and putting a
            //       .NET compatibility layer on top of it will probalby not fix much
            var ci = provider.ToCultureInfo();

            string[] formats =
            {
                ci.DateTimeFormat.UniversalSortableDateTimePattern,
                ci.DateTimeFormat.SortableDateTimePattern,
                ci.DateTimeFormat.FullDateTimePattern,
                ci.DateTimeFormat.RFC1123Pattern,
                ci.DateTimeFormat.LongDatePattern,
                ci.DateTimeFormat.LongTimePattern,
                ci.DateTimeFormat.ShortDatePattern,
                ci.DateTimeFormat.ShortTimePattern
            };

            var utc = TimeZone.GetTimeZone("UTC");

            // Note: I'm not sure this whole approach is the best anyway. Exception handling
            //       for control flow, a loop to tests all formats and such.
            //       It would probably better to use jodatime or nodatime. Maybe the parsing
            //       routine can be ripped off nodatime, so we don't have to include the whole
            //       library.

            foreach (var pattern in formats)
            {
                try
                {
                    var formatter = DateFormatFactory.GetFormat(pattern, DateTimeKind.Unspecified, provider);
                    formatter.Format.TimeZone = utc; // reset mutable value

                    Date parsed = formatter.Format.Parse(s);
                    var  result = FromParsedDate(parsed, s, style, formatter.Format, formatter.ContainsK, formatter.UseUtc);
                    return(result);
                }
                catch (ParseException)
                {
                }
            }
            throw new ArgumentException("unable to parse " + s);
        }
Пример #3
0
        public DateTime ConvertUtcToLocalTimeZone(DateTime dateTimeUtc)
        {
            // get the UTC/GMT Time Zone
            Java.Util.TimeZone utcGmtTimeZone = Java.Util.TimeZone.GetTimeZone("UTC");
            // get the local Time Zone
            Java.Util.TimeZone localTimeZone = Java.Util.TimeZone.Default;
            // convert the DateTime to Java type
            Date javaDate = DateTimeToNativeDate(dateTimeUtc);
            // convert to new time zone
            Date timeZoneDate = ConvertTimeZone(javaDate, utcGmtTimeZone, localTimeZone);
            // convert to systwem.datetime
            DateTime timeZoneDateTime = NativeDateToDateTime(timeZoneDate);

            return(timeZoneDateTime.ToLocalTime());
        }
Пример #4
0
        public static DateTime ParseExact(string s, string format, IFormatProvider provider, DateTimeStyles style)
        {
            // Note: the Date/Time handling in java is just broken, and putting a
            //       .NET compatibility layer on top of it will probalby not fix much
            if (s == null || format == null)
            {
                throw new ArgumentNullException();
            }

            if ((style & DateTimeStyles.AllowLeadingWhite) != 0)
            {
                s = s.TrimStart();
            }
            if ((style & DateTimeStyles.AllowTrailingWhite) != 0)
            {
                s = s.TrimEnd();
            }
            if ((style & DateTimeStyles.AllowWhiteSpaces) != 0)
            {
                s = s.Trim();
            }

            try
            {
                var formatter = DateFormatFactory.GetFormat(format, DateTimeKind.Unspecified, provider);
                formatter.Format.TimeZone = TimeZone.GetTimeZone("UTC"); // reset mutable value

                Date parsed = formatter.Format.Parse(s);

                var result = FromParsedDate(parsed, s, style, formatter.Format, formatter.ContainsK, formatter.UseUtc);
                return(result);
            }
            catch (ArgumentException ex)
            {
                throw new FormatException(ex.Message);
            }
            catch (ParseException ex)
            {
                throw new ArgumentException(ex.Message, "s");
            }
        }
Пример #5
0
        /// <summary>
        /// Converts a date between time zones
        /// </summary>
        /// <returns>The date in the converted timezone.</returns>
        /// <param name="date">Date to convert</param>
        /// <param name="fromTZ">from Time Zone</param>
        /// <param name="toTZ">To Time Zone</param>
        public static Java.Util.Date ConvertTimeZone(Java.Util.Date date, Java.Util.TimeZone fromTZ, Java.Util.TimeZone toTZ)
        {
            long fromTZDst = 0;

            if (fromTZ.InDaylightTime(date))
            {
                fromTZDst = fromTZ.DSTSavings;
            }

            long fromTZOffset = fromTZ.RawOffset + fromTZDst;

            long toTZDst = 0;

            if (toTZ.InDaylightTime(date))
            {
                toTZDst = toTZ.DSTSavings;
            }

            long toTZOffset = toTZ.RawOffset + toTZDst;

            return(new Java.Util.Date(date.Time + (toTZOffset - fromTZOffset)));
        }
        private DateTime parseTimestampStringToDate(MedicationSchedule ms)
        {
            DateFormat utcFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
            {
                TimeZone = TimeZone.GetTimeZone("UTC")
            };
            var date = new DateTime();

            try
            {
                date = DateTime.Parse(ms.Timestampstring);
                DateFormat pstFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS")
                {
                    TimeZone = TimeZone.GetTimeZone("PST")
                };
                Log.Error(Log_Tag, "timestampstring parsed" + date.ToLocalTime().ToString());
            }
            catch (ParseException e)
            {
                e.PrintStackTrace();
            }
            return(date.ToLocalTime());
        }
Пример #7
0
        public void AddAppointment(string desc, int day, int year, int month)
        {
            Java.Util.TimeZone timeZone = Java.Util.TimeZone.Default;

            ContentValues eventValues = new ContentValues();

            eventValues.Put(CalendarContract.Events.InterfaceConsts.CalendarId, "1");
            eventValues.Put(CalendarContract.Events.InterfaceConsts.Title, "Your AutoCal event");
            eventValues.Put(CalendarContract.Events.InterfaceConsts.Description, desc);
            eventValues.Put(CalendarContract.Events.InterfaceConsts.Dtstart, GetDateTimeMS(year, month, day, 00, 0));
            eventValues.Put(CalendarContract.Events.InterfaceConsts.Dtend, GetDateTimeMS(year, month, day, 23, 59));
            //eventValues.Put(CalendarContract.ExtraEventBeginTime, "00:00");
            //eventValues.Put(CalendarContract.ExtraEventEndTime, "23:59");
            eventValues.Put(CalendarContract.Events.InterfaceConsts.EventTimezone, timeZone.ID);
            eventValues.Put(CalendarContract.Events.InterfaceConsts.EventEndTimezone, timeZone.ID);

            //ContentResolver contResv = getApplicationContext().getContentResolver();
            //Context context = (Context) this.getActivity().getApplicationContext().getContentResolver();
            //ContentResolver result = (ContentResolver)context.getContentResolver();
            Android.Net.Uri uri = ContentResolver.Insert(CalendarContract.Events.ContentUri, eventValues);


            //long startTime = ;
            //Intent intent = new Intent(Intent.ActionInsert);
            //
            //intent.PutExtra(CalendarContract.Events.InterfaceConsts.Title, "New calendarEvent by Team B");
            //intent.PutExtra(CalendarContract.Events.InterfaceConsts.Description, desc);
            //intent.PutExtra(CalendarContract.Events.InterfaceConsts.Dtstart, GetDateTimeMS(year, month, day, 00, 0));
            //intent.PutExtra(CalendarContract.Events.InterfaceConsts.Dtend, GetDateTimeMS(year, month, day, 23, 59));
            //intent.PutExtra(CalendarContract.ExtraEventBeginTime, "00:00");
            //intent.PutExtra(CalendarContract.ExtraEventEndTime, "23:59");
            //intent.PutExtra(CalendarContract.Events.InterfaceConsts.EventTimezone, timeZone.ID);
            //intent.PutExtra(CalendarContract.Events.InterfaceConsts.EventEndTimezone, timeZone.ID);
            //intent.SetData(CalendarContract.Events.ContentUri);
            //((Activity)Forms.Context).StartActivity(intent);
        }
Пример #8
0
            // Called whenever the watch face is becoming visible or hidden.
            // Note that you must call base.OnVisibilityChanged first:

            public override void OnVisibilityChanged(bool visible)
            {
                base.OnVisibilityChanged(visible);

                if (Log.IsLoggable(Tag, LogPriority.Debug))
                {
                    Log.Debug(Tag, "OnVisibilityChanged: " + visible);
                }

                // If the watch face became visible, register the timezone receiver and get the current time.

                // Else, unregister the timezone receiver:

                if (visible)
                {
                    RegisterTimezoneReceiver();
                    _calendar.Clear(CalendarField.ZoneOffset);
                    _calendar.TimeZone = TimeZone.GetTimeZone(TimeZone.Default.ID);
                }
                else
                {
                    UnregisterTimezoneReceiver();
                }
            }