this post was submitted on 24 Aug 2025
456 points (98.9% liked)

Programmer Humor

25958 readers
903 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] _stranger_@lemmy.world 33 points 1 day ago* (last edited 1 day ago) (2 children)

Ok, everyone who's ever had to use datetime hates it, but not because it's insufficient, but because international date/time is such a nightmare that the library must be complicated enough to support all the edge cases I'm convinced that library has a function for traveling trough time.

For years I've wrapped datetime with custom functions that do exactly and only what I want to mitigate its all-plumbing-zero-porcelain approach to the problem.

[–] raman_klogius@ani.social 3 points 17 hours ago (1 children)
[–] Alaknar@sopuli.xyz 1 points 10 hours ago

This is exactly why I love PowerShell.

Need the [DateTime] object from 10 years ago? No biggie, just chuck (Get-Date).AddYears(-10) down your console.

Need it in a specific timezone? That one's trickier, but since PowerShell can do .Net, run this:

$TargetDateTime = (Get-Date).AddYears(-10)
$TargetTimeZone = "India Standard Time"
$tz = [TimeZoneInfo]::FindSystemTimeZoneById($TargetTimeZone)
$utcOffset = $tz.GetUtcOffset($TargetDateTime)
[DateTimeOffset]::new($TargetDateTime.Ticks, $utcOffset)

And you get a DateTimeOffset object, which is this beauty:

DateTime           : 25/08/2015 23:15:14
UtcDateTime        : 25/08/2015 17:45:14
LocalDateTime      : 25/08/2015 19:45:14
Date               : 25/08/2015 00:00:00
Day                : 25
DayOfWeek          : Tuesday
DayOfYear          : 237
Hour               : 23
Millisecond        : 421
Microsecond        : 428
Nanosecond         : 600
Minute             : 15
Month              : 8
Offset             : 05:30:00
TotalOffsetMinutes : 330
Second             : 14
Ticks              : 635761413144214286
UtcTicks           : 635761215144214286
TimeOfDay          : 23:15:14.4214286
Year               : 2015

DateTime is the time in your target timezone, UtcDateTime is, well, the UTC time, and LocalDateTime is the time on host you ran the commands on.

[–] ripcord@lemmy.world 8 points 1 day ago* (last edited 1 day ago) (1 children)

Complicated or not, the interfaces suck. And dont have to. And that's the problem.

[–] _stranger_@lemmy.world 4 points 1 day ago

exactly why I wrap the parts I need, it's like git, tons of power, zero help.