Brain Teaser: You have 3 dates with 3 offsets, from 3 variables, how do you find the newest date, but without using IF?

using System;
using System.Linq;

public class Program
public static void Main()
//Uncomment to get a list of timezones.
//foreach(var tz in TimeZoneInfo.GetSystemTimeZones()){
//    Console.WriteLine(tz.Id);

//first, create base DateTime
DateTime dtAlaska = new DateTime(2015,4,15,12,00,00);

//second, use datet ime to calc timespan, or assume local and convert. We will get timespan.
TimeSpan tsAlaska = TimeZoneInfo.FindSystemTimeZoneById("Alaskan Standard Time")

//last, put it together
DateTimeOffset dtoAlaska = new DateTimeOffset(2015,4,15,12,00,00,tsAlaska);

DateTime dtPacific = new DateTime(2015,4,15,12,00,00);
TimeSpan tsPacific = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time")
DateTimeOffset dtoPacific = new DateTimeOffset(2015,4,15,12,00,00,tsPacific);

DateTime dtEastern = new DateTime(2015,4,15,12,00,00);
TimeSpan tsEastern = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")
DateTimeOffset dtoEastern = new DateTimeOffset(2015,4,15,12,00,00,tsEastern);

DateTimeOffset[] dtaCollection = new DateTimeOffset[]{dtoAlaska,dtoPacific,dtoEastern};
DateTimeOffset dtoMax = dtaCollection.Max();
This entry was posted in Brian's Code Extreme, C# and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s