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
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
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
Reply
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
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