oh my fucking god php is such a fucking trainwreck
in particular its date handling leaves QUITE A LOT to be desired
I mean there's also the big security hoobajoob but that's not the bit that's frustrating me at the moment
Discussion
oh my fucking god php is such a fucking trainwreck
in particular its date handling leaves QUITE A LOT to be desired
I mean there's also the big security hoobajoob but that's not the bit that's frustrating me at the moment
@fluffy Something like:
```php
$now = new DateTime();
$now->setTimezone(new DateTimeZone("America/Los_Angeles"));
echo $now->format("w");
```
@cthos I don't want to change it at the ini level, and yeah the datetime approach is what everything points me to but it's so annoying to have to do that to replace a one-line hack on a piece of code I wrote for a quick and dirty thing 25 years ago
@cthos anyway I ended up doing this anyway, just because why not
it's still stupid how difficult it was to find all the various fiddly little bits on how to do it though (thanks for writing the only concise example code I've come across btw)
out of desperation I asked Gemini and it gave answers which look correct but involve writing a LOT more code than should be necessary for this
okay to be fair the easy way I'd do this in Python would involve importing arrow but it'd still result in a nice simple oneliner
but gosh, so much of the php standard library is just a thin wrapper around the C standard library, with a little bit of jank-ass object conversion
this isn't even for a thing I care about per se, I was just surprised to learn that a thing I wrote like 20 years ago and occasionally glance at has been doing it based on gmtime this whole time, since I usually only look at it in the morning
@fluffy
The webserver likely isn't in anybody's timezone so its locale stuff is going to be wrong for 24/25ths of the globe.
Turn it to a time_t and feed it to js on the client side and it might even show up in their language for free!
(Sorry for the "just don't do that then")
@EndlessMason this is for a personal non-public thing and the webserver is in the target audience's time zone (i.e. mine)
@EndlessMason also the whole thing is just a quick hack, as are most things written in PHP, and it's emitting a CSS rule based on the day of the week
@fluffy
Oh, div class=is-visible-tuesday?
@EndlessMason sorta, basically I have columns for the days of the week with classes like day-0, day-1, etc. and then a CSS rule that's just:
day-<?=date("w")?> { background: yellow; }
@EndlessMason this was for a thing that I used for my "daily website checks" thing that I don't actually use anymore and it's easier for me to just stop using it because everything I follow either has an RSS feed or is sufficiently transitory that I don't actually care about keeping up with it
searching stackoverflow only finds things that are either wildly incorrect or answering a completely different question (often a different question than what's being asked too)
all I'm trying to do is get the numeric day of the week in the local timezone
date("W") goes based on GMT or needs a UNIX timestamp in localtime
localtime() returns a structured datetime array and I don't see any way to convert that into a UNIX timestamp
I don't see any way to do date formatting based on a datetime array
what a miserable fucking language