Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Test date/time bug
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using System.Globalization; namespace Rextester { public class Program { public static void Main(string[] args) { // New issue //var dateMeeting = new DateTime(2018, 11, 27); Console.WriteLine("When MeetingDate the same as original and RaceDate should be the next day"); var dateMeeting = GetUtcDateTime("121218", "1400"); Console.WriteLine("DateMeeting should be: 12.12.2018 00:00:00, have: " + dateMeeting.Date); var raceDate = GetUtcDateTime(dateMeeting, "2000"); var raceDateLegacy = GetUtcDateTimeLegacy(dateMeeting.ToString("ddMMyy"), "2000"); Console.WriteLine("RaceDate should be: 13.12.2018 01:00:00, have: " + raceDate + ", legacy: " + raceDateLegacy + "\n\n"); Console.WriteLine("When MeetingDate is not the same as original and RaceDate shouldn't be the next day"); var dateMeeting2 = GetUtcDateTime("121218", "1900"); Console.WriteLine("DateMeeting should be: 13.12.2018 00:00:00, have: " + dateMeeting2.Date); var raceDate2 = GetUtcDateTime(dateMeeting2, "2000"); var raceDateLegacy2 = GetUtcDateTimeLegacy(dateMeeting2.ToString("ddMMyy"), "2000"); Console.WriteLine("RaceDate should be: 13.12.2018 01:00:00, have: " + raceDate2 + ", legacy: " + raceDateLegacy2 + "\n\n"); Console.WriteLine("When MeetingDate the same as original and RaceDate shouldn't be the next day"); var dateMeeting3 = GetUtcDateTime("121218", "1500"); Console.WriteLine("DateMeeting should be: 12.12.2018 00:00:00, have: " + dateMeeting3.Date); var raceDate3 = GetUtcDateTime(dateMeeting3, "1700"); var raceDateLegacy3 = GetUtcDateTimeLegacy(dateMeeting3.ToString("ddMMyy"), "1700"); Console.WriteLine("RaceDate should be: 12.12.2018 22:00:00, have: " + raceDate3 + ", legacy: " + raceDateLegacy3 + "\n\n"); } private static DateTime GetUtcDateTime(DateTime meetingDate, string time, bool timeWithSeconds = false) { var dateTimeFormat = timeWithSeconds ? "HHmmss" : "HHmm"; var temporaryDate = meetingDate; var timeInSpecificTimeZone = DateTime.ParseExact( ConvertTimeToCommonFormat(time), dateTimeFormat, CultureInfo.InvariantCulture); timeInSpecificTimeZone = ConvertToUtc(timeInSpecificTimeZone); var timeFromTrni = int.Parse(time.Substring(0, 2)); if(timeInSpecificTimeZone.Hour < timeFromTrni){ temporaryDate = temporaryDate.AddDays(1); } return new DateTime(temporaryDate.Year, temporaryDate.Month, temporaryDate.Day, timeInSpecificTimeZone.Hour, timeInSpecificTimeZone.Minute, timeInSpecificTimeZone.Second); } private static DateTime GetUtcDateTime(string date, string time, bool timeWithSeconds = false) { var dateTimeFormat = timeWithSeconds ? "ddMMyyHHmmss" : "ddMMyyHHmm"; var datetime = date + ConvertTimeToCommonFormat(time); var dateTimeInSpecificTimeZone = DateTime.ParseExact( datetime, dateTimeFormat, CultureInfo.InvariantCulture); return ConvertToUtc(dateTimeInSpecificTimeZone); } private static DateTime GetUtcDateTimeLegacy(string date, string time, bool timeWithSeconds = false) { var dateTimeFormat = timeWithSeconds ? "ddMMyyHHmmss" : "ddMMyyHHmm"; var datetime = date + ConvertTimeToCommonFormat(time); var resultTime = DateTime.ParseExact( datetime, dateTimeFormat, CultureInfo.InvariantCulture); resultTime = DateTime.SpecifyKind(resultTime, DateTimeKind.Utc); var tzi = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"); resultTime = resultTime.AddTicks(tzi.GetUtcOffset(DateTime.UtcNow).Ticks * -1); return resultTime; } public static DateTime ConvertToUtc(DateTime dateTimeInSpecificTimeZone){ var tzi = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"); return DateTime.SpecifyKind(dateTimeInSpecificTimeZone, DateTimeKind.Utc).AddTicks(tzi.GetUtcOffset(DateTime.UtcNow).Ticks * -1); } public static string ConvertTimeToCommonFormat(string time) { if (time.StartsWith("24")) { time = "00" + time.Substring(2); } return time; } } }
run
|
edit
|
history
|
help
1
Unity Character Controller Version 2
1 -5 6 x1=3 x2=2
RRR
cs002
otro
test
testing_editor
HelloWorld
test
054325462