Monday, November 08, 2010 at 12:05 AM.

on getLastPostBeforeDate (adrblog, d, adrAdrPost, catname=nil) {
		<<11/14/01; 9:18:46 PM by JES
			<<Added optional catname parameter, used to restrict the search to a given category.
		<<2/25/01; 5:10:58 PM by PBS
			<<This script sometimes returned false when there was indeed a post before the date specified -- in the case where there was no post after the date specified. Now this is handled in the else block.
		<<2/22/01; 9:44:16 PM by PBS
			<<Created. Much like radio.weblog.getNextPostAfterDate, except that it gets the last post before a date. This code was getting duplicated often.
	local (adrPost);
	on findPrevPost (ixpost, adradrpost) {
		local (adrpost = @adrblog^.posts[ixpost]);
		if catname == nil {
			adrAdrPost^ = adrpost;
			return (true)}
		else { //category
			loop {
				if radio.weblog.isPostInCategory (adrpost, catname) {
					adradrpost^ = adrpost;
					return (true)};
				if ixpost == 0 {
				adrpost = @adrblog^.posts[ixpost]}};
		return (false)};
	if radio.weblog.getNextPostAfterDate (adrblog, d, @adrPost, catname) {
		local (ixPost = indexOf (adrPost^));
		if ixPost > 1 {
			if findPrevPost (ixpost - 1, @adrpost) {
				adradrpost^ = adrpost;
				return (true)}}}
	else { //PBS 02/25/01: it's the last post in the posts table [which is in the category]
		local (sizeTable = sizeOf (adrblog^.posts));
		if sizeTable > 0 {
			if findPrevPost (sizetable, @adrpost) {
				adradrpost^ = adrpost;
				return (true)}}};
	return (false)}
<<bundle //debugging
	<<local (adrpost)
	<<getLastPostBeforeDate (radio.weblog.init (), (), @adrpost, "quotations")
	<<dialog.notify (adrpost)

This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.