Quick actions

cmd+k|ctrl+k

Navigation

Languages

ForecastVerification Local Date to RunDateTime Window

Snippet info

Language

Csharp

Visibility

public

Author

isobit

Created

2018-03-14T18:37:49Z

Updated

2018-03-19T21:16:51Z

using System;
using System.Globalization;
using System.Threading;

class MainClass {
    static void Main() {
        CultureInfo standardizedCulture = (CultureInfo)CultureInfo.CurrentCulture.Clone();
        standardizedCulture.DateTimeFormat.DateSeparator = "-";
        standardizedCulture.DateTimeFormat.LongDatePattern = "yyyy-MM-dd hh:mm:ss";
        standardizedCulture.DateTimeFormat.FullDateTimePattern = "yyyy-MM-dd hh:mm:ss";           
        standardizedCulture.DateTimeFormat.ShortDatePattern  = "yyyy-MM-dd"; 
        Thread.CurrentThread.CurrentCulture = standardizedCulture;
        Thread.CurrentThread.CurrentUICulture = standardizedCulture;
        
        
        var localDate = new DateTime(2018, 03, 18);
        Console.WriteLine($"Local Date = {localDate}");
        
        var tzOffset = new TimeSpan(-5, 0, 0);
        Console.WriteLine($"Timezone Offset = {tzOffset}");
        
        var dto = new DateTimeOffset(localDate, tzOffset);
        Console.WriteLine($"Start of Day, Local = {dto}");
        Console.WriteLine($"Start of Day, UTC   = {dto.ToUniversalTime()}");
        
        var fcstTimeSpan = new TimeSpan(15, 0, 0, 0);
        Console.WriteLine($"Forecast Time Span = {fcstTimeSpan}");
        
        var start = localDate.Add(-tzOffset);
        var end = start.AddDays(1);
        Console.WriteLine($"ValidDateTime Window               = [{start}, {end})");
        Console.WriteLine($"RunDateTime   Window               = [{end-fcstTimeSpan}, {start})");
        
        start = start.AddHours(-1);
        end = end.AddHours(1);
        Console.WriteLine($"ValidDateTime Window (with buffer) = [{start}, {end})");
        Console.WriteLine($"RunDateTime   Window (with buffer) = [{end-fcstTimeSpan}, {start})");
    }
}
INFO