public ChannelMessage(string id, DateTimeOffset when, string userName, string content) { this.Id = id; this.When = when.ToLocalTime(); this.User = userName; this.Content = content; }
public MeMessage(DateTimeOffset when, string userName, string content) { this.Content = content; this.When = when.ToLocalTime(); this.Time = this.When.ToString("h:mm:ss tt"); this.User = userName; }
/// <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; }
public static XElement TIME(string name, DateTimeOffset time) { var t1 = time.ToUniversalTime(); var t2 = time.ToLocalTime().ToString("G"); return new XElement( XN.time, PROP(name), new XAttribute(XN.datetime, t1), t2); }
public DateTimeOffset ScheduleNextTime(DateTimeOffset currentTime, JobExecutionRecord lastExecution) { var localTime = currentTime.ToLocalTime(); var oneAmToday = new DateTime(localTime.Year, localTime.Month, localTime.Day, _hour, _minute, 0, 0, DateTimeKind.Local); var nextScheduledTime = oneAmToday; if (localTime.Hour > _hour || (localTime.Hour == _hour && localTime.Minute >= _minute)) { // Switch to tomorrow nextScheduledTime = oneAmToday.AddDays(1); } return nextScheduledTime.ToUniversalTime(); }
public static string OffsetUtc(DateTimeOffset time) { if (time == default(DateTimeOffset)) return ""; var now = DateTimeOffset.UtcNow; var offset = now - time; if (Math.Abs(offset.TotalDays) > 7) { return time.ToLocalTime().ToString("MMMM dd, yyyy", CultureInfo.InvariantCulture); } if (offset > TimeSpan.Zero) { return PositiveTimeSpan(offset) + " ago"; } return PositiveTimeSpan(-offset) + " from now"; }
public static void ToLocalTime() { DateTimeOffset dateTimeOffset = new DateTimeOffset(new DateTime(1000, DateTimeKind.Utc)); Assert.Equal(new DateTimeOffset(dateTimeOffset.UtcDateTime.ToLocalTime()), dateTimeOffset.ToLocalTime()); }
private static int Main(string[] args) { CommandLineParser clp = new CommandLineParser(); clp.AddKnownOption("a", "assembly-info"); clp.AddKnownOption("", "test-b36min"); clp.AddKnownOption("b", "test-bmin"); clp.AddKnownOption("f", "format", true); clp.AddKnownOption("h", "help"); clp.AddKnownOption("i", "ignore-missing"); clp.AddKnownOption("m", "multi-project"); clp.AddKnownOption("r", "revision"); clp.AddKnownOption("s", "restore"); clp.AddKnownOption("v", "version"); clp.AddKnownOption("x", "test-xmin"); clp.AddKnownOption("B", "de-bmin"); clp.AddKnownOption("", "de-b36min"); clp.AddKnownOption("D", "de-dmin"); clp.AddKnownOption("I", "only-infver"); clp.AddKnownOption("M", "stop-if-modified"); clp.AddKnownOption("X", "de-xmin"); clp.AddKnownOption("", "debug"); debugOutput = clp.IsOptionSet("debug"); if (clp.IsOptionSet("h") || clp.IsOptionSet("v")) { HandleHelp(clp.IsOptionSet("h")); return 0; } if (clp.IsOptionSet("X")) { int baseYear; if (!int.TryParse(clp.GetArgument(0), out baseYear)) { Console.Error.WriteLine("Invalid argument: Base year expected"); return 1; } string xmin = clp.GetArgument(1).Trim().ToLowerInvariant(); DateTime time = DehexMinutes(baseYear, xmin); if (time == DateTime.MinValue) { Console.Error.WriteLine("Invalid xmin value."); return 0; } Console.WriteLine(time.ToString("yyyy-MM-dd HH:mm") + " UTC"); Console.WriteLine(time.ToLocalTime().ToString("yyyy-MM-dd HH:mm K")); return 0; } if (clp.IsOptionSet("B")) { int baseYear; if (!int.TryParse(clp.GetArgument(0), out baseYear)) { Console.Error.WriteLine("Invalid argument: Base year expected"); return 1; } string bmin = clp.GetArgument(1).Trim().ToLowerInvariant(); DateTime time = Debase28Minutes(baseYear, bmin); if (time == DateTime.MinValue) { Console.Error.WriteLine("Invalid bmin value."); return 0; } Console.WriteLine(time.ToString("yyyy-MM-dd HH:mm") + " UTC"); Console.WriteLine(time.ToLocalTime().ToString("yyyy-MM-dd HH:mm K")); return 0; } if (clp.IsOptionSet("de-b36min")) { int baseYear; if (!int.TryParse(clp.GetArgument(0), out baseYear)) { Console.Error.WriteLine("Invalid argument: Base year expected"); return 1; } string bmin = clp.GetArgument(1).Trim().ToLowerInvariant(); DateTime time = Debase36Minutes(baseYear, bmin); if (time == DateTime.MinValue) { Console.Error.WriteLine("Invalid b36min value."); return 0; } Console.WriteLine(time.ToString("yyyy-MM-dd HH:mm") + " UTC"); Console.WriteLine(time.ToLocalTime().ToString("yyyy-MM-dd HH:mm K")); return 0; } if (clp.IsOptionSet("D")) { int baseYear; if (!int.TryParse(clp.GetArgument(0), out baseYear)) { Console.Error.WriteLine("Invalid argument: Base year expected"); return 1; } string dmin = clp.GetArgument(1).Trim(); DateTime time = DedecMinutes(baseYear, dmin); if (time == DateTime.MinValue) { Console.Error.WriteLine("Invalid dmin value."); return 0; } Console.WriteLine(time.ToString("yyyy-MM-dd HH:mm") + " UTC"); Console.WriteLine(time.ToLocalTime().ToString("yyyy-MM-dd HH:mm K")); return 0; } if (clp.IsOptionSet("x")) { int baseYear; if (!int.TryParse(clp.GetArgument(0), out baseYear)) { Console.Error.WriteLine("Invalid argument: Base year expected"); return 1; } revTime = DateTime.UtcNow; long ticks1min = TimeSpan.FromMinutes(1).Ticks; revTime = new DateTime(revTime.Ticks / ticks1min * ticks1min, DateTimeKind.Utc); for (int i = 0; i < 10; i++) { Console.WriteLine(revTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm K") + " = " + HexMinutes(baseYear, 1)); revTime = revTime.AddMinutes(1); } return 0; } if (clp.IsOptionSet("b")) { int baseYear; if (!int.TryParse(clp.GetArgument(0), out baseYear)) { Console.Error.WriteLine("Invalid argument: Base year expected"); return 1; } revTime = DateTime.UtcNow; long ticks20min = TimeSpan.FromMinutes(20).Ticks; revTime = new DateTime(revTime.Ticks / ticks20min * ticks20min, DateTimeKind.Utc); for (int i = 0; i < 10; i++) { Console.WriteLine(revTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm K") + " = " + Base28Minutes(baseYear, 1)); revTime = revTime.AddMinutes(20); } return 0; } if (clp.IsOptionSet("test-b36min")) { int baseYear; if (!int.TryParse(clp.GetArgument(0), out baseYear)) { Console.Error.WriteLine("Invalid argument: Base year expected"); return 1; } revTime = DateTime.UtcNow; long ticks10min = TimeSpan.FromMinutes(10).Ticks; revTime = new DateTime(revTime.Ticks / ticks10min * ticks10min, DateTimeKind.Utc); for (int i = 0; i < 10; i++) { Console.WriteLine(revTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm K") + " = " + Base36Minutes(baseYear, 1)); revTime = revTime.AddMinutes(10); } return 0; } buildTime = DateTimeOffset.Now; bool patchAssemblyInfoFile = clp.IsOptionSet("a"); bool restoreAssemblyInfoFile = clp.IsOptionSet("s"); multiProjectMode = clp.IsOptionSet("m"); bool showRevision = clp.IsOptionSet("r"); bool stopIfModified = clp.IsOptionSet("M"); bool ignoreMissing = clp.IsOptionSet("i"); onlyInformationalVersion = clp.IsOptionSet("I"); string path = clp.GetArgument(0); string customFormat = "{!}{commit}"; if (clp.IsOptionSet("f")) customFormat = clp.GetOptionValue("f"); if (!patchAssemblyInfoFile && !restoreAssemblyInfoFile && !showRevision) showRevision = true; // Default action if (string.IsNullOrEmpty(path)) path = "."; if (debugOutput) Console.Error.WriteLine("Working on path " + path); bool hasProcessed = false; List<string> projectDirs = new List<string>(); if (multiProjectMode) { // Treat the single directory argument as the solution file name if (!path.ToLowerInvariant().EndsWith(".sln")) { Console.Error.WriteLine("Error: Specified file name is invalid. Only *.sln files accepted in\nmulti-project mode."); return 1; } if (!File.Exists(path)) { Console.Error.WriteLine("Error: Specified solution file does not exist."); return 1; } // Scan the solution file for projects and add them to the list string solutionDir = Path.GetDirectoryName(path); using (StreamReader sr = new StreamReader(path)) { while (!sr.EndOfStream) { string line = sr.ReadLine(); Match m = Regex.Match(line, @"^Project\(.+\) = "".+"", ""(.+\.(?:csproj|vbproj))"""); if (m.Success) { string projectPath = Path.Combine(solutionDir, m.Groups[1].Value); string projectDir = Path.GetDirectoryName(projectPath); if (debugOutput) Console.Error.WriteLine("Add project in " + projectDir); projectDirs.Add(projectDir); } } } if (projectDirs.Count == 0) { Console.Error.WriteLine("Error: Specified solution file contains no projects."); return 1; } // From now on, work with the solution directory as default path to get the revision of path = solutionDir; } if (patchAssemblyInfoFile) { if (!hasProcessed) { ProcessDirectory(path, ignoreMissing, true); if (revision == 0) { if (ignoreMissing) { revTime = DateTimeOffset.Now; } else { Console.Error.WriteLine("Error: Not a Subversion working directory."); return 1; } } hasProcessed = true; } if (stopIfModified && isModified) { Console.Error.WriteLine("Error: Subversion working directory contains uncommited changes, stop requested by option."); return 1; } if (multiProjectMode) { bool success = true; foreach (string projectDir in projectDirs) { success &= PatchAssemblyInfoFile(projectDir); } if (!success) { return 1; } } else { if (!PatchAssemblyInfoFile(path)) { return 1; } } } if (restoreAssemblyInfoFile) { if (multiProjectMode) { bool success = true; foreach (string projectDir in projectDirs) { success &= RestoreAssemblyInfoFile(projectDir); } if (!success) { return 1; } } else { if (!RestoreAssemblyInfoFile(path)) { return 1; } } } if (showRevision) { if (!hasProcessed) { ProcessDirectory(path, ignoreMissing, true); if (revision == 0) { if (ignoreMissing) { revTime = DateTimeOffset.Now; } else { Console.Error.WriteLine("Error: Not a Subversion working directory."); return 1; } } hasProcessed = true; } Console.WriteLine(ResolveFormat(customFormat)); } return 0; }
public static string GenerateHeader(string authorName, string authorFullEmail,string authoredAge, DateTimeOffset authorTime, string committerName, string committerFullEmail,string commitedAge, DateTimeOffset commitTime, Guid commitGuid) { var authorField =GenerateHeaderField( Strings.GetAuthorText()); var authorDateField=GenerateHeaderField(Strings.GetAuthorDateText()); var committerField = GenerateHeaderField(Strings.GetCommitterText()); var commitDate = GenerateHeaderField(Strings.GetCommitDateText()); var commitHashField = GenerateHeaderField(Strings.GetCommitHashText()); var authorEmail = GetEmail(authorFullEmail); var committerEmail = GetEmail(committerFullEmail); var expectedHeader = authorField + "<a href='mailto:" + HttpUtility.HtmlAttributeEncode(authorEmail) + "'>" + HttpUtility.HtmlEncode(authorFullEmail) + "</a>" + Environment.NewLine + authorDateField + authoredAge + " (" + authorTime.ToLocalTime().ToString("ddd MMM dd HH':'mm':'ss yyyy") + ")" + Environment.NewLine + committerField + "<a href='mailto:" + HttpUtility.HtmlAttributeEncode(committerEmail) + "'>" + HttpUtility.HtmlEncode(committerFullEmail) + "</a>" + Environment.NewLine + commitDate+commitedAge+" (" + commitTime.ToLocalTime().ToString("ddd MMM dd HH':'mm':'ss yyyy") + ")" + Environment.NewLine + commitHashField + commitGuid; return expectedHeader; }
internal static DateTimeOffset GetLastAccessTime(string path) { string str = LongPath.NormalizePath(path); new FileIOPermission(FileIOPermissionAccess.Read, new string[] { str }, false, false).Demand(); string str2 = Path.AddLongPathPrefix(str); Win32Native.WIN32_FILE_ATTRIBUTE_DATA data = new Win32Native.WIN32_FILE_ATTRIBUTE_DATA(); int errorCode = File.FillAttributeInfo(str2, ref data, false, false); if (errorCode != 0) { __Error.WinIOError(errorCode, str); } long fileTime = (data.ftLastAccessTimeHigh << 0x20) | data.ftLastAccessTimeLow; DateTimeOffset offset = new DateTimeOffset(DateTime.FromFileTimeUtc(fileTime).ToLocalTime()); return offset.ToLocalTime(); }
public NotificationMessage(DateTimeOffset when, string content) { this.When = when.ToLocalTime(); this.Time = this.When.ToString("h:mm:ss tt"); this.Content = content; }
public DateTimeOffset GetLastWriteTime(string path) { if (path == null) { throw new ArgumentNullException("path"); } if (path.Trim().Length == 0) { throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath"), "path"); } if (this.m_bDisposed) { throw new ObjectDisposedException(null, Environment.GetResourceString("IsolatedStorage_StoreNotOpen")); } if (this.m_closed) { throw new InvalidOperationException(Environment.GetResourceString("IsolatedStorage_StoreNotOpen")); } this.m_fiop.Assert(); this.m_fiop.PermitOnly(); string str2 = LongPath.NormalizePath(this.GetFullPath(path)); try { Demand(new FileIOPermission(FileIOPermissionAccess.Read, new string[] { str2 }, false, false)); } catch { DateTimeOffset offset3 = new DateTimeOffset(0x641, 1, 1, 0, 0, 0, TimeSpan.Zero); return offset3.ToLocalTime(); } DateTimeOffset lastWriteTime = LongPathFile.GetLastWriteTime(str2); CodeAccessPermission.RevertAll(); return lastWriteTime; }
public void OldEraToLocalTime () { TimeSpan offset = TimeSpan.Zero; var dto = new DateTimeOffset (new DateTime (1900, 1, 1).Ticks, offset); // Should never throw dto.ToLocalTime (); }
private DateTimeOffset CreateCalendarTime(DateTimeOffset dateTime) { return dateTime.ToLocalTime(); }
/// <summary> /// Returns the next time at which the <see cref="IDailyTimeIntervalTrigger" /> will /// fire, after the given time. If the trigger will not fire after the given /// time, <see langword="null" /> will be returned. /// </summary> /// <param name="afterTime"></param> /// <returns></returns> public override DateTimeOffset? GetFireTimeAfter(DateTimeOffset? afterTime) { // Check if trigger has completed or not. if (complete) { return null; } // Check repeatCount limit if (repeatCount != RepeatIndefinitely && timesTriggered > repeatCount) { return null; } // a. Increment afterTime by a second, so that we are comparing against a time after it! if (afterTime == null) { afterTime = SystemTime.UtcNow().AddSeconds(1); } else { afterTime = afterTime.Value.AddSeconds(1); } // now change to local time zone afterTime = afterTime.Value.ToLocalTime(); // b.Check to see if afterTime is after endTimeOfDay or not. // If yes, then we need to advance to next day as well. bool afterTimePassEndTimeOfDay = false; if (endTimeOfDay != null) { afterTimePassEndTimeOfDay = afterTime.Value > endTimeOfDay.GetTimeOfDayForDate(afterTime).Value; } DateTimeOffset? fireTime = AdvanceToNextDayOfWeek(afterTime.Value, afterTimePassEndTimeOfDay); if (fireTime == null) { return null; } // c. Calculate and save fireTimeEndDate variable for later use DateTimeOffset fireTimeEndDate; if (endTimeOfDay == null) { fireTimeEndDate = new TimeOfDay(23, 59, 59).GetTimeOfDayForDate(fireTime).Value; } else { fireTimeEndDate = endTimeOfDay.GetTimeOfDayForDate(fireTime).Value; } // e. Check fireTime against startTime or startTimeOfDay to see which go first. DateTimeOffset fireTimeStartDate = startTimeOfDay.GetTimeOfDayForDate(fireTime).Value; if (fireTime < startTimeUtc && startTimeUtc < fireTimeStartDate) { return fireTimeStartDate; } else if (fireTime < startTimeUtc && startTimeUtc > fireTimeStartDate) { return startTimeUtc; } else if (fireTime > startTimeUtc && fireTime < fireTimeStartDate) { return fireTimeStartDate; } // Always adjust the startTime to be startTimeOfDay startTimeUtc = fireTimeStartDate.ToUniversalTime(); // f. Continue to calculate the fireTime by incremental unit of intervals. long secondsAfterStart = (long) (fireTime.Value - startTimeUtc.ToLocalTime()).TotalSeconds; long repeatLong = RepeatInterval; DateTimeOffset sTime = startTimeUtc.ToLocalTime(); IntervalUnit repeatUnit = RepeatIntervalUnit; if (repeatUnit == IntervalUnit.Second) { long jumpCount = secondsAfterStart/repeatLong; if (secondsAfterStart%repeatLong != 0) { jumpCount++; } sTime = sTime.AddSeconds(RepeatInterval*(int) jumpCount); fireTime = sTime; } else if (repeatUnit == IntervalUnit.Minute) { long jumpCount = secondsAfterStart/(repeatLong*60L); if (secondsAfterStart%(repeatLong*60L) != 0) { jumpCount++; } sTime = sTime.AddMinutes(RepeatInterval*(int) jumpCount); fireTime = sTime; } else if (repeatUnit == IntervalUnit.Hour) { long jumpCount = secondsAfterStart/(repeatLong*60L*60L); if (secondsAfterStart%(repeatLong*60L*60L) != 0) { jumpCount++; } sTime = sTime.AddHours(RepeatInterval*(int) jumpCount); fireTime = sTime; } // g. Ensure this new fireTime is within one day, or else we need to advance to next day. if (fireTime > fireTimeEndDate) { // Check to see if fireTime has pass fireTime's end of day. If not, we need to advance by one day. DateTimeOffset fireTimeEndOfDay = new TimeOfDay(23, 59, 59).GetTimeOfDayForDate(fireTimeEndDate).Value; if (fireTime > fireTimeEndOfDay) { fireTime = AdvanceToNextDayOfWeek(fireTime.Value, false); } else { fireTime = AdvanceToNextDayOfWeek(fireTime.Value, true); } if (fireTime == null) { return null; } // Check to see if next day fireTime is before startTimeOfDay, if not, we need to set to startTimeOfDay. DateTimeOffset nextDayfireTimeStartDate = StartTimeOfDay.GetTimeOfDayForDate(fireTime).Value; if (fireTime < nextDayfireTimeStartDate) { fireTime = nextDayfireTimeStartDate; } } // i. Return calculated fireTime. return fireTime.Value.ToUniversalTime(); }
/// <summary> /// Gets the statistical information /// </summary> /// <param name="totalCasesNum">The number of total cases</param> /// <param name="passedNum">The number of passed cases</param> /// <param name="failedNum">The number of failed cases</param> /// <param name="testRunStartTime">The start time of the run</param> /// <param name="testRunEndTime">The end time of the run</param> /// <returns>Return statistical information about this test</returns> public string SummaryTable(long totalCasesNum, long passedNum, long failedNum, DateTimeOffset testRunStartTime, DateTimeOffset testRunEndTime) { DataType.RunSummary sry = new DataType.RunSummary() { TotalCount = totalCasesNum, FailedCount = failedNum, PassedCount = passedNum, InconclusiveCount = totalCasesNum - passedNum - failedNum, PassRate = totalCasesNum == 0 ? 0 : (float)passedNum * 100 / totalCasesNum, StartTime = testRunStartTime.ToLocalTime().ToString("MM/dd/yyyy HH:mm:ss"), EndTime = testRunEndTime.ToLocalTime().ToString("MM/dd/yyyy HH:mm:ss"), Duration = testRunEndTime.Subtract(testRunStartTime).ToString(@"hh\:mm\:ss") }; return (serializer.Serialize(sry)); }
/// <summary> /// Determine whether the given time (in milliseconds) is 'included' by the /// Calendar. /// <para> /// Note that this Calendar is only has full-day precision. /// </para> /// </summary> /// <param name="timeUtc"></param> /// <returns></returns> public override bool IsTimeIncluded(DateTimeOffset timeUtc) { DateTimeOffset localTime = timeUtc.ToLocalTime(); return base.IsTimeIncluded(localTime); }
public void RunAsync(bool isRerun, DateTimeOffset firstRunTimestamp, Action<string> callback) { new Thread(() => { string outputMessage = _outputMessage; #region temporal analysis for rerun if (isRerun && !string.IsNullOrWhiteSpace(_outputMessageRerun)) { TimeSpan promptAge = DateTimeOffset.UtcNow - firstRunTimestamp; int daysAgo = (int)promptAge.TotalDays; string daysAgoStr; if (daysAgo == 0) daysAgoStr = "today"; else if (daysAgo == 1) daysAgoStr = "yesterday"; else daysAgoStr = promptAge.TotalDays + " days ago"; outputMessage = string.Format(_outputMessageRerun, daysAgoStr + " at " + firstRunTimestamp.ToLocalTime().DateTime.ToString("h:mm tt")); } #endregion SensusServiceHelper.Get().TextToSpeechAsync(outputMessage, () => { SensusServiceHelper.Get().RunVoicePromptAsync(outputMessage, response => { Viewed = true; if (string.IsNullOrWhiteSpace(response)) response = null; _response = response; Complete = _response != null; callback(_response); }); }); }).Start(); }
private string GetTimeString(DateTimeOffset date) { date = date.ToLocalTime(); DateTimeOffset today = DateTimeOffset.Now; if (today.Date == date.Date) return "at " + date.ToString("HH:mm"); else if (today.Date.Subtract(new TimeSpan(6, 0, 0, 0)) <= date) return "on " + date.ToString("ddd, HH:mm"); else return "on " + date.ToString("dd MMM, HH:mm"); }
private static string ConvertTime(DateTimeOffset time) { if (time == DateTimeOffset.MinValue) return "n/a"; return time.ToLocalTime().ToString("s").Replace("T", " "); }