本文整理汇总了C#中LocalDate类的典型用法代码示例。如果您正苦于以下问题:C# LocalDate类的具体用法?C# LocalDate怎么用?C# LocalDate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LocalDate类属于命名空间,在下文中一共展示了LocalDate类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Round
/// <summary>
/// Rundung des AfA-Datums
/// </summary>
/// <param name="date">Das zu rundende Datum</param>
/// <param name="mode">Der Rundungsmodus</param>
/// <returns>Das gerundete AfA-Datum</returns>
public static LocalDate Round(this LocalDate date, DateRoundingMode mode)
{
LocalDate result;
switch (mode)
{
case DateRoundingMode.Day:
result = date;
break;
case DateRoundingMode.Month:
result = new LocalDate(date.Year, date.Month, 1);
if (date.Day >= 15)
result = result + Period.FromMonths(1);
break;
case DateRoundingMode.BeginOfMonth:
result = new LocalDate(date.Year, date.Month, 1);
break;
case DateRoundingMode.HalfYear:
if (date.Month >= 7)
{
result = new LocalDate(date.Year, 7, 1);
}
else
{
result = new LocalDate(date.Year, 1, 1);
}
break;
case DateRoundingMode.BeginOfYear:
result = new LocalDate(date.Year, 1, 1);
break;
default:
throw new NotSupportedException();
}
return result;
}
开发者ID:FubarDevelopment,项目名称:AfA,代码行数:40,代码来源:LocalDateExtensions.cs
示例2: Length_Exclusive
public void Length_Exclusive()
{
LocalDate start = new LocalDate(2000, 1, 1);
LocalDate end = new LocalDate(2000, 2, 10);
var interval = new DateInterval(start, end, false);
Assert.AreEqual(40, interval.Length);
}
开发者ID:KonstantinDavidov,项目名称:nodatime,代码行数:7,代码来源:DateIntervalTest.cs
示例3: ComparisonOperators_SameCalendar
public void ComparisonOperators_SameCalendar()
{
LocalDate date1 = new LocalDate(2011, 1, 2);
LocalDate date2 = new LocalDate(2011, 1, 2);
LocalDate date3 = new LocalDate(2011, 1, 5);
Assert.IsFalse(date1 < date2);
Assert.IsTrue(date1 < date3);
Assert.IsFalse(date2 < date1);
Assert.IsFalse(date3 < date1);
Assert.IsTrue(date1 <= date2);
Assert.IsTrue(date1 <= date3);
Assert.IsTrue(date2 <= date1);
Assert.IsFalse(date3 <= date1);
Assert.IsFalse(date1 > date2);
Assert.IsFalse(date1 > date3);
Assert.IsFalse(date2 > date1);
Assert.IsTrue(date3 > date1);
Assert.IsTrue(date1 >= date2);
Assert.IsFalse(date1 >= date3);
Assert.IsTrue(date2 >= date1);
Assert.IsTrue(date3 >= date1);
}
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:26,代码来源:LocalDateTest.Comparison.cs
示例4: LocalDateTest
public void LocalDateTest()
{
LocalDate d1 = new LocalDate(2016, 1, 10);
LocalDate d2 = new LocalDate(2016, 1, 1);
LocalDate d1other = new LocalDate(2016, 1, 10);
Assert.AreNotEqual(d1, d2);
Assert.AreEqual(d1, d1other);
using (SessionNoServer session = new SessionNoServer(systemDir))
{
session.BeginUpdate();
LocalDateField test1 = new LocalDateField("def", d1);
session.Persist(test1);
LocalDateField test = new LocalDateField("abc", d2);
session.Persist(test);
var result1 = session.AllObjects<LocalDateField>().First(t => t.Field2.Equals(d2)); // this works
session.Commit();
}
using (SessionNoServer session = new SessionNoServer(systemDir))
{
session.BeginRead();
var result2 = session.AllObjects<LocalDateField>().First(t =>
{
var l = t.Field2;
return l.Equals(d2);
}); // this should work and doesnt
session.Commit();
}
}
开发者ID:VelocityDB,项目名称:VelocityDB,代码行数:30,代码来源:DateTimeTest.cs
示例5: CombineWithTime
public void CombineWithTime()
{
LocalDate date = new LocalDate(2010, 6, 16);
LocalTime time = new LocalTime(16, 20);
LocalDateTime dateTime = date + time;
Assert.AreEqual(new LocalDateTime(2010, 6, 16, 16, 20, 0), dateTime);
}
开发者ID:KonstantinDavidov,项目名称:nodatime,代码行数:7,代码来源:LocalDateDemo.cs
示例6: Subtraction_PeriodWithTime
public void Subtraction_PeriodWithTime()
{
LocalDate date = new LocalDate(2010, 1, 1);
Period period = Period.FromHours(1);
// Use method not operator here to form a valid statement
Assert.Throws<ArgumentException>(() => LocalDate.Subtract(date, period));
}
开发者ID:ivandrofly,项目名称:nodatime,代码行数:7,代码来源:LocalDateTest.PeriodArithmetic.cs
示例7: PeriodAddition_MethodEquivalents
public void PeriodAddition_MethodEquivalents()
{
LocalDate start = new LocalDate(2010, 6, 19);
Period period = Period.FromMonths(3) + Period.FromDays(10);
Assert.AreEqual(start + period, LocalDate.Add(start, period));
Assert.AreEqual(start + period, start.Plus(period));
}
开发者ID:ivandrofly,项目名称:nodatime,代码行数:7,代码来源:LocalDateTest.PeriodArithmetic.cs
示例8: Subtraction_TruncatesOnShortMonth
public void Subtraction_TruncatesOnShortMonth()
{
LocalDate start = new LocalDate(2010, 3, 30);
Period period = Period.FromMonths(1);
LocalDate expected = new LocalDate(2010, 2, 28);
Assert.AreEqual(expected, start - period);
}
开发者ID:ivandrofly,项目名称:nodatime,代码行数:7,代码来源:LocalDateTest.PeriodArithmetic.cs
示例9: Subtraction_WithPeriod
public void Subtraction_WithPeriod()
{
LocalDate start = new LocalDate(2010, 9, 29);
Period period = Period.FromMonths(3) + Period.FromDays(10);
LocalDate expected = new LocalDate(2010, 6, 19);
Assert.AreEqual(expected, start - period);
}
开发者ID:ivandrofly,项目名称:nodatime,代码行数:7,代码来源:LocalDateTest.PeriodArithmetic.cs
示例10: Add
/// <summary>
/// Addiert zu einem Datum (unter Berücksichtigung der geforderten Genauigkeit) die Anzahl an Jahren, Monaten und/oder Tagen.
/// </summary>
/// <param name="date">Das Datum zu dem die Jahre, Monate und Tage addiert werden sollen</param>
/// <param name="addYears">Die Anzahl an Jahren die addiert werden sollen (kann auch negativ sein)</param>
/// <param name="addMonths">Die Anzahl an Monaten die addiert werden sollen (kann auch negativ sein)</param>
/// <param name="addDays">Die Anzahl an Tagen die addiert werden sollen (kann auch negativ sein)</param>
/// <returns>Das neue Datum nach der Addition von Jahren, Monaten und/oder Tagen</returns>
public LocalDate Add(LocalDate date, long addYears, long addMonths, long addDays)
{
var day = date.Day + addDays;
var month = date.Month + addMonths;
var year = date.Year + addYears;
month += day / 30;
day %= 30;
if (day < 0)
{
day += 30;
--month;
}
year += month / 12;
month %= 12;
if (month < 0)
{
month += 12;
--year;
}
var newYear = (int)year;
var newMonth = (int)month;
var newDay = (int)day;
var lastDayOfMonth = new LocalDate(newYear, newMonth, 1).GetLastDayOfMonth();
if (lastDayOfMonth.Day < newDay)
newDay = lastDayOfMonth.Day;
return new LocalDate(newYear, newMonth, newDay);
}
开发者ID:FubarDevelopment,项目名称:AfA,代码行数:40,代码来源:DatePrecision30.cs
示例11: DayOfMonth
public void DayOfMonth()
{
var start = new LocalDate(2014, 6, 27);
var end = new LocalDate(2014, 6, 19);
var adjuster = DateAdjusters.DayOfMonth(19);
Assert.AreEqual(end, adjuster(start));
}
开发者ID:ivandrofly,项目名称:nodatime,代码行数:7,代码来源:DateAdjustersTest.cs
示例12: AssertEquivalent
/// <summary>
/// Checks that each day from the given start year to the end year (inclusive) is equal
/// between the BCL and the Noda Time calendar. Additionally, the number of days in each month and year
/// and the number of months (and leap year status) in each year is checked.
/// </summary>
internal static void AssertEquivalent(Calendar bcl, CalendarSystem noda, int fromYear, int toYear)
{
// We avoid asking the BCL to create a DateTime on each iteration, simply
// because the BCL implementation is so slow. Instead, we just check at the start of each month that
// we're at the date we expect.
DateTime bclDate = bcl.ToDateTime(fromYear, 1, 1, 0, 0, 0, 0);
for (int year = fromYear; year <= toYear; year++)
{
Assert.AreEqual(bcl.GetDaysInYear(year), noda.GetDaysInYear(year), "Year: {0}", year);
Assert.AreEqual(bcl.GetMonthsInYear(year), noda.GetMonthsInYear(year), "Year: {0}", year);
for (int month = 1; month <= noda.GetMonthsInYear(year); month++)
{
// Sanity check at the start of each month. Even this is surprisingly slow.
// (These three tests make up about 20% of the total execution time for the test.)
Assert.AreEqual(year, bcl.GetYear(bclDate));
Assert.AreEqual(month, bcl.GetMonth(bclDate));
Assert.AreEqual(1, bcl.GetDayOfMonth(bclDate));
Assert.AreEqual(bcl.GetDaysInMonth(year, month), noda.GetDaysInMonth(year, month),
"Year: {0}; Month: {1}", year, month);
Assert.AreEqual(bcl.IsLeapYear(year), noda.IsLeapYear(year), "Year: {0}", year);
for (int day = 1; day <= noda.GetDaysInMonth(year, month); day++)
{
LocalDate nodaDate = new LocalDate(year, month, day, noda);
Assert.AreEqual(bclDate, nodaDate.ToDateTimeUnspecified(),
"Original calendar system date: {0:yyyy-MM-dd}", nodaDate);
Assert.AreEqual(nodaDate, LocalDate.FromDateTime(bclDate, noda));
Assert.AreEqual(year, nodaDate.Year);
Assert.AreEqual(month, nodaDate.Month);
Assert.AreEqual(day, nodaDate.Day);
bclDate = bclDate.AddDays(1);
}
}
}
}
开发者ID:ivandrofly,项目名称:nodatime,代码行数:40,代码来源:BclEquivalenceHelper.cs
示例13: Construction_EndBeforeStart
public void Construction_EndBeforeStart()
{
LocalDate start = new LocalDate(1600, 1, 1);
LocalDate end = new LocalDate(1500, 1, 1);
Assert.Throws<ArgumentException>(() => new DateInterval(start, end));
Assert.Throws<ArgumentException>(() => new DateInterval(start, end, true));
}
开发者ID:ivandrofly,项目名称:nodatime,代码行数:7,代码来源:DateIntervalTest.cs
示例14: Construction_DifferentCalendars
public void Construction_DifferentCalendars()
{
LocalDate start = new LocalDate(1600, 1, 1);
LocalDate end = new LocalDate(1800, 1, 1, JulianCalendar);
Assert.Throws<ArgumentException>(() => new DateInterval(start, end));
Assert.Throws<ArgumentException>(() => new DateInterval(start, end, true));
}
开发者ID:ivandrofly,项目名称:nodatime,代码行数:7,代码来源:DateIntervalTest.cs
示例15: Transitions2000To2010
public void Transitions2000To2010()
{
// These were fetched with Joda Time 1.6.2, which definitely uses the new rules.
var expectedDates = new[]
{
new LocalDate(2000, 3, 30), // Thursday morning
new LocalDate(2001, 3, 29), // Thursday morning
new LocalDate(2002, 3, 29), // Friday morning from here onwards
new LocalDate(2003, 3, 28),
new LocalDate(2004, 3, 26),
new LocalDate(2005, 4, 1),
new LocalDate(2006, 3, 31),
new LocalDate(2007, 3, 30),
new LocalDate(2008, 3, 28),
new LocalDate(2009, 3, 27),
new LocalDate(2010, 3, 26)
};
for (int year = 2000; year <= 2010; year++)
{
LocalDate summer = new LocalDate(year, 6, 1);
var intervalPair = Jordan.MapLocal(summer.AtMidnight());
Assert.AreEqual(1, intervalPair.Count);
Assert.AreEqual(expectedDates[year - 2000], intervalPair.EarlyInterval.IsoLocalStart.Date);
}
}
开发者ID:nicklbailey,项目名称:nodatime,代码行数:26,代码来源:JordanTest.cs
示例16: Constructor_PropertiesRoundTrip
public void Constructor_PropertiesRoundTrip()
{
LocalDate date = new LocalDate(2023, 7, 27);
Assert.AreEqual(2023, date.Year);
Assert.AreEqual(7, date.MonthOfYear);
Assert.AreEqual(27, date.DayOfMonth);
}
开发者ID:manirana007,项目名称:NodaTime,代码行数:7,代码来源:LocalDateTest.Construction.cs
示例17: Constructor_PropertiesRoundTrip_CustomCalendar
public void Constructor_PropertiesRoundTrip_CustomCalendar()
{
LocalDate date = new LocalDate(2023, 7, 27, CalendarSystem.GetJulianCalendar(4));
Assert.AreEqual(2023, date.Year);
Assert.AreEqual(7, date.MonthOfYear);
Assert.AreEqual(27, date.DayOfMonth);
}
开发者ID:manirana007,项目名称:NodaTime,代码行数:7,代码来源:LocalDateTest.Construction.cs
示例18: BclThroughHistory_Scriptural
public void BclThroughHistory_Scriptural()
{
var bcl = BclCalendars.Hebrew;
var noda = CalendarSystem.HebrewScriptural;
// The min supported date/time starts part way through the year
var minYear = bcl.GetYear(bcl.MinSupportedDateTime) + 1;
// The max supported date/time ends part way through the year
var maxYear = bcl.GetYear(bcl.MaxSupportedDateTime) - 1;
// Can't use BclEquivalenceHelper for this one, because of the month conversions.
for (int year = minYear; year <= maxYear; year++)
{
int months = bcl.GetMonthsInYear(year);
Assert.AreEqual(months, noda.GetMonthsInYear(year));
for (int civilMonth = 1; civilMonth <= months; civilMonth++)
{
int scripturalMonth = HebrewMonthConverter.CivilToScriptural(year, civilMonth);
Assert.AreEqual(bcl.GetDaysInMonth(year, civilMonth), noda.GetDaysInMonth(year, scripturalMonth),
"Year: {0}; Month: {1} (civil)", year, civilMonth);
for (int day = 1; day < bcl.GetDaysInMonth(year, civilMonth); day++)
{
DateTime bclDate = bcl.ToDateTime(year, civilMonth, day, 0, 0, 0, 0);
LocalDate nodaDate = new LocalDate(year, scripturalMonth, day, noda);
Assert.AreEqual(bclDate, nodaDate.AtMidnight().ToDateTimeUnspecified(), "{0}-{1}-{2}", year, scripturalMonth, day);
Assert.AreEqual(nodaDate, LocalDateTime.FromDateTime(bclDate, noda).Date);
Assert.AreEqual(year, nodaDate.Year);
Assert.AreEqual(scripturalMonth, nodaDate.Month);
Assert.AreEqual(day, nodaDate.Day);
}
}
}
}
开发者ID:ivandrofly,项目名称:nodatime,代码行数:33,代码来源:HebrewCalendarSystemTest.cs
示例19: Add
public LocalDate Add(LocalDate localDate, int value)
{
var calendar = localDate.Calendar;
var calculator = calendar.YearMonthDayCalculator;
var yearMonthDay = calculator.AddMonths(localDate.YearMonthDay, value);
return new LocalDate(yearMonthDay, calendar);
}
开发者ID:KonstantinDavidov,项目名称:nodatime,代码行数:7,代码来源:MonthsPeriodField.cs
示例20: CombineWithTime
public void CombineWithTime()
{
LocalDate date = new LocalDate(2010, 6, 16);
LocalTime time = new LocalTime(16, 20, 0);
LocalDateTime dateTime = date + time;
Assert.AreEqual("ISO: 2010-06-16T16:20:00 LOC", dateTime.ToString());
}
开发者ID:manirana007,项目名称:NodaTime,代码行数:7,代码来源:LocalDateDemo.cs
注:本文中的LocalDate类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论