本文整理汇总了C#中System.Globalization.GregorianCalendar类的典型用法代码示例。如果您正苦于以下问题:C# GregorianCalendar类的具体用法?C# GregorianCalendar怎么用?C# GregorianCalendar使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GregorianCalendar类属于System.Globalization命名空间,在下文中一共展示了GregorianCalendar类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetDaylightChanges
/// <summary>
/// Returns the daylight changes for UTC (never).
/// </summary>
public override DaylightTime GetDaylightChanges(int year)
{
// We need a start and stop time
DateTime start, end;
Calendar cal = new GregorianCalendar();
// 2007+ at this point has a slightly different start/stop
if (year >= 2007)
{
start = new DateTime(year, 4, 1, 2, 0, 0);
end = new DateTime(year, 11, 1, 2, 0, 0);
}
else
{
start = new DateTime(year, 3, 1, 2, 0, 0);
end = new DateTime(year, 12, 1, 2, 0, 0);
}
// Move forward for the start date until we have a sunday
while (cal.GetDayOfWeek(start) != DayOfWeek.Sunday)
start = cal.AddDays(start, 1);
// Move backwards from the end date to the last sunday
while (cal.GetDayOfWeek(end) != DayOfWeek.Sunday)
start = cal.AddDays(end, 1);
// Create it
return new DaylightTime(start, end,
new TimeSpan(stOffset - dtOffset, 0, 0));
}
示例2: WorkYear
public WorkYear(int year, WorkDayParserSettings parserSettings, int hitListLookBackInWeeks, float hoursPerDay, PNSearchViewModel pnSearch, PositionSearchViewModel positionSearch)
{
this.hitListLookBackInWeeks = hitListLookBackInWeeks;
this.pnSearch = pnSearch;
this.positionSearch = positionSearch;
this.Year = year;
this.Months = new ObservableCollection<WorkMonth>();
this.Weeks = new ObservableCollection<WorkWeek>();
var germanSpecialDays = SpecialDaysUtils.GetGermanSpecialDays(year);
var cal = new GregorianCalendar();
for (int month = 1; month <= cal.GetMonthsInYear(year); month++)
{
WorkMonth wm = new WorkMonth(year, month, germanSpecialDays, parserSettings, hoursPerDay);
this.Months.Add(wm);
foreach (var workWeek in wm.Weeks)
{
this.Weeks.Add(workWeek);
workWeek.PropertyChanged += this.workWeek_PropertyChanged;
}
}
this.ProjectHitlist = new QuickFillObservableCollection<HitlistInfo>();
this.PositionHitlist = new QuickFillObservableCollection<HitlistInfo>();
this.UpdateProjectHitlistAsync();
this.UpdatePositionHitlistAsync();
}
示例3: Create
public List<List<CalendarDay>> Create(IQueryable<Episode> episodeCollection, DateTime currentDate)
{
List<List<CalendarDay>> model = this.ConstructModel();
Calendar calendar = new GregorianCalendar();
const int CalendarDays = 42;
DateTime startDate = new DateTime(currentDate.Year, currentDate.Month, 1);
startDate = startDate.Subtract(new TimeSpan((int)calendar.GetDayOfWeek(startDate) - (int)DayOfWeek.Monday, 0, 0, 0));
DateTime endDate = startDate.Add(new TimeSpan(CalendarDays, 0, 0, 0));
List<CalendarEpisode> episodes = this.GetEpisodes(episodeCollection, startDate, endDate);
int weekIndex = 0;
for (int i = 0; i < CalendarDays; i++)
{
DayOfWeek dayOfWeek = calendar.GetDayOfWeek(startDate);
this.AddEpisodes(model, episodes, startDate, weekIndex);
startDate = startDate.AddDays(1);
if (dayOfWeek == DayOfWeek.Sunday)
{
weekIndex++;
}
}
return model;
}
示例4: PosTest1
public void PosTest1()
{
System.Globalization.Calendar tbc = new ThaiBuddhistCalendar();
System.Globalization.Calendar gc = new GregorianCalendar();
DateTime desiretdDT = gc.ToDateTime(1, 1, 1, 0, 0, 0, 0);
Assert.Equal(tbc.MinSupportedDateTime, desiretdDT);
}
示例5: AreAnyRoomsInRangeAvailable
/// <summary>
/// Returns false only if all fields for the range has availability set to false
/// </summary>
/// <remarks>
/// This method is useful to checking un-availability, as it will return true if there is any availability in a date range
/// </remarks>
/// <param name="availability">The record to check</param>
/// <param name="fromDayOfYear">From which Day Of Year</param>
/// <param name="toDayOfYear">OPTIONAL: to which Day Of Year, last day in sequence will not be checked will not be checked</param>
/// <returns>True if any of the rooms in the range specified is available otherwise false</returns>
public static bool AreAnyRoomsInRangeAvailable(RoomsAvailability availability, int fromDayOfYear, int? toDayOfYear = null)
{
// if the availability is null means that the room is assumed to be available
if(availability == null)
{
return true;
}
//because we have leap years we need to consider either 365 or 366 days
if (!toDayOfYear.HasValue)
{
GregorianCalendar calendar = new GregorianCalendar();
toDayOfYear = calendar.GetDaysInYear(availability.Year);
}
bool isAvailable = false;
for (int d = fromDayOfYear; d < toDayOfYear; d++)
{
string propertyName = String.Format("IsDay{0:000}Available", d);
PropertyInfo p = typeof(RoomsAvailability).GetProperty(propertyName);
isAvailable = isAvailable | (bool)p.GetValue(availability, null);
}
return isAvailable;
}
示例6: WorkMonth
public WorkMonth(int year, int month, GermanSpecialDays specialDays, IEnumerable<ShortCut> shortCuts, float hoursPerDay)
{
this.year = year;
this.month = month;
this.hoursPerDay = hoursPerDay;
this.Weeks = new ObservableCollection<WorkWeek>();
this.Days = new ObservableCollection<WorkDay>();
this.ShortCutStatistic = new ObservableCollection<KeyValuePair<string, ShortCutStatistic>>();
// TODO which date should i take?
this.ReloadShortcutStatistic(shortCuts);
var cal = new GregorianCalendar();
WorkWeek lastWeek = null;
for (int day = 1; day <= cal.GetDaysInMonth(year, month); day++) {
var dt = new DateTime(year, month, day);
WorkDay wd = new WorkDay(year, month, day, specialDays);
this.Days.Add(wd);
var weekOfYear = cal.GetWeekOfYear(dt, CalendarWeekRule.FirstDay, DayOfWeek.Monday);
if (lastWeek == null || lastWeek.WeekOfYear != weekOfYear) {
lastWeek = new WorkWeek(this, weekOfYear);
lastWeek.PropertyChanged += new PropertyChangedEventHandler(this.WeekPropertyChanged);
this.Weeks.Add(lastWeek);
}
lastWeek.AddDay(wd);
}
}
示例7: PosTest1
public void PosTest1()
{
System.Globalization.Calendar tc = new TaiwanCalendar();
System.Globalization.Calendar gc = new GregorianCalendar();
DateTime desiredDT = gc.ToDateTime(1912, 1, 1, 0, 0, 0, 0);
Assert.Equal(desiredDT, tc.MinSupportedDateTime);
}
示例8: EncodeDate
public static int EncodeDate(DateTime d)
{
int day, month, year;
int c, ya;
GregorianCalendar calendar = new GregorianCalendar();
day = calendar.GetDayOfMonth(d);
month = calendar.GetMonth(d);
year = calendar.GetYear(d);
if (month > 2)
{
month -= 3;
}
else
{
month += 9;
year -= 1;
}
c = year / 100;
ya = year - 100 * c;
return ((146097 * c) / 4 + (1461 * ya) / 4 + (153 * month + 2) / 5 + day + 1721119 - 2400001);
}
示例9: GetCalendarDaysFor
public static List<ActivityDay> GetCalendarDaysFor(int? period/*0=yearly, 1=monthly and 2=weekly*/)
{
var days = new List<ActivityDay>();
//var calendar = new ActivityCalendar();
var calendarYear = new GregorianCalendar();
switch (period)
{
case 0:
var dayNumber=(int)DateTime.Now.DayOfWeek;
var weekDay = DateTime.Now.AddDays(-dayNumber);
for (int i=0;i<7;i++)
{
days.Add(new ActivityDay {
Date = weekDay,
Name = calendarYear.GetDayOfWeek(weekDay).ToString(),
Status=true,
ActivityStatus = calendarYear.GetDayOfWeek(weekDay) == DayOfWeek.Friday ?
DayStatus.Holiday
:DayStatus.Active});
weekDay=weekDay.AddDays(1);
}
break;
case 1:
var daysInMonth=calendarYear.GetDaysInMonth(DateTime.Now.Year, DateTime.Now.Month);
for (int day = 1; day <= daysInMonth;day++ )
{
var date = new DateTime(DateTime.Now.Year, DateTime.Now.Month, day);
days.Add(new ActivityDay
{
Date = date,
Name = calendarYear.GetDayOfWeek(date).ToString(),
Status = true,
ActivityStatus = calendarYear.GetDayOfWeek(date) ==
DayOfWeek.Friday ? DayStatus.Holiday : DayStatus.Active
});
}
break;
default:
var daysInYr=calendarYear.GetDaysInYear(DateTime.Now.Year);
var startOfYr = new DateTime(DateTime.Now.Year, 1, 1);
for (int day = 0; day < daysInYr; day++)
{
var dateOfYr = new ActivityDay {Date=startOfYr.AddDays(day) };
dateOfYr.Name = calendarYear.GetDayOfWeek(dateOfYr.Date).ToString();
dateOfYr.Status = true;
dateOfYr.ActivityStatus = calendarYear.GetDayOfWeek(dateOfYr.Date) == DayOfWeek.Friday ? DayStatus.Holiday : DayStatus.Active;
days.Add(dateOfYr);
}
break;
}
return days;
}
示例10: FN_GER_GetWeekOfYear
public static SqlInt32 FN_GER_GetWeekOfYear(SqlDateTime _date)
{
System.Globalization.GregorianCalendar gc = new System.Globalization.GregorianCalendar();
return _date.IsNull ? SqlInt32.Null : gc.GetWeekOfYear(_date.Value, System.Globalization.CalendarWeekRule.FirstFullWeek, DayOfWeek.Monday);
}
示例11: PosTest1
private void PosTest1(GregorianCalendarTypes calendarType)
{
System.Globalization.Calendar myCalendar = new GregorianCalendar(calendarType);
int expectedTwoDigitYearMax, actualTwoDigitYearMax;
expectedTwoDigitYearMax = c_DEFAULT_TWO_DIGIT_YEAR_MAX;
actualTwoDigitYearMax = myCalendar.TwoDigitYearMax;
Assert.Equal(expectedTwoDigitYearMax, actualTwoDigitYearMax);
}
示例12: PosTest1
public void PosTest1()
{
System.Globalization.Calendar tc = new TaiwanCalendar();
System.Globalization.Calendar gc = new GregorianCalendar();
DateTime desiretdDT = gc.ToDateTime(9999, 12, 31, 23, 59, 59, 999);
desiretdDT = desiretdDT.AddTicks(9999);
Assert.Equal(desiretdDT, tc.MaxSupportedDateTime);
}
示例13: Can_Get_IndexOfDay_For_Other_Calendars_Using_CultureHelper
public void Can_Get_IndexOfDay_For_Other_Calendars_Using_CultureHelper()
{
var calendar = new GregorianCalendar();
var dt = new DateTime(2009, 5, 11); //Should be Monday
var dow = CultureHelper.GetDayOfWeek(dt, calendar);
Assert.AreEqual(1, dow);
}
示例14: PosTest
// PosTest: Get the MaxSupportedDateTime of Gregorian calendar
private void PosTest(GregorianCalendarTypes calendarType)
{
System.Globalization.Calendar myCalendar = new GregorianCalendar(calendarType);
DateTime expectedTime, actualTime;
expectedTime = DateTime.MaxValue;
actualTime = myCalendar.MaxSupportedDateTime;
Assert.Equal(expectedTime, actualTime);
}
示例15: GetDaysInYearShouldReturnCorrectCount
public void GetDaysInYearShouldReturnCorrectCount()
{
var target = new GregorianFiscalCalendar( 7 );
var calendar = new GregorianCalendar();
for ( var year = 1998; year <= 2030; year++ )
Assert.Equal( calendar.GetDaysInYear( year ), target.GetDaysInYear( year ) );
}