OJ's rants

It's not about you, it's about the software

WTF: Date Malarky

| Comments

I don’t think I’m going to need to say much about the following code, as anyone with even an inkling of the features of the .NET framework would know that it’s a joke. See the nugget(s) of genius below:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
public static void ToStartofCurrDay(ref DateTime aDate)
{
  aDate = aDate.Subtract(aDate.TimeOfDay);
}

public static void ToEndofPrevDay(ref DateTime aDate)
{
  aDate = aDate.Subtract(aDate.TimeOfDay);
  TimeSpan ts = new TimeSpan(1);
  aDate = aDate.Subtract(ts);
}

public static void ToEndofCurrDay(ref DateTime aDate)
{
  aDate = aDate - aDate.TimeOfDay;
  aDate = aDate.AddHours(23);
  aDate = aDate.AddMinutes(59);
  aDate = aDate.AddSeconds(59);
  aDate = aDate.AddMilliseconds(999);
}

The thing that annoys me about this is that it was written by the lead/architect! The man who should know the framework like the back of his hand. Scary stuff. It’s this kind of thing that inspired my comments about “knowing your tech” in my post about the day job.

Comments