getTZ(String tzOffset) { /* ** Only a small number timezones are expected to be active. ** Timezones and offsets are cached for quick access. */ TimeZone tz; lock (tzCache.SyncRoot) // sync access to the static tzCache hash { tz = (TimeZone)tzCache[tzOffset]; if (tz == null) { /* ** Construct timezone for offset */ int offset = parseOffset(tzOffset); tz = new SimpleTimeZone(offset * 60000, "GMT" + tzOffset); tzCache.Add(tzOffset, tz); } } // end lock return(tz); } // getTZ
protected override async void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.AlarmLayout); Context context = this.ApplicationContext; Intent intent = new Intent(context, typeof(AlarmReceiver)); PendingIntent pendingIntent_afternoon; AlarmService service = new AlarmService(); string med = await service.getMedicine(); string[] values = Regex.Split(med, "&"); Console.WriteLine(string.Format("Medicine: {0}", med)); intent.PutExtra("MedicineName", values[0]); if (Convert.ToInt32(values[1].Trim()) > 3) { intent.PutExtra("NumberofTimes", (values[1].Trim())); intent.PutExtra("afternoon", "false"); intent.PutExtra("evening", "true"); intent.PutExtra("check", "false"); } else { intent.PutExtra("NumberofTimes", "2"); } Locale loc = new Locale("en", "us"); // Create Pacific time zone with -8 hours offset: Java.Util.TimeZone tz = new SimpleTimeZone(-28800000, "America/Los_Angeles"); Calendar cal_alarm_afternoon = Calendar.GetInstance(tz, loc); cal_alarm_afternoon.Set(CalendarField.HourOfDay, 16); cal_alarm_afternoon.Set(CalendarField.Minute, 58); cal_alarm_afternoon.Set(CalendarField.Second, 0); pendingIntent_afternoon = PendingIntent.GetBroadcast(context, 0, intent, PendingIntentFlags.UpdateCurrent); AlarmManager manager = (AlarmManager)GetSystemService(Context.AlarmService); manager.SetRepeating(AlarmType.RtcWakeup, cal_alarm_afternoon.TimeInMillis, Android.App.AlarmManager.IntervalDay, pendingIntent_afternoon); Toast.MakeText(this, "Alarm Set for afternoon", ToastLength.Long).Show(); }
protected override async void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.AlarmLayout); Context context = this.ApplicationContext; Intent intent = new Intent(context, typeof(AlarmReceiver)); PendingIntent pendingIntent_afternoon; AlarmService service = new AlarmService(); string med = await service.getMedicine(); string[] values = Regex.Split(med, "&"); Console.WriteLine(string.Format("Medicine: {0}", med)); intent.PutExtra("MedicineName", values[0]); if(Convert.ToInt32(values[1].Trim()) > 3) { intent.PutExtra("NumberofTimes", (values[1].Trim())); intent.PutExtra("afternoon", "false"); intent.PutExtra("evening", "true"); intent.PutExtra("check", "false"); } else { intent.PutExtra("NumberofTimes", "2"); } Locale loc = new Locale("en", "us"); // Create Pacific time zone with -8 hours offset: Java.Util.TimeZone tz = new SimpleTimeZone(-28800000, "America/Los_Angeles"); Calendar cal_alarm_afternoon = Calendar.GetInstance(tz, loc); cal_alarm_afternoon.Set(CalendarField.HourOfDay, 16); cal_alarm_afternoon.Set(CalendarField.Minute, 58); cal_alarm_afternoon.Set(CalendarField.Second, 0); pendingIntent_afternoon = PendingIntent.GetBroadcast(context, 0, intent, PendingIntentFlags.UpdateCurrent); AlarmManager manager = (AlarmManager)GetSystemService(Context.AlarmService); manager.SetRepeating(AlarmType.RtcWakeup, cal_alarm_afternoon.TimeInMillis, Android.App.AlarmManager.IntervalDay, pendingIntent_afternoon); Toast.MakeText(this, "Alarm Set for afternoon", ToastLength.Long).Show(); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.AlarmLayout); Context context = this.ApplicationContext; Intent intent = new Intent(context, typeof(AlarmReceiver)); PendingIntent pendingIntent_morning; Button alarmset = FindViewById<Button>(Resource.Id.AlarmSet); alarmset.Click += async delegate { AlarmService service = new AlarmService(); string med = await service.getMedicine(); string[] values = Regex.Split(med, "&"); Console.WriteLine(string.Format( "Medicine: {0}", med)); intent.PutExtra("MedicineName", values[0]); intent.PutExtra("NumberofTimes", values[1].Trim()); intent.PutExtra("check", "true"); var numOfTime = values[1].Trim(); Locale loc = new Locale("en", "us"); // Create Pacific time zone with -8 hours offset: Java.Util.TimeZone tz = new SimpleTimeZone(-28800000, "America/Los_Angeles"); //morning alarm Calendar cal_alarm_morning = Calendar.GetInstance(tz, loc); cal_alarm_morning.Set(CalendarField.HourOfDay, 16); cal_alarm_morning.Set(CalendarField.Minute, 55); cal_alarm_morning.Set(CalendarField.Second, 0); pendingIntent_morning = PendingIntent.GetBroadcast(context, 0, intent, 0); AlarmManager manager = (AlarmManager)GetSystemService(Context.AlarmService); manager.SetRepeating(AlarmType.RtcWakeup, cal_alarm_morning.TimeInMillis, Android.App.AlarmManager.IntervalDay, pendingIntent_morning); Toast.MakeText(this, "Alarm Set", ToastLength.Long).Show(); }; }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.AlarmLayout); Context context = this.ApplicationContext; Intent intent = new Intent(context, typeof(AlarmReceiver)); PendingIntent pendingIntent_morning; Button alarmset = FindViewById <Button>(Resource.Id.AlarmSet); alarmset.Click += async delegate { AlarmService service = new AlarmService(); string med = await service.getMedicine(); string[] values = Regex.Split(med, "&"); Console.WriteLine(string.Format("Medicine: {0}", med)); intent.PutExtra("MedicineName", values[0]); intent.PutExtra("NumberofTimes", values[1].Trim()); intent.PutExtra("check", "true"); var numOfTime = values[1].Trim(); Locale loc = new Locale("en", "us"); // Create Pacific time zone with -8 hours offset: Java.Util.TimeZone tz = new SimpleTimeZone(-28800000, "America/Los_Angeles"); //morning alarm Calendar cal_alarm_morning = Calendar.GetInstance(tz, loc); cal_alarm_morning.Set(CalendarField.HourOfDay, 16); cal_alarm_morning.Set(CalendarField.Minute, 55); cal_alarm_morning.Set(CalendarField.Second, 0); pendingIntent_morning = PendingIntent.GetBroadcast(context, 0, intent, 0); AlarmManager manager = (AlarmManager)GetSystemService(Context.AlarmService); manager.SetRepeating(AlarmType.RtcWakeup, cal_alarm_morning.TimeInMillis, Android.App.AlarmManager.IntervalDay, pendingIntent_morning); Toast.MakeText(this, "Alarm Set", ToastLength.Long).Show(); }; }
/// <exclude/> /// <summary> /// The public version of this API only accepts LONG/SHORT, the internal /// version (which this calls) also accepts LONG_GENERIC/SHORT_GENERIC. /// </summary> /// private String _getDisplayName(bool daylight, int style, ULocale locale) { /* * NOTES: (1) We use SimpleDateFormat for simplicity; we could do this * more efficiently but it would duplicate the SimpleDateFormat code * here, which is undesirable. (2) Attempts to move the code from * SimpleDateFormat to here also run aground because this requires * SimpleDateFormat to keep a Locale object around, which it currently * doesn't; to synthesize such a locale upon resurrection; and to * somehow handle the special case of construction from a * DateFormatSymbols object. */ // We keep a cache, indexed by locale. The cache contains a // SimpleDateFormat object, which we create on demand. WeakReference data = (WeakReference)cachedLocaleData[locale]; IBM.ICU.Text.SimpleDateFormat format; if (data == null || (format = (IBM.ICU.Text.SimpleDateFormat)data.Target) == null) { format = new IBM.ICU.Text.SimpleDateFormat(null, locale); ILOG.J2CsMapping.Collections.Collections.Put(cachedLocaleData, locale, new WeakReference(format)); } String[] patterns = { "z", "zzzz", "v", "vvvv" }; format.ApplyPattern(patterns[style]); if (style >= 2) { // Generic names may change time to time even for a single time // zone. // This method returns the one used for the zone now. format.SetTimeZone(this); return(format.Format(DateTime.Now)); } else { // Create a new SimpleTimeZone as a stand-in for this zone; the // stand-in // will have no DST, or DST during January, but the same ID and // offset, // and hence the same display name. We don't cache these because // they're small and cheap to create. SimpleTimeZone tz; if (daylight && UseDaylightTime()) { int savings = GetDSTSavings(); tz = new SimpleTimeZone(GetRawOffset(), GetID(), IBM.ICU.Util.Calendar.JANUARY, 1, 0, 0, IBM.ICU.Util.Calendar.FEBRUARY, 1, 0, 0, savings); } else { tz = new SimpleTimeZone(GetRawOffset(), GetID()); } format.SetTimeZone(tz); // Format a date in January. We use the value 10*ONE_DAY == Jan 11 // 1970 // 0:00 GMT. return(format.Format(new DateTime((864000000L) * 10000))); } }
public void TestSunriseTimes() { // logln("Sunrise/Sunset times for San Jose, California, USA"); // CalendarAstronomer astro = new CalendarAstronomer(-121.55, 37.20); // TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles"); // We'll use a table generated by the UNSO website as our reference // From: http://aa.usno.navy.mil/ // -Location: W079 25, N43 40 // -Rise and Set for the Sun for 2001 // -Zone: 4h West of Greenwich int[] USNO = { 6, 59, 19, 45, 6, 57, 19, 46, 6, 56, 19, 47, 6, 54, 19, 48, 6, 52, 19, 49, 6, 50, 19, 51, 6, 48, 19, 52, 6, 47, 19, 53, 6, 45, 19, 54, 6, 43, 19, 55, 6, 42, 19, 57, 6, 40, 19, 58, 6, 38, 19, 59, 6, 36, 20, 0, 6, 35, 20, 1, 6, 33, 20, 3, 6, 31, 20, 4, 6, 30, 20, 5, 6, 28, 20, 6, 6, 27, 20, 7, 6, 25, 20,8, 6, 23, 20, 10, 6, 22, 20, 11, 6, 20, 20, 12, 6, 19, 20, 13, 6, 17, 20, 14, 6, 16, 20, 16, 6, 14, 20, 17, 6, 13, 20, 18, 6, 11, 20, 19, }; Logln("Sunrise/Sunset times for Toronto, Canada"); CalendarAstronomer astro = new CalendarAstronomer(-(79 + 25 / 60), 43 + 40 / 60); // As of ICU4J 2.8 the ICU4J time zones implement pass-through // to the underlying JDK. Because of variation in the // underlying JDKs, we have to use a fixed-offset // SimpleTimeZone to get consistent behavior between JDKs. // The offset we want is [-18000000, 3600000] (raw, dst). // [aliu 10/15/03] // TimeZone tz = TimeZone.getTimeZone("America/Montreal"); IBM.ICU.Util.TimeZone tz = new SimpleTimeZone(-18000000 + 3600000, "Montreal(FIXED)"); IBM.ICU.Util.GregorianCalendar cal = new IBM.ICU.Util.GregorianCalendar(tz, Locale.US); IBM.ICU.Util.GregorianCalendar cal2 = new IBM.ICU.Util.GregorianCalendar(tz, Locale.US); cal.Clear(); cal.Set(IBM.ICU.Util.Calendar.YEAR, 2001); cal.Set(IBM.ICU.Util.Calendar.MONTH, IBM.ICU.Util.Calendar.APRIL); cal.Set(IBM.ICU.Util.Calendar.DAY_OF_MONTH, 1); cal.Set(IBM.ICU.Util.Calendar.HOUR_OF_DAY, 12); // must be near local noon for // getSunRiseSet to work IBM.ICU.Text.DateFormat df = IBM.ICU.Text.DateFormat.GetTimeInstance(cal, IBM.ICU.Text.DateFormat.MEDIUM, Locale.US); IBM.ICU.Text.DateFormat df2 = IBM.ICU.Text.DateFormat.GetDateTimeInstance(cal, IBM.ICU.Text.DateFormat.MEDIUM, IBM.ICU.Text.DateFormat.MEDIUM, Locale.US); IBM.ICU.Text.DateFormat day = IBM.ICU.Text.DateFormat.GetDateInstance(cal, IBM.ICU.Text.DateFormat.MEDIUM, Locale.US); for (int i = 0; i < 30; i++) { astro.SetDate(cal.GetTime()); DateTime sunrise = DateUtil.DateFromJavaMillis(astro.GetSunRiseSet(true)); DateTime sunset = DateUtil.DateFromJavaMillis(astro.GetSunRiseSet(false)); cal2.SetTime(cal.GetTime()); cal2.Set(IBM.ICU.Util.Calendar.SECOND, 0); cal2.Set(IBM.ICU.Util.Calendar.MILLISECOND, 0); cal2.Set(IBM.ICU.Util.Calendar.HOUR_OF_DAY, USNO[4 * i + 0]); cal2.Set(IBM.ICU.Util.Calendar.MINUTE, USNO[4 * i + 1]); DateTime exprise = cal2.GetTime(); cal2.Set(IBM.ICU.Util.Calendar.HOUR_OF_DAY, USNO[4 * i + 2]); cal2.Set(IBM.ICU.Util.Calendar.MINUTE, USNO[4 * i + 3]); DateTime expset = cal2.GetTime(); // Compute delta of what we got to the USNO data, in seconds int deltarise = Math.Abs((int)((sunrise.Ticks / 10000) - (exprise.Ticks / 10000)) / 1000); int deltaset = Math.Abs((int)((sunset.Ticks / 10000) - (expset.Ticks / 10000)) / 1000); // Allow a deviation of 0..MAX_DEV seconds // It would be nice to get down to 60 seconds, but at this // point that appears to be impossible without a redo of the // algorithm using something more advanced than Duffett-Smith. int MAX_DEV = 180; if (deltarise > MAX_DEV || deltaset > MAX_DEV) { if (deltarise > MAX_DEV) { Errln("FAIL: " + day.Format(cal.GetTime()) + ", Sunrise: " + df2.Format(sunrise) + " (USNO " + df.Format(exprise) + " d=" + deltarise + "s)"); } else { Logln(day.Format(cal.GetTime()) + ", Sunrise: " + df.Format(sunrise) + " (USNO " + df.Format(exprise) + ")"); } if (deltaset > MAX_DEV) { Errln("FAIL: " + day.Format(cal.GetTime()) + ", Sunset: " + df2.Format(sunset) + " (USNO " + df.Format(expset) + " d=" + deltaset + "s)"); } else { Logln(day.Format(cal.GetTime()) + ", Sunset: " + df.Format(sunset) + " (USNO " + df.Format(expset) + ")"); } } else { Logln(day.Format(cal.GetTime()) + ", Sunrise: " + df.Format(sunrise) + " (USNO " + df.Format(exprise) + ")" + ", Sunset: " + df.Format(sunset) + " (USNO " + df.Format(expset) + ")"); } cal.Add(IBM.ICU.Util.Calendar.DATE, 1); } // CalendarAstronomer a = new CalendarAstronomer(-(71+5/60), 42+37/60); // cal.clear(); // cal.set(cal.YEAR, 1986); // cal.set(cal.MONTH, cal.MARCH); // cal.set(cal.DATE, 10); // cal.set(cal.YEAR, 1988); // cal.set(cal.MONTH, cal.JULY); // cal.set(cal.DATE, 27); // a.setDate(cal.getTime()); // long r = a.getSunRiseSet2(true); }