What day is today?

Jul 11, 2006 16:12


Is there any way to tell, programmatically, what Date or DateTime "today" or "now" are from within an S2 layer's code? I would dearly love to style today's entries slightly differently, but there doesn't seem to be anything in Core that returns a current timestamp.
How does one go about submitting feature requests for S2 Core, anyway?

Leave a comment

Comments 6

isabeau July 12 2006, 01:05:04 UTC
Not sure about the second thing, but as to the first-- "Page" class items have:

DateTime time A DateTime object filled with the time (GMT) when the page was created. (Read-only)

which you could then format in such a way as to compare the date with the date of the entry, or whatever. (Page-created time being 'today', more or less.)

Reply

ctate July 12 2006, 02:52:13 UTC
Oho, that's the closest you can get, I think. I somehow was thinking that the time a Page was created was when the *journal* was created, not the particular page rendering. Silly me.

The one unfortunate wrinkle, of course, is that the Page time is in GMT, but Entry times are user-specified and are generally in their own local time. Alas, alack. But this is darn close, thanks!

Reply

afuna July 13 2006, 06:57:35 UTC
I saw a Date::compare function in the core layer which could be used for comparing the date, but I can't seem to use it. Compiler complains that there's no such function, so I guess that leaves time/date-format + string comparison.

Reply

isabeau July 13 2006, 10:35:21 UTC
but I can't seem to use it

That's 'cause it only works with a Date class object -- both Date and DateTime have the compare function, but it only takes Date as an argument -- and both the Page::time and Entry::time are DateTime objects, not Dates.

(You could also do it with CSS instead of string comparison; that is, have the entry container HTML include class="$e.time->date_format("%%d%%%%m%%%%yy%%")" (er, you'd have to calculate the date format thingum outside of the string, and then do class="$date"), and have the page-generated CSS include the special instructions for things of class $p.time->date_format("%%d%%%%m%%%%yy%%") (again generating it outside the string)... but that's kind of silly when you can just compare the two formatted $.times. *grin*)

Reply


ctate July 15 2006, 05:33:06 UTC
What I wound up doing was this:

1) Writing a trivial are_same_day(DateTime a, DateTime b) function that returns a bool if two given DateTime objects refer to the same day, and...

2) Using a most excellent function called gmt_offset() that takes a GMT DateTime and various local timezone information as arguments, and returns a hash of various expressions of the time's local equivalent, as strings. The routine is by kunzite1 and can be found at http://www.livejournal.com/community/s2layers/13400.html

So now when I render the page, I convert Page::time to local using gmt_offset(), build a DateTime with the relevant bits of its output, then compare each entry's datestamp with that, shading the background as appropiate for a match or lack thereof.

Voila!

Reply


Leave a comment

Up