/// <summary> /// 根据所给时间计算出该时间所在的周是那一年的第几周 /// </summary> /// <param name="dt">参考时间</param> /// <returns></returns> public static int GetWeekOfYear(DateTime dt) { System.Globalization.GregorianCalendar gc = new System.Globalization.GregorianCalendar(); int weekOfYear = gc.GetWeekOfYear(dt, System.Globalization.CalendarWeekRule.FirstDay, DayOfWeek.Monday); return(weekOfYear); }
public int GetWeekOfYear(DateTime d) { System.Globalization.GregorianCalendar cal = new System.Globalization.GregorianCalendar(System.Globalization.GregorianCalendarTypes.Localized); int weekOfYear = cal.GetWeekOfYear(d, System.Globalization.CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday); return(weekOfYear); }
private static void CalculateWeeks() { // <Snippet5> var thTH = new System.Globalization.CultureInfo("th-TH"); var thCalendar = thTH.DateTimeFormat.Calendar; var dat = new DateTime(1395, 8, 18, thCalendar); Console.WriteLine("Using the Thai Buddhist Era calendar:"); Console.WriteLine($"Date: {dat.ToString("d", thTH)}"); Console.WriteLine($"Day of Week: {thCalendar.GetDayOfWeek(dat)}"); Console.WriteLine($"Week of year: {thCalendar.GetWeekOfYear(dat, System.Globalization.CalendarWeekRule.FirstDay, DayOfWeek.Sunday)}\n"); var greg = new System.Globalization.GregorianCalendar(); Console.WriteLine("Using the Gregorian calendar:"); Console.WriteLine($"Date: {dat:d}"); Console.WriteLine($"Day of Week: {dat.DayOfWeek}"); Console.WriteLine($"Week of year: {greg.GetWeekOfYear(dat, System.Globalization.CalendarWeekRule.FirstDay,DayOfWeek.Sunday)}"); // The example displays the following output: // Using the Thai Buddhist Era calendar // Date : 18/8/1395 // Day of Week: Sunday // Week of year: 34 // // Using the Gregorian calendar // Date : 18/08/0852 // Day of Week: Sunday // Week of year: 34 // </Snippet5> }
protected override void OnCreate(Bundle bundle) { // If these are not used the ToString for DateTime throws an exception in some cultures // For more information: https://forums.xamarin.com/discussion/42899/datetime-tostring-throws-argumentoutofrangeexception-in-thai-locale var c1 = new System.Globalization.ChineseLunisolarCalendar(); var c2 = new System.Globalization.GregorianCalendar(); var c3 = new System.Globalization.HebrewCalendar(); var c4 = new System.Globalization.HijriCalendar(); var c5 = new System.Globalization.JapaneseCalendar(); var c6 = new System.Globalization.JapaneseLunisolarCalendar(); var c7 = new System.Globalization.JulianCalendar(); var c8 = new System.Globalization.KoreanCalendar(); var c9 = new System.Globalization.KoreanLunisolarCalendar(); var c10 = new System.Globalization.PersianCalendar(); var c11 = new System.Globalization.TaiwanCalendar(); var c12 = new System.Globalization.TaiwanLunisolarCalendar(); var c13 = new System.Globalization.ThaiBuddhistCalendar(); var c14 = new System.Globalization.UmAlQuraCalendar(); StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder(); StrictMode.SetVmPolicy(builder.Build()); base.OnCreate(bundle); CrossCurrentActivity.Current.Init(this, bundle); PermissionsHelper.Activity = this; this.SetTheme(Resource.Style.Theme_Design_Light); //CachedImageRenderer.Init(false); FFImageLoading.Forms.Platform.CachedImageRenderer.Init(false); global::Xamarin.Forms.Forms.Init(this, bundle); LoadApplication(new App()); }
/// <summary> /// 菜单增加 /// </summary> /// <param name="foodInfoAddViewModel"></param> /// <returns></returns> public int Food_Add(FoodInfoAddViewModel foodInfoAddViewModel) { System.Globalization.GregorianCalendar gc = new System.Globalization.GregorianCalendar(); var t = DateTime.Now; var tt = Convert.ToInt32(t.DayOfWeek) == 0 ? 7 : Convert.ToInt32(t.DayOfWeek); DateTime tmpDay1 = t.AddDays(8 - tt); //var t1 = DateTime.Parse("2020-12-31"); int NextweekOfYear = gc.GetWeekOfYear(tmpDay1, System.Globalization.CalendarWeekRule.FirstDay, DayOfWeek.Monday); string year = ""; if (foodInfoAddViewModel.WeekNumber == "1" && NextweekOfYear == 1) { year = (DateTime.Now.Year + 1).ToString(); } else { year = DateTime.Now.Year.ToString(); } var food_Info = _IMapper.Map <FoodInfoAddViewModel, Food_Info>(foodInfoAddViewModel); food_Info.AddDate = DateTime.Now; food_Info.status = "0"; food_Info.isDelete = "0"; food_Info.Year = year; _IFoodInfoRepository.Add(food_Info); return(_IFoodInfoRepository.SaveChanges()); }
} //end method /// <summary> Returns a string value representing the input Gregorian Calendar object in /// an Hl7 Date Format. /// </summary> public static System.String toHl7DTFormat(System.Globalization.GregorianCalendar cal) { System.String val = ""; try { //set the input cal object so that it can report errors //on it's value //UPGRADE_ISSUE: Method 'java.util.Calendar.setLenient' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javautilCalendarsetLenient_boolean'" // UPGRADE_ISSUE: Commented out:cal.setLenient(false); //UPGRADE_TODO: Method 'java.util.Calendar.get' was converted to 'SupportClass.CalendarManager.Get' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilCalendarget_int'" int calYear = SupportClass.CalendarManager.manager.Get(cal, SupportClass.CalendarManager.YEAR); //UPGRADE_TODO: Method 'java.util.Calendar.get' was converted to 'SupportClass.CalendarManager.Get' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilCalendarget_int'" int calMonth = SupportClass.CalendarManager.manager.Get(cal, SupportClass.CalendarManager.MONTH) + 1; //UPGRADE_TODO: Method 'java.util.Calendar.get' was converted to 'SupportClass.CalendarManager.Get' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilCalendarget_int'" int calDay = SupportClass.CalendarManager.manager.Get(cal, SupportClass.CalendarManager.DAY_OF_MONTH); CommonDT dt = new CommonDT(); dt.setYearMonthDayPrecision(calYear, calMonth, calDay); val = dt.Value; } //end try catch (DataTypeException e) { throw e; } //end catch catch (System.Exception e) { throw new DataTypeException("An unexpected exception ocurred", e); } //end catch return(val); } //end method
private void InitBlock(TestCustomSearcherSort enclosingInstance) { this.enclosingInstance = enclosingInstance; System.DateTime temp_calendar; temp_calendar = new System.Globalization.GregorianCalendar().ToDateTime(1980, 1, 1, 0, 0, 0, 0); base_Renamed = temp_calendar; }
} //end method /// <summary> Returns a string value representing the input Gregorian Calendar object in /// an Hl7 Date Format. /// </summary> public static System.String toHl7DTFormat(System.Globalization.GregorianCalendar cal) { System.String val = ""; try { //set the input cal object so that it can report errors //on it's value int calYear = SupportClass.CalendarManager.manager.Get(cal, SupportClass.CalendarManager.YEAR); int calMonth = SupportClass.CalendarManager.manager.Get(cal, SupportClass.CalendarManager.MONTH) + 1; int calDay = SupportClass.CalendarManager.manager.Get(cal, SupportClass.CalendarManager.DAY_OF_MONTH); CommonDT dt = new CommonDT(); dt.setYearMonthDayPrecision(calYear, calMonth, calDay); val = dt.Value; } //end try catch (DataTypeException e) { throw e; } //end catch catch (System.Exception e) { throw new DataTypeException(e); } //end catch return(val); } //end method
//根据条件查询部门 private Expression <Func <Food_Info, bool> > SearchFoodWhere(FoodInfoSearchViewModel foodInfoSearchViewModel) { var predicate = WhereExtension.True <Food_Info>();//初始化where表达式 predicate = predicate.And(p => p.Price.ToString().Contains(foodInfoSearchViewModel.Price.ToString())); predicate = predicate.And(p => p.FoodName.Contains(foodInfoSearchViewModel.FoodName)); predicate = predicate.And(p => p.FoodType.Contains(foodInfoSearchViewModel.FoodType)); predicate = predicate.And(p => p.Remark.Contains(foodInfoSearchViewModel.Remark)); if (foodInfoSearchViewModel.flag == "0")//手机,默认查询当前周 { System.Globalization.GregorianCalendar gc = new System.Globalization.GregorianCalendar(); int weekOfYear = gc.GetWeekOfYear(DateTime.Now, System.Globalization.CalendarWeekRule.FirstDay, DayOfWeek.Monday); predicate = predicate.And(p => p.WeekNumber == weekOfYear.ToString()); //默认当前周 predicate = predicate.And(p => p.Year == DateTime.Now.Year.ToString()); //默认当前年 } else//PC查询任意周 { if (foodInfoSearchViewModel.flag != "") { predicate = predicate.And(p => p.WeekNumber == foodInfoSearchViewModel.flag); } predicate = predicate.And(p => p.Year.Contains(foodInfoSearchViewModel.Year)); } predicate = predicate.And(p => p.isDelete == "0"); return(predicate); }
private void btnBY_Click(object sender, EventArgs e) { System.Globalization.GregorianCalendar cGregorianCalendar = new System.Globalization.GregorianCalendar(); dateTimePickerS.Value = DateTime.Parse(System.DateTime.Now.Year.ToString() + "-" + System.DateTime.Now.Month.ToString() + "-1 00:00:00"); dateTimePickerE.Value = DateTime.Parse(System.DateTime.Now.Year.ToString() + "-" + System.DateTime.Now.Month.ToString() + "-" + cGregorianCalendar.GetDaysInMonth(System.DateTime.Now.Year, System.DateTime.Now.Month).ToString() + " 23:59:59"); }
static Version() { System.Globalization.GregorianCalendar temp_calendar; temp_calendar = new System.Globalization.GregorianCalendar(); SupportClass.CalendarManager.manager.Set(temp_calendar, 2004, 10, 10); lastBuild = temp_calendar; }
public static System.DateTime ToTimestamp(long value_Renamed) { System.Globalization.Calendar cal = new System.Globalization.GregorianCalendar(); var year = (int)(value_Renamed / 10000000000000L); value_Renamed %= 10000000000000L; var month = (int)(value_Renamed / 100000000000L); value_Renamed %= 100000000000L; var day = (int)(value_Renamed / 1000000000); value_Renamed %= 1000000000; var hour = (int)(value_Renamed / 10000000); value_Renamed %= 10000000; var min = (int)(value_Renamed / 100000); value_Renamed %= 100000; var sec = (int)(value_Renamed / 1000); var ms = (int)(value_Renamed % 1000); SupportClass.CalendarManager.manager.Set(cal, year, month - 1, day, hour, min, sec); SupportClass.CalendarManager.manager.Set(cal, SupportClass.CalendarManager.MILLISECOND, ms); return(SupportClass.CalendarManager.manager.GetDateTime(cal)); }
} //end method /// <summary> This method takes in integer values for the year and month and day /// and performs validations, it then sets the value in the object /// formatted as an HL7 date value with year&month&day precision (YYYYMMDD). /// </summary> public virtual void setYearMonthDayPrecision(int yr, int mnth, int dy) { try { System.Globalization.GregorianCalendar cal = new System.Globalization.GregorianCalendar(); SupportClass.CalendarManager.manager.Clear(cal); //UPGRADE_ISSUE: Method 'java.util.Calendar.setLenient' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javautilCalendarsetLenient_boolean'" // UPGRADE_ISSUE: Commented out:cal.setLenient(false); //ensure that the year field is four digits long if (System.Convert.ToString(yr).Length != 4) { System.String msg = "The input year value must be four digits long"; DataTypeException e = new DataTypeException(msg); throw e; } //validate the input month/day combination SupportClass.CalendarManager.manager.Set(cal, yr, (mnth - 1), dy); SupportClass.CalendarManager.manager.GetDateTime(cal); //for error detection year = yr; month = mnth; day = dy; value_Renamed = System.Convert.ToString(yr) + DataTypeUtil.preAppendZeroes(mnth, 2) + DataTypeUtil.preAppendZeroes(dy, 2); } catch (DataTypeException e) { throw e; } //end catch catch (System.Exception e) { throw new DataTypeException("An unexpected exception ocurred", e); } //end catch } //end method
public static int GetWeekOfYear(this DateTime data, DayOfWeek diaSemanaReferencia) { System.Globalization.GregorianCalendar gc = new System.Globalization.GregorianCalendar(); return gc.GetWeekOfYear(data, System.Globalization.CalendarWeekRule.FirstFullWeek, diaSemanaReferencia); }
// // This method is invoked when the application has loaded and is ready to run. In this // method you should instantiate the window, load the UI into it and then make the window // visible. // // You have 17 seconds to return from this method, or iOS will terminate your application. // public override bool FinishedLaunching(UIApplication app, NSDictionary options) { // If these are not used the ToString for DateTime throws an exception in some cultures // For more information: https://forums.xamarin.com/discussion/42899/datetime-tostring-throws-argumentoutofrangeexception-in-thai-locale var c1 = new System.Globalization.ChineseLunisolarCalendar(); var c2 = new System.Globalization.GregorianCalendar(); var c3 = new System.Globalization.HebrewCalendar(); var c4 = new System.Globalization.HijriCalendar(); var c5 = new System.Globalization.JapaneseCalendar(); var c6 = new System.Globalization.JapaneseLunisolarCalendar(); var c7 = new System.Globalization.JulianCalendar(); var c8 = new System.Globalization.KoreanCalendar(); var c9 = new System.Globalization.KoreanLunisolarCalendar(); var c10 = new System.Globalization.PersianCalendar(); var c11 = new System.Globalization.TaiwanCalendar(); var c12 = new System.Globalization.TaiwanLunisolarCalendar(); var c13 = new System.Globalization.ThaiBuddhistCalendar(); var c14 = new System.Globalization.UmAlQuraCalendar(); AnalyticsHelper.Initialize(Xamarin.Forms.Device.iOS); global::Xamarin.Forms.Forms.Init(); CachedImageRenderer.Init(); LoadApplication(new App()); UITextField.Appearance.TintColor = Xamarin.Forms.Color.FromHex("#2548D8").ToUIColor(); #if __TESTS__ Xamarin.Calabash.Start(); #endif return(base.FinishedLaunching(app, options)); }
public virtual void writeHeader() { db.Seek(0, System.IO.SeekOrigin.Begin); db.WriteByte((System.Byte) 0x03); System.Globalization.GregorianCalendar gc = new System.Globalization.GregorianCalendar(); //UPGRADE_TODO: Method 'java.util.Calendar.get' was converted to 'SupportClass.CalendarManager.Get' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073_javautilCalendarget_int"' int y = SupportClass.CalendarManager.manager.Get(gc, SupportClass.CalendarManager.YEAR) - 1900; //UPGRADE_TODO: Method 'java.util.Calendar.get' was converted to 'SupportClass.CalendarManager.Get' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073_javautilCalendarget_int"' int m = SupportClass.CalendarManager.manager.Get(gc, SupportClass.CalendarManager.MONTH) + 1; //UPGRADE_TODO: Method 'java.util.Calendar.get' was converted to 'SupportClass.CalendarManager.Get' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073_javautilCalendarget_int"' int d = SupportClass.CalendarManager.manager.Get(gc, SupportClass.CalendarManager.DAY_OF_MONTH); db.WriteByte((System.Byte)y); db.WriteByte((System.Byte)m); db.WriteByte((System.Byte)d); writeInt(numRecords); writeShort(hdrSize); writeShort(recordSize); for (int i = 0; i < 20; i++) { db.WriteByte((System.Byte) 0); } for (int i = 0; i < fields.Length; i++) { fields[i].writeHeader(); } db.WriteByte((System.Byte) 0x0d); }
private void ___GetLabelFormat(DateTime datetime, DateTime datetimeprev, out LabelFormat minor, out LabelFormat major) { minor = new LabelFormat() { Text = string.Empty, Font = this.Font, Color = HeaderFormat.Color, Margin = 3, TextAlign = ChartTextAlign.MiddleCenter }; major = new LabelFormat() { Text = string.Empty, Font = this.Font, Color = HeaderFormat.Color, Margin = 3, TextAlign = ChartTextAlign.MiddleLeft }; System.Globalization.GregorianCalendar calendar = new System.Globalization.GregorianCalendar(); switch (TimeResolution) { case TimeResolution.Week: minor.Text = calendar.GetWeekOfYear(datetime, System.Globalization.CalendarWeekRule.FirstFullWeek, DayOfWeek.Monday).ToString(); if (datetime.Month != datetimeprev.Month) { major.Text = datetime.ToString("MMMM"); } break; //case TimeResolution.Hour: // minor.Text = datetime.Hour.ToString(); // if (datetime.Day != datetimeprev.Day) major.Text = datetime.ToString("dd MMM yyyy"); // break; default: // case TimeResolution.Day: -- to implement other TimeResolutions, add to this function or listen to the the PaintTimeline event minor.Text = datetime.Day.ToString(); // datetime.ToString("dddd").Substring(0, 1).ToUpper(); if (datetime.Day == 15) { major.Text = datetime.ToString("MMM"); } break; } }
} //end method /// <summary> Returns a string value representing the input Gregorian Calendar object in /// an Hl7 Time Format. /// </summary> public static System.String toHl7TMFormat(System.Globalization.GregorianCalendar cal) { System.String val = ""; try { //set the input cal object so that it can report errors //on it's value //UPGRADE_ISSUE: Method 'java.util.Calendar.setLenient' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javautilCalendarsetLenient_boolean'" // UPGRADE_ISSUE: Commented out:cal.setLenient(false); //UPGRADE_TODO: Method 'java.util.Calendar.get' was converted to 'SupportClass.CalendarManager.Get' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilCalendarget_int'" int calHour = SupportClass.CalendarManager.manager.Get(cal, SupportClass.CalendarManager.HOUR_OF_DAY); //UPGRADE_TODO: Method 'java.util.Calendar.get' was converted to 'SupportClass.CalendarManager.Get' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilCalendarget_int'" int calMin = SupportClass.CalendarManager.manager.Get(cal, SupportClass.CalendarManager.MINUTE); //UPGRADE_TODO: Method 'java.util.Calendar.get' was converted to 'SupportClass.CalendarManager.Get' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilCalendarget_int'" int calSec = SupportClass.CalendarManager.manager.Get(cal, SupportClass.CalendarManager.SECOND); //UPGRADE_TODO: Method 'java.util.Calendar.get' was converted to 'SupportClass.CalendarManager.Get' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilCalendarget_int'" int calMilli = SupportClass.CalendarManager.manager.Get(cal, SupportClass.CalendarManager.MILLISECOND); //the inputs seconds and milli seconds should be combined into a float type float fractSec = calMilli / 1000F; float calSecFloat = calSec + fractSec; //UPGRADE_TODO: Method 'java.util.Calendar.get' was converted to 'SupportClass.CalendarManager.Get' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilCalendarget_int'" //UPGRADE_ISSUE: Field 'java.util.Calendar.ZONE_OFFSET' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javautilCalendarZONE_OFFSET_f'" //UPGRADE_ISSUE: Field 'java.util.Calendar.DST_OFFSET' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javautilCalendarDST_OFFSET_f'" int calOffset = SupportClass.CalendarManager.manager.Get(cal, SupportClass.CalendarManager.ZONE_OFFSET) + SupportClass.CalendarManager.manager.Get(cal, SupportClass.CalendarManager.DST_OFFSET); //Note the input's Offset value is in milliseconds, we must convert it to //a 4 digit integer in the HL7 Offset format. int offSetSignInt; if (calOffset < 0) { offSetSignInt = -1; } else { offSetSignInt = 1; } //get the absolute value of the gmtOffSet int absGmtOffSet = System.Math.Abs(calOffset); int gmtOffSetHours = absGmtOffSet / (3600 * 1000); int gmtOffSetMin = (absGmtOffSet / 60000) % (60); //reset calOffset calOffset = ((gmtOffSetHours * 100) + gmtOffSetMin) * offSetSignInt; //Create an object of the TS class and populate it with the above values //then return the HL7 string value from the object CommonTM tm = new CommonTM(); tm.setHourMinSecondPrecision(calHour, calMin, calSecFloat); tm.Offset = calOffset; val = tm.Value; } // end try catch (DataTypeException e) { throw e; } //end catch catch (System.Exception e) { throw new DataTypeException("An unexpected exception ocurred", e); } //end catch return(val); } //end method
/// <summary> This method takes in integer values for the year and month and day /// and performs validations, it then sets the value in the object /// formatted as an HL7 date value with year and month and day precision (YYYYMMDD). /// </summary> public virtual void setYearMonthDayPrecision(int yr, int mnth, int dy) { try { System.Globalization.GregorianCalendar cal = new System.Globalization.GregorianCalendar(); SupportClass.CalendarManager.manager.Clear(cal); //ensure that the year field is four digits long if (System.Convert.ToString(yr).Length != 4) { System.String msg = "The input year value must be four digits long"; DataTypeException e = new DataTypeException(msg); throw e; } //validate the input month/day combination SupportClass.CalendarManager.manager.Set(cal, yr, (mnth - 1), dy); SupportClass.CalendarManager.manager.GetDateTime(cal); //for error detection year = yr; month = mnth; day = dy; value_Renamed = System.Convert.ToString(yr) + DataTypeUtil.preAppendZeroes(mnth, 2) + DataTypeUtil.preAppendZeroes(dy, 2); } catch (DataTypeException e) { throw e; } catch (System.Exception e) { throw new DataTypeException("An unexpected exception ocurred", e); } }
private void SetDateNextRun() { if (Recurring.GetFrequency() < 1) { Recurring.SetFrequency(1); } int frequency = Recurring.GetFrequency(); dt = Recurring.GetDateNextRun(); System.Globalization.GregorianCalendar gcal = new System.Globalization.GregorianCalendar(); if (Recurring.GetFrequencyType().Equals("D")) { dt1 = dt.Value.AddDays(frequency); } else if (Recurring.GetFrequencyType().Equals("W")) { dt1 = dt.Value.AddDays(7 * frequency); } else if (Recurring.GetFrequencyType().Equals("M")) { dt1 = dt.Value.AddMonths(frequency); } else if (Recurring.GetFrequencyType().Equals("Q")) { dt1 = dt.Value.AddMonths(3 * frequency); } Recurring.SetDateNextRun(dt1); }
private void ConfigureDisplay() { DateTime startDate = DateTime.Today.AddMonths(-1); System.Globalization.GregorianCalendar cal = new System.Globalization.GregorianCalendar(); this.rdiStartDate.SelectedDate = new DateTime(startDate.Year, startDate.Month, 01); this.rdiEndDate.SelectedDate = new DateTime(startDate.Year, startDate.Month, cal.GetDaysInMonth(startDate.Year, startDate.Month)); }
/// <summary> Limit a date's resolution. For example, the date <code>1095767411000</code> /// (which represents 2004-09-21 13:50:11) will be changed to /// <code>1093989600000</code> (2004-09-01 00:00:00) when using /// <code>Resolution.MONTH</code>. /// /// </summary> /// <param name="resolution">The desired resolution of the date to be returned /// </param> /// <returns> the date with all values more precise than <code>resolution</code> /// set to 0 or 1, expressed as milliseconds since January 1, 1970, 00:00:00 GMT /// </returns> public static long Round(long time, Resolution resolution) { System.Globalization.Calendar cal = new System.Globalization.GregorianCalendar(); // {{Aroush}} do we care about 'cal' // protected in JDK's prior to 1.4 //cal.setTimeInMillis(time); System.DateTime dt = new System.DateTime(time); if (resolution == Resolution.YEAR) { dt = dt.AddMonths(1 - dt.Month); dt = dt.AddDays(1 - dt.Day); dt = dt.AddHours(0 - dt.Hour); dt = dt.AddMinutes(0 - dt.Minute); dt = dt.AddSeconds(0 - dt.Second); dt = dt.AddMilliseconds(0 - dt.Millisecond); } else if (resolution == Resolution.MONTH) { dt = dt.AddDays(1 - dt.Day); dt = dt.AddHours(0 - dt.Hour); dt = dt.AddMinutes(0 - dt.Minute); dt = dt.AddSeconds(0 - dt.Second); dt = dt.AddMilliseconds(0 - dt.Millisecond); } else if (resolution == Resolution.DAY) { dt = dt.AddHours(0 - dt.Hour); dt = dt.AddMinutes(0 - dt.Minute); dt = dt.AddSeconds(0 - dt.Second); dt = dt.AddMilliseconds(0 - dt.Millisecond); } else if (resolution == Resolution.HOUR) { dt = dt.AddMinutes(0 - dt.Minute); dt = dt.AddSeconds(0 - dt.Second); dt = dt.AddMilliseconds(0 - dt.Millisecond); } else if (resolution == Resolution.MINUTE) { dt = dt.AddSeconds(0 - dt.Second); dt = dt.AddMilliseconds(0 - dt.Millisecond); } else if (resolution == Resolution.SECOND) { dt = dt.AddMilliseconds(0 - dt.Millisecond); } else if (resolution == Resolution.MILLISECOND) { // don't cut off anything } else { throw new System.ArgumentException("unknown resolution " + resolution); } return(dt.Ticks); }
//UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'" public static DateFields getFields(ref System.DateTime d, System.String timezone) { System.Globalization.Calendar cd = new System.Globalization.GregorianCalendar(); DateFields fields = new DateFields(); return(fields); }
/// <summary> /// 今年第几周,年的第一周从年的第一天开始,到指定周的下一个首日结束。 /// </summary> /// <param name="datetime"></param> /// <param name="dayOfWeek"></param> /// <returns></returns> public static int GetWeekOfYearFirstDay(this DateTime datetime, DayOfWeek dayOfWeek) { int weekYear = new System.Globalization.GregorianCalendar() .GetWeekOfYear(datetime, System.Globalization.CalendarWeekRule.FirstDay, dayOfWeek); return(weekYear); }
/// <summary> /// 获取当前时间是当年的第几周 >=1 /// </summary> /// <param name="dt"></param> /// <returns></returns> public static int WeekInYear(this DateTime dt) { //创建公历日历对象 var gc = new System.Globalization.GregorianCalendar(); //获取指定日期是周数 CalendarWeekRule指定 第一周开始于该年的第一天,DayOfWeek指定每周第一天是星期几 return(gc.GetWeekOfYear(dt, System.Globalization.CalendarWeekRule.FirstDay, DayOfWeek.Monday)); //return (int)Math.Ceiling(dt.DayOfYear / (decimal)7); }
} //end method /// <summary> Returns a string value representing the input Gregorian Calendar object in /// an Hl7 TimeStamp Format. /// </summary> public static System.String toHl7TSFormat(System.Globalization.GregorianCalendar cal) { System.String val = ""; try { //set the input cal object so that it can report errors //on it's value int calYear = SupportClass.CalendarManager.manager.Get(cal, SupportClass.CalendarManager.YEAR); int calMonth = SupportClass.CalendarManager.manager.Get(cal, SupportClass.CalendarManager.MONTH) + 1; int calDay = SupportClass.CalendarManager.manager.Get(cal, SupportClass.CalendarManager.DAY_OF_MONTH); int calHour = SupportClass.CalendarManager.manager.Get(cal, SupportClass.CalendarManager.HOUR_OF_DAY); int calMin = SupportClass.CalendarManager.manager.Get(cal, SupportClass.CalendarManager.MINUTE); int calSec = SupportClass.CalendarManager.manager.Get(cal, SupportClass.CalendarManager.SECOND); int calMilli = SupportClass.CalendarManager.manager.Get(cal, SupportClass.CalendarManager.MILLISECOND); //the inputs seconds and milli seconds should be combined into a float type float fractSec = calMilli / 1000F; float calSecFloat = calSec + fractSec; TimeSpan utcSpan = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now); int calOffset = utcSpan.Hours * 100 + utcSpan.Minutes; //Note the input's Offset value is in milliseconds, we must convert it to //a 4 digit integer in the HL7 Offset format. int offSetSignInt; if (calOffset < 0) { offSetSignInt = -1; } else { offSetSignInt = 1; } //get the absolute value of the gmtOffSet int absGmtOffSet = System.Math.Abs(calOffset); int gmtOffSetHours = absGmtOffSet / (3600 * 1000); int gmtOffSetMin = (absGmtOffSet / 60000) % (60); //reset calOffset calOffset = ((gmtOffSetHours * 100) + gmtOffSetMin) * offSetSignInt; //Create an object of the TS class and populate it with the above values //then return the HL7 string value from the object CommonTS ts = new CommonTS(); ts.setDateSecondPrecision(calYear, calMonth, calDay, calHour, calMin, calSecFloat); ts.Offset = calOffset; val = ts.Value; } // end try catch (DataTypeException e) { throw e; } //end catch catch (System.Exception e) { throw new DataTypeException(e); } //end catch return(val); } //end method
/// <summary> /// Gibt die Kalenderwoche zurück. /// </summary> public static int GetWeekOfYear(this DateTime date) { // das this Schlüsselwort informiert den Compiler, dass // GetWeekOfYear den DatenTyp DateTime erweitern soll. var cal = new System.Globalization.GregorianCalendar(); return(cal.GetWeekOfYear(date, System.Globalization.CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday)); }
internal static long Time(int year, int month, int day) { // {{Aroush System.DateTime tempDate = System.DateTime.Now; System.Globalization.GregorianCalendar calendar = new System.Globalization.GregorianCalendar(); //tempDate.Year = year; //tempDate.Month = month; //tempDate.Day = day; return tempDate.Ticks; // Aroush}} }
/// <summary> /// 今天是当年的第几周 /// </summary> /// <returns></returns> static int TodayOfWeekInYear() { //获取当前周 DateTime now = DateTime.Now; // System.Globalization in mscorlib.dll System.Globalization.GregorianCalendar calend = new System.Globalization.GregorianCalendar();//日历函数 int week = calend.GetWeekOfYear(now, System.Globalization.CalendarWeekRule.FirstDay, DayOfWeek.Monday); return(week); }
internal static long Time(int year, int month, int day) { // {{Aroush System.DateTime tempDate = System.DateTime.Now; System.Globalization.GregorianCalendar calendar = new System.Globalization.GregorianCalendar(); //tempDate.Year = year; //tempDate.Month = month; //tempDate.Day = day; return(tempDate.Ticks); // Aroush}} }
static void Main(string[] args) { var greg = new System.Globalization.GregorianCalendar(); var dat = new DateTime(2000, 3, 18, greg); Console.WriteLine($"Day of Week: {dat.DayOfWeek}"); string s = DateTime.Now.AddDays(7).ToShortDateString(); Console.WriteLine(s); }
private void ConfigureDisplay() { if (!string.IsNullOrEmpty(Request.QueryString[c_customerID_QS])) { int id = int.Parse(Request.QueryString[c_customerID_QS]); Facade.IOrganisation facOrganisation = new Facade.Organisation(); organisation = facOrganisation.GetForIdentityId(id); RadComboBoxItem listItem = new RadComboBoxItem(organisation.OrganisationDisplayName, organisation.IdentityId.ToString()); cboClient.Items.Add(listItem); cboClient.SelectedValue = organisation.IdentityId.ToString(); hidSelectedClientsValues.Value = organisation.IdentityId.ToString() + ","; hidSelectedClientsText.Value = organisation.OrganisationDisplayName + ","; } DateTime startDate = DateTime.Today.AddMonths(-1); System.Globalization.GregorianCalendar cal = new System.Globalization.GregorianCalendar(); if (!string.IsNullOrEmpty(Request.QueryString[c_startDate_QS])) { this.rdiStartDate.SelectedDate = DateTime.Parse(Request.QueryString[c_startDate_QS], null, System.Globalization.DateTimeStyles.RoundtripKind); } else { this.rdiStartDate.SelectedDate = new DateTime(startDate.Year, startDate.Month, 01); } if (!string.IsNullOrEmpty(Request.QueryString[c_endDate_QS])) { this.rdiEndDate.SelectedDate = DateTime.Parse(Request.QueryString[c_endDate_QS], null, System.Globalization.DateTimeStyles.RoundtripKind); } else { this.rdiEndDate.SelectedDate = new DateTime(startDate.Year, startDate.Month, cal.GetDaysInMonth(startDate.Year, startDate.Month)); } lblMode.Text = IsClient ? "Client" : "Sub-Contractor"; if (!string.IsNullOrEmpty(cboClient.SelectedValue) && !string.IsNullOrEmpty(Request.QueryString[c_startDate_QS]) && !string.IsNullOrEmpty(Request.QueryString[c_endDate_QS])) { Refresh(); } this.rfvCboClient.Enabled = !IsClient; seSelectedClients.Visible = lblSelectedClients.Visible = btnRemoveSelectedClients.Visible = btnAddCboClient.Visible = IsClient; }
/// <summary> Converts a millisecond time to a string suitable for indexing. /// /// </summary> /// <param name="time">the date expressed as milliseconds since January 1, 1970, 00:00:00 GMT /// </param> /// <param name="resolution">the desired resolution, see /// {@link #Round(long, DateTools.Resolution)} /// </param> /// <returns> a string in format <code>yyyyMMddHHmmssSSS</code> or shorter, /// depeding on <code>resolution</code> /// </returns> public static System.String TimeToString(long time, Resolution resolution) { System.Globalization.Calendar cal = new System.Globalization.GregorianCalendar(); // {{Aroush}} do we care about 'cal' //protected in JDK's prior to 1.4 //cal.setTimeInMillis(round(time, resolution)); System.DateTime dt = new System.DateTime(Round(time, resolution)); System.String t = ""; if (resolution == Resolution.YEAR) { t = dt.ToString("yyyy"); } else if (resolution == Resolution.MONTH) { t = dt.ToString("yyyyMM"); } else if (resolution == Resolution.DAY) { t = dt.ToString("yyyyMMdd"); } else if (resolution == Resolution.HOUR) { t = dt.ToString("yyyyMMddHH"); } else if (resolution == Resolution.MINUTE) { t = dt.ToString("yyyyMMddHHmm"); } else if (resolution == Resolution.SECOND) { t = dt.ToString("yyyyMMddHHmmss"); } else if (resolution == Resolution.MILLISECOND) { t = dt.ToString("yyyyMMddHHmmssfff"); } else { throw new System.ArgumentException("unknown resolution " + resolution); } return t; }
public void NpgsqlDateConstructors() { NpgsqlDate date; DateTime dateTime; System.Globalization.Calendar calendar = new System.Globalization.GregorianCalendar(); date = new NpgsqlDate(); Assert.AreEqual(1, date.Day); Assert.AreEqual(DayOfWeek.Monday, date.DayOfWeek); Assert.AreEqual(1, date.DayOfYear); Assert.AreEqual(false, date.IsLeapYear); Assert.AreEqual(1, date.Month); Assert.AreEqual(1, date.Year); dateTime = new DateTime(2009, 5, 31); date = new NpgsqlDate(dateTime); Assert.AreEqual(dateTime.Day, date.Day); Assert.AreEqual(dateTime.DayOfWeek, date.DayOfWeek); Assert.AreEqual(dateTime.DayOfYear, date.DayOfYear); Assert.AreEqual(calendar.IsLeapYear(2009), date.IsLeapYear); Assert.AreEqual(dateTime.Month, date.Month); Assert.AreEqual(dateTime.Year, date.Year); //Console.WriteLine(new DateTime(2009, 5, 31).Ticks); //Console.WriteLine((new DateTime(2009, 5, 31) - new DateTime(1, 1, 1)).TotalDays); // 2009-5-31 dateTime = new DateTime(633793248000000000); // ticks since 1 Jan 1 date = new NpgsqlDate(733557); // days since 1 Jan 1 Assert.AreEqual(dateTime.Day, date.Day); Assert.AreEqual(dateTime.DayOfWeek, date.DayOfWeek); Assert.AreEqual(dateTime.DayOfYear, date.DayOfYear); Assert.AreEqual(calendar.IsLeapYear(2009), date.IsLeapYear); Assert.AreEqual(dateTime.Month, date.Month); Assert.AreEqual(dateTime.Year, date.Year); // copy previous value. should get same result date = new NpgsqlDate(date); Assert.AreEqual(dateTime.Day, date.Day); Assert.AreEqual(dateTime.DayOfWeek, date.DayOfWeek); Assert.AreEqual(dateTime.DayOfYear, date.DayOfYear); Assert.AreEqual(calendar.IsLeapYear(2009), date.IsLeapYear); Assert.AreEqual(dateTime.Month, date.Month); Assert.AreEqual(dateTime.Year, date.Year); }
/// <summary> Limit a date's resolution. For example, the date <code>1095767411000</code> /// (which represents 2004-09-21 13:50:11) will be changed to /// <code>1093989600000</code> (2004-09-01 00:00:00) when using /// <code>Resolution.MONTH</code>. /// /// </summary> /// <param name="resolution">The desired resolution of the date to be returned /// </param> /// <returns> the date with all values more precise than <code>resolution</code> /// set to 0 or 1, expressed as milliseconds since January 1, 1970, 00:00:00 GMT /// </returns> public static long Round(long time, Resolution resolution) { System.Globalization.Calendar cal = new System.Globalization.GregorianCalendar(); // {{Aroush}} do we care about 'cal' // protected in JDK's prior to 1.4 //cal.setTimeInMillis(time); System.DateTime dt = new System.DateTime(time); if (resolution == Resolution.YEAR) { dt = dt.AddMonths(1 - dt.Month); dt = dt.AddDays(1 - dt.Day); dt = dt.AddHours(0 - dt.Hour); dt = dt.AddMinutes(0 - dt.Minute); dt = dt.AddSeconds(0 - dt.Second); dt = dt.AddMilliseconds(0 - dt.Millisecond); } else if (resolution == Resolution.MONTH) { dt = dt.AddDays(1 - dt.Day); dt = dt.AddHours(0 - dt.Hour); dt = dt.AddMinutes(0 - dt.Minute); dt = dt.AddSeconds(0 - dt.Second); dt = dt.AddMilliseconds(0 - dt.Millisecond); } else if (resolution == Resolution.DAY) { dt = dt.AddHours(0 - dt.Hour); dt = dt.AddMinutes(0 - dt.Minute); dt = dt.AddSeconds(0 - dt.Second); dt = dt.AddMilliseconds(0 - dt.Millisecond); } else if (resolution == Resolution.HOUR) { dt = dt.AddMinutes(0 - dt.Minute); dt = dt.AddSeconds(0 - dt.Second); dt = dt.AddMilliseconds(0 - dt.Millisecond); } else if (resolution == Resolution.MINUTE) { dt = dt.AddSeconds(0 - dt.Second); dt = dt.AddMilliseconds(0 - dt.Millisecond); } else if (resolution == Resolution.SECOND) { dt = dt.AddMilliseconds(0 - dt.Millisecond); } else if (resolution == Resolution.MILLISECOND) { // don't cut off anything } else { throw new System.ArgumentException("unknown resolution " + resolution); } return dt.Ticks; }
/// <summary> Should be called only through static method of same name.</summary> private void writeStatus(System.String message, bool verbose) { lock (this) { bool output = true; if (this.detail == NuGenStatus.NONE || (verbose && this.detail != NuGenStatus.VERBOSE)) output = false; System.Globalization.GregorianCalendar now = new System.Globalization.GregorianCalendar(); SupportClass.CalendarManager.manager.SetDateTime(now, System.DateTime.Now); System.Text.StringBuilder mess = new System.Text.StringBuilder(); mess.Append(SupportClass.CalendarManager.manager.Get(now, SupportClass.CalendarManager.DAY_OF_MONTH)); mess.Append("/"); mess.Append(SupportClass.CalendarManager.manager.Get(now, SupportClass.CalendarManager.MONTH + 1)); mess.Append("/"); mess.Append(SupportClass.CalendarManager.manager.Get(now, SupportClass.CalendarManager.YEAR)); mess.Append(" "); mess.Append(SupportClass.CalendarManager.manager.Get(now, SupportClass.CalendarManager.HOUR_OF_DAY)); mess.Append(":"); mess.Append(SupportClass.CalendarManager.manager.Get(now, SupportClass.CalendarManager.MINUTE)); mess.Append(":"); mess.Append(SupportClass.CalendarManager.manager.Get(now, SupportClass.CalendarManager.SECOND)); mess.Append("."); mess.Append(SupportClass.CalendarManager.manager.Get(now, SupportClass.CalendarManager.MILLISECOND)); mess.Append(" "); mess.Append(message); if (output) { if (this.dest == NuGenStatus.STANDARD_OUT) { System.Console.Out.WriteLine(mess.ToString()); } else { try { this.fileOut.Write(mess.ToString()); this.fileOut.Write("\r\n"); this.fileOut.Flush(); } catch (System.IO.IOException e) { System.Console.Error.WriteLine("Error writing status message to file: " + e.Message); System.Console.Out.WriteLine(mess.ToString()); } } } } }
public static System.DateTime ToTimestamp(long value_Renamed) { System.Globalization.Calendar cal = new System.Globalization.GregorianCalendar(); var year = (int) (value_Renamed / 10000000000000L); value_Renamed %= 10000000000000L; var month = (int) (value_Renamed / 100000000000L); value_Renamed %= 100000000000L; var day = (int) (value_Renamed / 1000000000); value_Renamed %= 1000000000; var hour = (int) (value_Renamed / 10000000); value_Renamed %= 10000000; var min = (int) (value_Renamed / 100000); value_Renamed %= 100000; var sec = (int) (value_Renamed / 1000); var ms = (int) (value_Renamed % 1000); SupportClass.CalendarManager.manager.Set(cal, year, month - 1, day, hour, min, sec); SupportClass.CalendarManager.manager.Set(cal, SupportClass.CalendarManager.MILLISECOND, ms); return SupportClass.CalendarManager.manager.GetDateTime(cal); }
public static System.DateTime Date(int year, int month, int day) { System.Globalization.Calendar cal = new System.Globalization.GregorianCalendar(); SupportClass.CalendarManager.manager.Set(cal, year - 1900, month - 1, day); return SupportClass.CalendarManager.manager.GetDateTime(cal); }
/// <summary> This method takes in integer values for the year and month and performs validations, /// it then sets the value field formatted as an HL7 date /// value with year and month precision (YYYYMM). /// Note: The first month = 1 = January. /// </summary> public virtual void setYearMonthPrecision(int yr, int mnth) { try { System.Globalization.GregorianCalendar cal = new System.Globalization.GregorianCalendar(); SupportClass.CalendarManager.manager.Clear(cal); //ensure that the year field is four digits long if (System.Convert.ToString(yr).Length != 4) { System.String msg = "The input year value must be four digits long"; DataTypeException e = new DataTypeException(msg); throw e; } //validate the input month //GregorianCalendar cal = new GregorianCalendar(yr,(mnth-1),1); SupportClass.CalendarManager.manager.Set(cal, yr, (mnth - 1), 1); SupportClass.CalendarManager.manager.GetDateTime(cal); //for error detection year = yr; month = mnth; day = 0; value_Renamed = System.Convert.ToString(yr) + DataTypeUtil.preAppendZeroes(mnth, 2); } catch (DataTypeException e) { throw e; } catch (System.Exception e) { throw new DataTypeException("An unexpected exception ocurred", e); } }
/// <summary> This method takes in integer values for the year and month and performs validations, /// it then sets the value field formatted as an HL7 date /// value with year&month precision (YYYYMM). /// Note: The first month = 1 = January. /// </summary> public virtual void setYearMonthPrecision(int yr, int mnth) { try { System.Globalization.GregorianCalendar cal = new System.Globalization.GregorianCalendar(); SupportClass.CalendarManager.manager.Clear(cal); //UPGRADE_ISSUE: Method 'java.util.Calendar.setLenient' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javautilCalendarsetLenient_boolean'" // UPGRADE_ISSUE: Commented out:cal.setLenient(false); //ensure that the year field is four digits long if (System.Convert.ToString(yr).Length != 4) { System.String msg = "The input year value must be four digits long"; DataTypeException e = new DataTypeException(msg); throw e; } //validate the input month //GregorianCalendar cal = new GregorianCalendar(yr,(mnth-1),1); SupportClass.CalendarManager.manager.Set(cal, yr, (mnth - 1), 1); SupportClass.CalendarManager.manager.GetDateTime(cal); //for error detection year = yr; month = mnth; day = 0; value_Renamed = System.Convert.ToString(yr) + DataTypeUtil.preAppendZeroes(mnth, 2); } catch (DataTypeException e) { throw e; } //end catch catch (System.Exception e) { throw new DataTypeException("An unexpected exception ocurred", e); } //end catch }
private static void AddDateDoc(System.String content, int year, int month, int day, int hour, int minute, int second, IndexWriter iw) { Document d = new Document(); d.Add(new Field("f", content, Field.Store.YES, Field.Index.ANALYZED)); System.Globalization.Calendar cal = new System.Globalization.GregorianCalendar(); System.DateTime tempAux = new System.DateTime(year, month, day, hour, minute, second, cal); d.Add(new Field("date", DateField.DateToString(tempAux), Field.Store.YES, Field.Index.NOT_ANALYZED)); iw.AddDocument(d); }
private System.String GetLocalizedDate(int year, int month, int day, bool extendLastDate) { System.Globalization.Calendar calendar = new System.Globalization.GregorianCalendar(); System.DateTime temp = new System.DateTime(year, month, day, calendar); if (extendLastDate) { temp = temp.AddHours(23); temp = temp.AddMinutes(59); temp = temp.AddSeconds(59); temp = temp.AddMilliseconds(999); } return temp.ToShortDateString(); }
public virtual void TestDateRange() { System.String startDate = GetLocalizedDate(2002, 1, 1, false); System.String endDate = GetLocalizedDate(2002, 1, 4, false); System.Globalization.Calendar calendar = new System.Globalization.GregorianCalendar(); System.DateTime endDateExpected = new System.DateTime(2002, 1, 4, 23, 59, 59, 999, calendar); System.String defaultField = "default"; System.String monthField = "month"; System.String hourField = "hour"; QueryParser qp = new QueryParser("field", new SimpleAnalyzer()); // Don't set any date resolution and verify if DateField is used System.DateTime tempAux = endDateExpected; AssertDateRangeQueryEquals(qp, defaultField, startDate, endDate, tempAux, null); // set a field specific date resolution qp.SetDateResolution(monthField, DateTools.Resolution.MONTH); // DateField should still be used for defaultField System.DateTime tempAux2 = endDateExpected; AssertDateRangeQueryEquals(qp, defaultField, startDate, endDate, tempAux2, null); // set default date resolution to MILLISECOND qp.SetDateResolution(DateTools.Resolution.MILLISECOND); // set second field specific date resolution qp.SetDateResolution(hourField, DateTools.Resolution.HOUR); // for this field no field specific date resolution has been set, // so verify if the default resolution is used System.DateTime tempAux3 = endDateExpected; AssertDateRangeQueryEquals(qp, defaultField, startDate, endDate, tempAux3, DateTools.Resolution.MILLISECOND); // verify if field specific date resolutions are used for these two fields System.DateTime tempAux4 = endDateExpected; AssertDateRangeQueryEquals(qp, monthField, startDate, endDate, tempAux4, DateTools.Resolution.MONTH); System.DateTime tempAux5 = endDateExpected; AssertDateRangeQueryEquals(qp, hourField, startDate, endDate, tempAux5, DateTools.Resolution.HOUR); }
public virtual void TestLegacyDateRange() { System.String startDate = GetLocalizedDate(2002, 1, 1, false); System.String endDate = GetLocalizedDate(2002, 1, 4, false); System.Globalization.Calendar endDateExpected = new System.Globalization.GregorianCalendar(); System.DateTime tempAux = new System.DateTime(2002, 1, 4, 23, 59, 59, 999, endDateExpected); AssertQueryEquals("[ " + EscapeDateString(startDate) + " TO " + EscapeDateString(endDate) + "]", null, "[" + GetLegacyDate(startDate) + " TO " + DateField.DateToString(tempAux) + "]"); AssertQueryEquals("{ " + EscapeDateString(startDate) + " " + EscapeDateString(endDate) + " }", null, "{" + GetLegacyDate(startDate) + " TO " + GetLegacyDate(endDate) + "}"); }
/// <summary> Populates certain required fields in a response message header, using /// information from the corresponding inbound message. The current time is /// used for the message time field, and <code>MessageIDGenerator</code> is /// used to create a unique message ID. Version and message type fields are /// not populated. /// </summary> public static void fillResponseHeader(Segment inbound, Segment outbound) { if (!inbound.getName().Equals("MSH") || !outbound.getName().Equals("MSH")) throw new NuGenHL7Exception("Need MSH segments. Got " + inbound.getName() + " and " + outbound.getName()); //get MSH data from incoming message ... System.String encChars = Terser.get_Renamed(inbound, 2, 0, 1, 1); System.String fieldSep = Terser.get_Renamed(inbound, 1, 0, 1, 1); System.String procID = Terser.get_Renamed(inbound, 11, 0, 1, 1); //populate outbound MSH using data from inbound message ... Terser.set_Renamed(outbound, 2, 0, 1, 1, encChars); Terser.set_Renamed(outbound, 1, 0, 1, 1, fieldSep); System.Globalization.GregorianCalendar now = new System.Globalization.GregorianCalendar(); SupportClass.CalendarManager.manager.SetDateTime(now, System.DateTime.Now); Terser.set_Renamed(outbound, 7, 0, 1, 1, CommonTS.toHl7TSFormat(now)); Terser.set_Renamed(outbound, 10, 0, 1, 1, MessageIDGenerator.Instance.NewID); Terser.set_Renamed(outbound, 11, 0, 1, 1, procID); }
/// <exception cref="ParseException">throw in overridden method to disallow /// </exception> protected internal virtual Query GetRangeQuery(System.String field, System.String part1, System.String part2, bool inclusive) { if (lowercaseExpandedTerms) { part1 = part1.ToLower(); part2 = part2.ToLower(); } try { System.DateTime d1; System.DateTime d2; try { d1 = System.DateTime.Parse(part1, locale); } catch (System.Exception) { d1 = System.DateTime.Parse(part1); } try { d2 = System.DateTime.Parse(part2, locale); } catch (System.Exception) { d2 = System.DateTime.Parse(part2); } if (inclusive) { // The user can only specify the date, not the time, so make sure // the time is set to the latest possible time of that date to really // include all documents: System.Globalization.Calendar cal = new System.Globalization.GregorianCalendar(); System.DateTime tempDate = d2; d2 = d2.AddHours(23 - tempDate.Hour); d2 = d2.AddMinutes(59 - tempDate.Minute); d2 = d2.AddSeconds(59 - tempDate.Second); d2 = d2.AddMilliseconds(999 - tempDate.Millisecond); } DateTools.Resolution resolution = GetDateResolution(field); if (resolution == null) { // no default or field specific date resolution has been set, // use deprecated DateField to maintain compatibility with // pre-1.9 Lucene versions. part1 = DateField.DateToString(d1); part2 = DateField.DateToString(d2); } else { part1 = DateTools.DateToString(d1, resolution); part2 = DateTools.DateToString(d2, resolution); } } catch (System.Exception) { } return NewRangeQuery(field, part1, part2, inclusive); }
/// <exception cref="ParseException">throw in overridden method to disallow /// </exception> protected internal virtual Query GetRangeQuery(System.String field, System.String part1, System.String part2, bool inclusive) { if (lowercaseExpandedTerms) { part1 = part1.ToLower(); part2 = part2.ToLower(); } try { System.DateTime d1; System.DateTime d2; try { d1 = System.DateTime.Parse(part1, locale); } catch (System.Exception) { d1 = System.DateTime.Parse(part1); } try { d2 = System.DateTime.Parse(part2, locale); } catch (System.Exception) { d2 = System.DateTime.Parse(part2); } if (inclusive) { // The user can only specify the date, not the time, so make sure // the time is set to the latest possible time of that date to really // include all documents: System.Globalization.Calendar cal = new System.Globalization.GregorianCalendar(); System.DateTime tempDate = d2; d2 = d2.AddHours(23 - tempDate.Hour); d2 = d2.AddMinutes(59 - tempDate.Minute); d2 = d2.AddSeconds(59 - tempDate.Second); d2 = d2.AddMilliseconds(999 - tempDate.Millisecond); } part1 = DateField.DateToString(d1); part2 = DateField.DateToString(d2); } catch (System.Exception) { } return new RangeQuery(new Term(field, part1), new Term(field, part2), inclusive); }
public void SpecialDates() { NpgsqlDate date; DateTime dateTime; System.Globalization.Calendar calendar = new System.Globalization.GregorianCalendar(); // a date after a leap year. dateTime = new DateTime(2008, 5, 31); date = new NpgsqlDate(dateTime); Assert.AreEqual(dateTime.Day, date.Day); Assert.AreEqual(dateTime.DayOfWeek, date.DayOfWeek); Assert.AreEqual(dateTime.DayOfYear, date.DayOfYear); Assert.AreEqual(calendar.IsLeapYear(2008), date.IsLeapYear); Assert.AreEqual(dateTime.Month, date.Month); Assert.AreEqual(dateTime.Year, date.Year); // A date that is a leap year day. dateTime = new DateTime(2000, 2, 29); date = new NpgsqlDate(2000, 2, 29); Assert.AreEqual(dateTime.Day, date.Day); Assert.AreEqual(dateTime.DayOfWeek, date.DayOfWeek); Assert.AreEqual(dateTime.DayOfYear, date.DayOfYear); Assert.AreEqual(calendar.IsLeapYear(2000), date.IsLeapYear); Assert.AreEqual(dateTime.Month, date.Month); Assert.AreEqual(dateTime.Year, date.Year); // A date that is not in a leap year. dateTime = new DateTime(1900, 3, 1); date = new NpgsqlDate(1900, 3, 1); Assert.AreEqual(dateTime.Day, date.Day); Assert.AreEqual(dateTime.DayOfWeek, date.DayOfWeek); Assert.AreEqual(dateTime.DayOfYear, date.DayOfYear); Assert.AreEqual(calendar.IsLeapYear(1900), date.IsLeapYear); Assert.AreEqual(dateTime.Month, date.Month); Assert.AreEqual(dateTime.Year, date.Year); // a date after a leap year. date = new NpgsqlDate(-1, 12, 31); Assert.AreEqual(31, date.Day); Assert.AreEqual(DayOfWeek.Sunday, date.DayOfWeek); Assert.AreEqual(366, date.DayOfYear); Assert.AreEqual(true, date.IsLeapYear); Assert.AreEqual(12, date.Month); Assert.AreEqual(-1, date.Year); }
/// <summary> Converts a millisecond time to a string suitable for indexing. /// /// </summary> /// <param name="time">the date expressed as milliseconds since January 1, 1970, 00:00:00 GMT /// </param> /// <param name="resolution">the desired resolution, see /// {@link #Round(long, DateTools.Resolution)} /// </param> /// <returns> a string in format <code>yyyyMMddHHmmssSSS</code> or shorter, /// depeding on <code>resolution</code>; using UTC as timezone /// </returns> public static System.String TimeToString(long time, Resolution resolution) { System.Globalization.Calendar cal = new System.Globalization.GregorianCalendar(); //protected in JDK's prior to 1.4 //cal.setTimeInMillis(round(time, resolution)); System.DateTime dt = new System.DateTime(Round(time, resolution)); System.String result; if (resolution == Resolution.YEAR) { lock (YEAR_FORMAT) { result = dt.ToString(YEAR_FORMAT); } } else if (resolution == Resolution.MONTH) { lock (MONTH_FORMAT) { result = dt.ToString(MONTH_FORMAT); } } else if (resolution == Resolution.DAY) { lock (DAY_FORMAT) { result = dt.ToString(DAY_FORMAT); } } else if (resolution == Resolution.HOUR) { lock (HOUR_FORMAT) { result = dt.ToString(HOUR_FORMAT); } } else if (resolution == Resolution.MINUTE) { lock (MINUTE_FORMAT) { result = dt.ToString(MINUTE_FORMAT); } } else if (resolution == Resolution.SECOND) { lock (SECOND_FORMAT) { result = dt.ToString(SECOND_FORMAT); } } else if (resolution == Resolution.MILLISECOND) { lock (MILLISECOND_FORMAT) { result = dt.ToString(MILLISECOND_FORMAT); } } else { throw new System.ArgumentException("unknown resolution " + resolution); } return result; }
public static int DateToInt(ref System.DateTime date) { System.Globalization.Calendar cal = new System.Globalization.GregorianCalendar(); SupportClass.CalendarManager.manager.SetDateTime(cal, date); return SupportClass.CalendarManager.manager.Get(cal, SupportClass.CalendarManager.YEAR) * 10000 + (SupportClass.CalendarManager.manager.Get(cal, SupportClass.CalendarManager.MONTH) + 1) * 100 + SupportClass.CalendarManager.manager.Get(cal, SupportClass.CalendarManager.DATE); }
private MamdaOptionExpirationDateSet filterExpirations(MamdaOptionExpirationDateSet initialSet) { if (mExpirationDays > 0) { // Find the subset of expirations between now and some // number of days into the future. System.Globalization.Calendar c = new System.Globalization.GregorianCalendar(System.Globalization.GregorianCalendarTypes.USEnglish); DateTime futureDate = c.AddDays(DateTime.Today, mExpirationDays); return initialSet.getExpirationsBefore(futureDate); } else if (mNumExpirations > 0) { // Explicit number of expiration dates. return initialSet.getExpirations(mNumExpirations); } else { // All expiration months. We *copy* the initial set // because we may reduce the set to a particular range of // strike prices. return new MamdaOptionExpirationDateSet(initialSet); } }
internal static long Time(int year, int month, int day) { // {{Aroush //// System.Globalization.GregorianCalendar calendar = new System.Globalization.GregorianCalendar(); //// return SupportClass.CalendarManager.manager.GetDateTime(calendar).Ticks; System.DateTime tempDate = System.DateTime.Now; System.Globalization.GregorianCalendar calendar = new System.Globalization.GregorianCalendar(); //tempDate.Year = year; //tempDate.Month = month; //tempDate.Day = day; return tempDate.Ticks; // Aroush}} }
public static int GetWeek(DateTime dtm) { System.Globalization.GregorianCalendar gCalendar = new System.Globalization.GregorianCalendar(); return gCalendar.GetWeekOfYear(dtm, System.Globalization.CalendarWeekRule.FirstDay, System.DayOfWeek.Monday); }
public static int TimeToInt(ref System.DateTime date) { System.Globalization.Calendar cal = new System.Globalization.GregorianCalendar(); SupportClass.CalendarManager.manager.SetDateTime(cal, date); return SupportClass.CalendarManager.manager.Get(cal, SupportClass.CalendarManager.HOUR_OF_DAY) * 10000000 + SupportClass.CalendarManager.manager.Get(cal, SupportClass.CalendarManager.MINUTE) * 100000 + SupportClass.CalendarManager.manager.Get(cal, SupportClass.CalendarManager.SECOND) * 1000 + SupportClass.CalendarManager.manager.Get(cal, SupportClass.CalendarManager.MILLISECOND); }
public void TestVersioningOfJavaDateRangeBehavior() { var startDate = GetLocalizedDate(2002, 1, 1, false); var endDate = GetLocalizedDate(2002, 1, 4, false); System.Globalization.Calendar calendar = new System.Globalization.GregorianCalendar(); var endDateExpected = new DateTime(2002, 1, 4, 23, 59, 59, 999, calendar); var qp = new QueryParser(Version.LUCENE_24, "field", new SimpleAnalyzer()); // Don't set any date resolution and verify if DateField is used AssertDateRangeQueryEquals(qp, "default", startDate, endDate, endDateExpected, null); // Use dates with dashes in them, which aren't parsed out as dates in Java AssertDateRangeQueryEquals(qp, "default", "2002-1-1", "2002-1-4", endDateExpected, null); qp = new QueryParser(Version.LUCENE_CURRENT, "field", new SimpleAnalyzer()); // We still want to make sure that a localized date of "M/d/YYYY" will be parsed out // as a datefield as expected. AssertDateRangeQueryEquals(qp, "default", startDate, endDate, endDateExpected, null); // This should be a normal query, NOT a date query if we're emulating Java (on or above Version LUCENE_30) AssertQueryEquals(qp, "field", "default:[2002-1-1 TO 2002-1-4]", "default:[2002-1-1 TO 2002-1-4]"); }
public virtual void TestLegacyDateRange() { System.String startDate = GetLocalizedDate(2002, 2, 1, false); System.String endDate = GetLocalizedDate(2002, 2, 4, false); System.Globalization.Calendar endDateExpected = new System.Globalization.GregorianCalendar(); // endDateExpected should be set to: "2002, 1, 4, 23, 59, 59, 999" otherwise what's the point of useing GregorianCalendar() // {{Aroush-2.1}} System.DateTime tempAux = new System.DateTime(2002, 2, 4, 23, 59, 59, 999); AssertQueryEquals("[ " + startDate + " TO " + endDate + "]", null, "[" + GetLegacyDate(startDate) + " TO " + DateField.DateToString(tempAux) + "]"); AssertQueryEquals("{ " + startDate + " " + endDate + " }", null, "{" + GetLegacyDate(startDate) + " TO " + GetLegacyDate(endDate) + "}"); }