Ayende @ Rahien

My name is Oren Eini
Founder of Hibernating Rhinos LTD and RavenDB.
You can reach me by phone or email:


+972 52-548-6969

, @ Q c

Posts: 6,026 | Comments: 44,842

filter by tags archive

Extending SubText to report Future Posts

time to read 3 min | 449 words

Since I am making so much use of future posts recently, I decided that it would be interesting to have a sidebar that shows the future posts. The problem is that I really don’t want to mess around with SubText.

This is not a slight against SubText, it has served me well for a long time. It is simply that for what I wanted, the number of steps that I would have to go through is way too long:

  • Get the relevant source
  • Compile it on my machine
  • Figure out SubText’s architecture and where I should make my changes
  • Upload a new version of the blog engine

It is possible, but it just take too long. Moreover, it would most certainly break the next time that I would update SubText, because I would forget all about it.

But it is not the only way to get stuff done, however. Here is my solution:

Update: I actually had a bug here related to time zone handling, fixed now.

Update 2: I used the 3.5 TimeZone semantics for this, but my server is running 2.0, use an okay hack instead. And fixed potential issue with < & > in the titles.

<%@ Page Language="C#" %>
<%@ OutputCache Duration="60" VaryByParam="None" %>

<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Configuration" %>
string connectionString = ConfigurationManager.ConnectionStrings["subtextData"].ConnectionString;
using(SqlConnection connection = new SqlConnection(connectionString))
	using(SqlCommand cmd = connection.CreateCommand())
		cmd.CommandText = @"
select top 15 Id, DateSyndicated, Title from subtext_Content
where DateSyndicated > @nowIsrael
order by DateSyndicated
		DateTime nowIsrael = DateTime.UtcNow.AddHours(3);
		using(SqlDataReader reader = cmd.ExecuteReader())
			if(reader.HasRows == false)
				%><li>Queue is empty</li><%
				DateTime dateSyndicated = (DateTime)reader["DateSyndicated"];
				string title = (string) reader["Title"];
				string formattedSyndication;
				TimeSpan timeLeft = dateSyndicated - DateTime.Now;
				if (timeLeft.Days > 7)
					formattedSyndication = timeLeft.Days / 7 + " weeks " + timeLeft.Days % 7 + " days";
				else if (timeLeft.Days > 0)
					formattedSyndication = timeLeft.Days + " days";
				else if (timeLeft.Hours > 0)
					formattedSyndication = timeLeft.Hours + " hours";
				else if (timeLeft.Minutes > 0)
					formattedSyndication = timeLeft.Minutes + " minutes";
					formattedSyndication = "In a moment";
				<li><%= formattedSyndication %> <br /> <%= Server.HtmlEncode(title) %></li>

And then it was just a matter of changing the template to include the following JavaScript:


And that is it. It works, it is safe, it can’t really break anything, and it will probably survive blog upgrades.


Damien Guard

...until you put < in a title like "Using List <t correctly" ;-)



Line 20: TimeZoneInfo israelTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Israel Standard Time");

Line 21: DateTime nowIsrael = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, israelTimeZone);


Jan Willem B

nice that we can take a peek at the future post titles too :)

Ayende Rahien



But I had only 2 of those out of 4K+

Ian Nelson

Hmm, currently two posts are showing as appearing "In A Moment", and have been for several minutes.

Comment preview

Comments have been closed on this topic.


No future posts left, oh my!


  1. Technical observations from my wife (3):
    13 Nov 2015 - Production issues
  2. Production postmortem (13):
    13 Nov 2015 - The case of the “it is slow on that machine (only)”
  3. Speaking (5):
    09 Nov 2015 - Community talk in Kiev, Ukraine–What does it take to be a good developer
  4. Find the bug (5):
    11 Sep 2015 - The concurrent memory buster
  5. Buffer allocation strategies (3):
    09 Sep 2015 - Bad usage patterns
View all series


Main feed Feed Stats
Comments feed   Comments Feed Stats