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

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

afuna July 13 2006, 16:34:33 UTC
It should be able to handle it, I think, since DateTime extends Date. Comment string (what do you call that little explaining thing?) specifically mentions that the time portion of DateTime will default to midnight when compared with a Date.

I think S2 automatically handles it even when you're passing as a parameter (example is Page p which is usually passed to print_entry, or what Bloggish does with EntryLite/Entry/Comment. Um, what does Bloggish do? No need to answer that XP)

Off on a tangent there...

Ah, yes, I did try casting it to a Date using the as keyword, and it worked, but the compiler still complained even when both the caller and the parameter were of type Date (was reflected in the error message ( ... )

Reply


Leave a comment

Up