本文整理汇总了C#中LocalInstant类的典型用法代码示例。如果您正苦于以下问题:C# LocalInstant类的具体用法?C# LocalInstant怎么用?C# LocalInstant使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LocalInstant类属于命名空间,在下文中一共展示了LocalInstant类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MinusOffset_Zero_IsNeutralElement
public void MinusOffset_Zero_IsNeutralElement()
{
Instant sampleInstant = new Instant(1, 23456L);
LocalInstant sampleLocalInstant = new LocalInstant(1, 23456L);
Assert.AreEqual(sampleInstant, sampleLocalInstant.Minus(Offset.Zero));
Assert.AreEqual(sampleInstant, sampleLocalInstant.MinusZeroOffset());
}
示例2: SetValue
internal override LocalInstant SetValue(LocalInstant localInstant, long value)
{
FieldUtils.VerifyValueBounds(this, value, min, max);
long wrappedValue = WrappedField.GetInt64Value(localInstant);
long remainder = wrappedValue >= 0 ? wrappedValue % divisor : (divisor - 1) + ((wrappedValue + 1) % divisor);
return WrappedField.SetValue(localInstant, value * divisor + remainder);
}
示例3: GetValue_WithLocalInstant
public void GetValue_WithLocalInstant()
{
LocalInstant when = new LocalInstant(987654321L);
Assert.AreEqual(0, field.GetValue(new Duration(0L), when));
Assert.AreEqual(12345, field.GetValue(new Duration(123456789L), when));
Assert.AreEqual(-1, field.GetValue(new Duration(-12345L), when));
}
示例4: GetZoneIntervals_WithinFirstSummer
public void GetZoneIntervals_WithinFirstSummer()
{
var early = new LocalInstant(2000, 6, 1, 0, 0);
var pair = TestZone.GetZoneIntervals(early);
Assert.AreEqual("Summer", pair.EarlyInterval.Name);
Assert.IsNull(pair.LateInterval);
}
示例5: SetValue
internal override LocalInstant SetValue(LocalInstant localInstant, long value)
{
FieldUtils.VerifyValueBounds(this, value, 0, divisor - 1);
int wrappedValue = WrappedField.GetValue(localInstant);
int divided = wrappedValue >= 0 ? wrappedValue / divisor : ((wrappedValue + 1) / divisor) - 1;
return WrappedField.SetValue(localInstant, divided * divisor + value);
}
示例6: GetDifference
internal override int GetDifference(LocalInstant minuendInstant, LocalInstant subtrahendInstant)
{
differences++;
DiffFirstArg = minuendInstant;
DiffSecondArg = subtrahendInstant;
return 30;
}
示例7: GetInt64Difference
internal override long GetInt64Difference(LocalInstant minuendInstant, LocalInstant subtrahendInstant)
{
DateTimeField field = calendarSystem.Fields.WeekYear;
if (minuendInstant < subtrahendInstant)
{
return -GetInt64Difference(subtrahendInstant, minuendInstant);
}
int minuendWeekYear = field.GetValue(minuendInstant);
int subtrahendWeekYear = field.GetValue(subtrahendInstant);
Duration minuendRemainder = field.Remainder(minuendInstant);
Duration subtrahendRemainder = field.Remainder(subtrahendInstant);
// Balance leap weekyear differences on remainders.
if (subtrahendRemainder >= Week53Ticks && calendarSystem.GetWeeksInYear(minuendWeekYear) <= 52)
{
subtrahendRemainder -= Duration.OneWeek;
}
int difference = minuendWeekYear - subtrahendWeekYear;
if (minuendRemainder < subtrahendRemainder)
{
difference--;
}
return difference;
}
示例8: Add
internal override LocalInstant Add(LocalInstant localInstant, int value)
{
int32Additions++;
AddInstantArg = localInstant;
AddValueArg = value;
return new LocalInstant(localInstant.Ticks + value * unitTicks);
}
示例9: GetInt64Value_WithLocalInstant
public void GetInt64Value_WithLocalInstant()
{
LocalInstant when = new LocalInstant(56789L);
Assert.AreEqual(0L, TicksDurationField.Instance.GetInt64Value(new Duration(0L), when));
Assert.AreEqual(1234L, TicksDurationField.Instance.GetInt64Value(new Duration(1234L), when));
Assert.AreEqual(-1234L, TicksDurationField.Instance.GetInt64Value(new Duration(-1234L), when));
Assert.AreEqual(int.MaxValue + 1L, TicksDurationField.Instance.GetInt64Value(new Duration(int.MaxValue + 1L), when));
}
示例10: SetValue
internal override LocalInstant SetValue(LocalInstant localInstant, long value)
{
FieldUtils.VerifyValueBounds(this, value, 1, GetMaximumValue());
if (calendarSystem.GetYear(localInstant) <= 0)
{
value = 1 - value;
}
return base.SetValue(localInstant, value);
}
示例11: SetValue
internal override LocalInstant SetValue(LocalInstant localInstant, long value)
{
FieldUtils.VerifyValueBounds(this, value, 0, GetMaximumValue());
if (WrappedField.GetValue(localInstant) < 0)
{
value = -value;
}
return base.SetValue(localInstant, value);
}
示例12: FromDateTime
public void FromDateTime()
{
LocalInstant expected = new LocalInstant(2011, 08, 18, 20, 53);
foreach (DateTimeKind kind in Enum.GetValues(typeof(DateTimeKind)))
{
DateTime x = new DateTime(2011, 08, 18, 20, 53, 0, kind);
LocalInstant actual = LocalInstant.FromDateTime(x);
Assert.AreEqual(expected, actual);
}
}
示例13: GetValue_DelegatesToGetInt64Value
public void GetValue_DelegatesToGetInt64Value()
{
var field = new StubDateTimeField();
var arg = new LocalInstant(60);
field.GetValue(arg);
Assert.That(field.GetInt64ValueWasCalled, Is.True);
Assert.That(field.GetInt64ValueArg, Is.EqualTo(arg));
}
示例14: Equality
public void Equality()
{
LocalInstant equal = new LocalInstant(1, 100L);
LocalInstant different1 = new LocalInstant(1, 200L);
LocalInstant different2 = new LocalInstant(2, 100L);
TestHelper.TestEqualsStruct(equal, equal, different1);
TestHelper.TestOperatorEquality(equal, equal, different1);
TestHelper.TestEqualsStruct(equal, equal, different2);
TestHelper.TestOperatorEquality(equal, equal, different2);
}
示例15: Add
/// <summary>
/// Add the specified month to the specified time instant.
/// The amount added may be negative.
/// </summary>
/// <param name="localInstant">The local instant to update</param>
/// <param name="value">The months to add (can be negative).</param>
/// <returns>The updated local instant</returns>
/// <remarks>
/// If the new month has less total days than the specified
/// day of the month, this value is coerced to the nearest
/// sane value. e.g.
/// 07-31 - (1 month) = 06-30
/// 03-31 - (1 month) = 02-28 or 02-29 depending
/// </remarks>
internal override LocalInstant Add(LocalInstant localInstant, int value)
{
// Keep the parameter name the same as the original declaration, but
// use a more meaningful name in the method
int months = value;
if (months == 0)
{
return localInstant;
}
// Save the time part first
long timePart = calendarSystem.GetTickOfDay(localInstant);
// Get the year and month
int thisYear = calendarSystem.GetYear(localInstant);
int thisMonth = calendarSystem.GetMonthOfYear(localInstant, thisYear);
// Do not refactor without careful consideration.
// Order of calculation is important.
int yearToUse;
// Initially, monthToUse is zero-based
int monthToUse = thisMonth - 1 + months;
if (monthToUse >= 0)
{
yearToUse = thisYear + (monthToUse / monthsPerYear);
monthToUse = (monthToUse % monthsPerYear) + 1;
}
else
{
yearToUse = thisYear + (monthToUse / monthsPerYear) - 1;
monthToUse = Math.Abs(monthToUse);
int remMonthToUse = monthToUse % monthsPerYear;
// Take care of the boundary condition
if (remMonthToUse == 0)
{
remMonthToUse = monthsPerYear;
}
monthToUse = monthsPerYear - remMonthToUse + 1;
// Take care of the boundary condition
if (monthToUse == 1)
{
yearToUse++;
}
}
// End of do not refactor.
// Quietly force DOM to nearest sane value.
int dayToUse = calendarSystem.GetDayOfMonth(localInstant, thisYear, thisMonth);
int maxDay = calendarSystem.GetDaysInMonth(yearToUse, monthToUse);
dayToUse = Math.Min(dayToUse, maxDay);
// Get proper date part, and return result
long datePart = calendarSystem.GetYearMonthDayTicks(yearToUse, monthToUse, dayToUse);
return new LocalInstant(datePart + timePart);
}