本文整理汇总了C#中DateTimeOffset类的典型用法代码示例。如果您正苦于以下问题:C# DateTimeOffset类的具体用法?C# DateTimeOffset怎么用?C# DateTimeOffset使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DateTimeOffset类属于命名空间,在下文中一共展示了DateTimeOffset类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetNextIncludedTimeUtc
/// <summary>
/// Determine the next time (in milliseconds) that is 'included' by the
/// Calendar after the given time. Return the original value if timeStamp is
/// included. Return DateTime.MinValue if all days are excluded.
/// <para>
/// Note that this Calendar is only has full-day precision.
/// </para>
/// </summary>
/// <param name="timeUtc"></param>
/// <returns></returns>
public override DateTimeOffset GetNextIncludedTimeUtc(DateTimeOffset timeUtc)
{
if (base.AreAllDaysExcluded())
{
return DateTime.MinValue;
}
// Call base calendar implementation first
DateTimeOffset baseTime = base.GetNextIncludedTimeUtc(timeUtc);
if ((baseTime != DateTimeOffset.MinValue) && (baseTime > timeUtc))
{
timeUtc = baseTime;
}
// Get timestamp for 00:00:00
//DateTime d = timeUtc.Date; --commented out for local time impl
DateTime d = timeUtc.ToLocalTime().Date;
if (!IsDayExcluded(d.DayOfWeek))
{
return timeUtc;
} // return the original value
while (IsDayExcluded(d.DayOfWeek))
{
d = d.AddDays(1);
}
return d;
}
示例2: OnClosing
// not virtual as is called from the ctor
protected void OnClosing(DateTimeOffset closed)
{
DomainEventHandler<IssueClosed> handler = Closing;
if (handler != null) handler(this, new DomainEventEventArgs<IssueClosed>(
new IssueClosed(Id) { Closed = closed },
doClose));
}
示例3: IndexDecider_EndsUpInTheOutput
public void IndexDecider_EndsUpInTheOutput()
{
//DO NOTE that you cant send objects as scalar values through Logger.*("{Scalar}", {});
var timestamp = new DateTimeOffset(2013, 05, 28, 22, 10, 20, 666, TimeSpan.FromHours(10));
const string messageTemplate = "{Song}++ @{Complex}";
var template = new MessageTemplateParser().Parse(messageTemplate);
_options.IndexDecider = (l, utcTime) => string.Format("logstash-{1}-{0:yyyy.MM.dd}", utcTime, l.Level.ToString().ToLowerInvariant());
using (var sink = new ElasticsearchSink(_options))
{
var properties = new List<LogEventProperty> { new LogEventProperty("Song", new ScalarValue("New Macabre")) };
var e = new LogEvent(timestamp, LogEventLevel.Information, null, template, properties);
sink.Emit(e);
var exception = new ArgumentException("parameter");
properties = new List<LogEventProperty>
{
new LogEventProperty("Song", new ScalarValue("Old Macabre")),
new LogEventProperty("Complex", new ScalarValue(new { A = 1, B = 2}))
};
e = new LogEvent(timestamp.AddYears(-2), LogEventLevel.Fatal, exception, template, properties);
sink.Emit(e);
}
_seenHttpPosts.Should().NotBeEmpty().And.HaveCount(1);
var json = _seenHttpPosts.First();
var bulkJsonPieces = json.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
bulkJsonPieces.Should().HaveCount(4);
bulkJsonPieces[0].Should().Contain(@"""_index"":""logstash-information-2013.05.28");
bulkJsonPieces[1].Should().Contain("New Macabre");
bulkJsonPieces[2].Should().Contain(@"""_index"":""logstash-fatal-2011.05.28");
bulkJsonPieces[3].Should().Contain("Old Macabre");
//serilog by default simpy .ToString()'s unknown objects
bulkJsonPieces[3].Should().Contain("Complex\":\"{");
}
示例4: ChainedHeader
public ChainedHeader(BlockHeader blockHeader, int height, BigInteger totalWork, DateTimeOffset dateSeen)
{
BlockHeader = blockHeader;
Height = height;
TotalWork = totalWork;
DateSeen = dateSeen;
}
示例5: UsesCustomPropertyNames
public async Task UsesCustomPropertyNames()
{
try
{
await new HttpClient().GetStringAsync("http://i.do.not.exist");
}
catch (Exception e)
{
var timestamp = new DateTimeOffset(2013, 05, 28, 22, 10, 20, 666, TimeSpan.FromHours(10));
var messageTemplate = "{Song}++";
var template = new MessageTemplateParser().Parse(messageTemplate);
using (var sink = new ElasticsearchSink(_options))
{
var properties = new List<LogEventProperty>
{
new LogEventProperty("Song", new ScalarValue("New Macabre")),
new LogEventProperty("Complex", new ScalarValue(new { A = 1, B = 2 }))
};
var logEvent = new LogEvent(timestamp, LogEventLevel.Information, e, template, properties);
sink.Emit(logEvent);
logEvent = new LogEvent(timestamp.AddDays(2), LogEventLevel.Information, e, template, properties);
sink.Emit(logEvent);
}
_seenHttpPosts.Should().NotBeEmpty().And.HaveCount(1);
var json = _seenHttpPosts.First();
var bulkJsonPieces = json.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
bulkJsonPieces.Should().HaveCount(4);
bulkJsonPieces[0].Should().Contain(@"""_index"":""logstash-2013.05.28");
bulkJsonPieces[1].Should().Contain("New Macabre");
bulkJsonPieces[1].Should().NotContain("Properties\"");
bulkJsonPieces[1].Should().Contain("fields\":{");
bulkJsonPieces[1].Should().Contain("@timestamp");
bulkJsonPieces[2].Should().Contain(@"""_index"":""logstash-2013.05.30");
}
}
示例6: GetBuildDescription
internal static string GetBuildDescription(Build build, bool includeRefDescription, DateTimeOffset now)
{
if (build == null) throw new ArgumentNullException("build");
var @ref = "";
if (includeRefDescription)
@ref = String.Concat(" on ", GetRefDescription(build));
if (!build.Started.HasValue)
{
if (!build.Queued.HasValue)
return String.Format("Build #{0}{1} queued.", build.Id, @ref);
return String.Format("Build #{0}{1} queued {2} seconds ago.", build.Id, @ref, build.Queued.Value.Since(now));
}
if (!build.Finished.HasValue)
return String.Format("Build #{0}{1} started {2} seconds ago.", build.Id, @ref, build.Started.Value.Since(now));
if (!build.Succeeded.HasValue)
return String.Format("Build #{0}{1} finished in {2} seconds.", build.Id, @ref, build.Started.Value.Until(build.Finished.Value));
if (build.Succeeded.Value)
return String.Format("Build #{0}{1} succeeded in {2} seconds.", build.Id, @ref, build.Started.Value.Until(build.Finished.Value));
return String.Format("Build #{0}{1} failed in {2} seconds.", build.Id, @ref, build.Started.Value.Until(build.Finished.Value));
}
示例7: Syncronize
private void Syncronize()
{
lock (_stopwatch) {
_baseTime = DateTimeOffset.UtcNow;
_stopwatch.Restart();
}
}
示例8: GetHeartbeatMeasurementFromData
public static HeartbeatMeasurement GetHeartbeatMeasurementFromData(byte[] data, DateTimeOffset timeStamp)
{
// Heart Rate profile defined flag values
const byte HEART_RATE_VALUE_FORMAT = 0x01;
byte flags = data[0];
ushort HeartbeatMeasurementValue = 0;
if (((flags & HEART_RATE_VALUE_FORMAT) != 0))
{
HeartbeatMeasurementValue = (ushort)((data[2] << 8) + data[1]);
}
else
{
HeartbeatMeasurementValue = data[1];
}
DateTimeOffset tmpVal = timeStamp;
if (tmpVal == null)
{
tmpVal = DateTimeOffset.Now;
}
return new HeartbeatMeasurement
{
HeartbeatValue = HeartbeatMeasurementValue,
Timestamp = tmpVal
};
}
示例9: when_getting_now_as_datetimeoffset_should_return_the_mock_provider_now_as_datetimeoffset
public void when_getting_now_as_datetimeoffset_should_return_the_mock_provider_now_as_datetimeoffset()
{
var expectedDate = new DateTimeOffset(20.July(2015));
_mockProvider.NowAsDateTimeOffset.Returns(expectedDate);
TimeProvider.Current.NowAsDateTimeOffset.Should().Be(expectedDate);
}
示例10: IssueCommentItemViewModel
internal IssueCommentItemViewModel(string body, string login, string avatar, DateTimeOffset createdAt)
{
Comment = body;
Actor = login;
AvatarUrl = new GitHubAvatar(avatar);
CreatedAt = createdAt;
}
示例11: AbsoluteTimerWaitHandle
public AbsoluteTimerWaitHandle(DateTimeOffset dueTime)
{
_dueTime = dueTime;
_eventWaitHandle = new EventWaitHandle(false, EventResetMode.ManualReset);
SafeWaitHandle = _eventWaitHandle.SafeWaitHandle;
var dueSpan = (_dueTime - DateTimeOffset.Now);
var period = new TimeSpan(dueSpan.Ticks / 10);
if (dueSpan < TimeSpan.Zero)
{
_eventWaitHandle.Set();
}
else
{
_timer = new Timer(period.TotalMilliseconds)
{
AutoReset = false,
};
_timer.Elapsed += TimerOnElapsed;
_timer.Start();
}
}
示例12: Complete
public override void Complete(
string completedComments,
IEnumerable<CreateDocumentParameters> createDocumentParameterObjects,
IEnumerable<long> documentLibraryIdsToRemove,
UserForAuditing userForAuditing,
User user,
DateTimeOffset completedDate)
{
//Addition conditions for completeing a FurtherControlMeasureTask.
if (TaskStatus == TaskStatus.NoLongerRequired)
{
throw new AttemptingToCompleteFurtherControlMeasureTaskThatIsNotRequiredException();
}
if (!CanUserComplete(user))
{
throw new AttemptingToCompleteFurtherControlMeasureTaskThatTheUserDoesNotHavePermissionToAccess(Id);
}
base.Complete(
completedComments,
createDocumentParameterObjects,
documentLibraryIdsToRemove,
userForAuditing,
user,
completedDate);
}
示例13: TodayIsTheDayOfThe
private bool TodayIsTheDayOfThe(DateTime itineraryDate, string eventsTimeZoneId)
{
var timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(eventsTimeZoneId);
var utcOffset = timeZoneInfo.GetUtcOffset(itineraryDate);
var intineraryDateConvertedToEventsTimeZone = new DateTimeOffset(itineraryDate, utcOffset);
return (intineraryDateConvertedToEventsTimeZone.Date - DateTimeUtcNow().Date).TotalDays == 0;
}
开发者ID:stevejgordon,项目名称:allReady,代码行数:7,代码来源:SendRequestConfirmationMessagesTheDayOfAnItineraryDate.cs
示例14: LogEntry
private LogEntry(Object message, IEnumerable<String> categories, DateTimeOffset occurredOn, IDictionary<String, Object> auxiliaryProperties)
{
_Message = message;
_Categories = new ReadOnlyCollection<String>(categories.ToList());
_OccurredOn = occurredOn;
_AuxiliaryProperties = new ReadOnlyDictionary<String, Object>(auxiliaryProperties);
}
示例15: After
/// <summary>
/// Asserts that a <see cref="DateTime"/> occurs a specified amount of time after another <see cref="DateTime"/>.
/// </summary>
/// <param name="target">
/// The <see cref="DateTime"/> to compare the subject with.
/// </param>
/// <param name="reason">
/// A formatted phrase explaining why the assertion should be satisfied. If the phrase does not
/// start with the word <i>because</i>, it is prepended to the message.
/// </param>
/// <param name="reasonArgs">
/// Zero or more values to use for filling in any <see cref="string.Format(string,object[])"/> compatible placeholders.
/// </param>
public AndConstraint<DateTimeOffsetAssertions> After(DateTimeOffset target, string reason = "", params object[] reasonArgs)
{
bool success = Execute.Assertion
.ForCondition(subject.HasValue)
.BecauseOf(reason, reasonArgs)
.FailWith("Expected date and/or time {0} to be " + predicate.DisplayText +
" {1} after {2}{reason}, but found a <null> DateTime.",
subject, timeSpan, target);
if (success)
{
var actual = subject.Value.Subtract(target);
if (!predicate.IsMatchedBy(actual, timeSpan))
{
Execute.Assertion
.BecauseOf(reason, reasonArgs)
.FailWith(
"Expected date and/or time {0} to be " + predicate.DisplayText +
" {1} after {2}{reason}, but it differs {3}.",
subject, timeSpan, target, actual);
}
}
return new AndConstraint<DateTimeOffsetAssertions>(parentAssertions);
}