Skip to content

Commit

Permalink
Fixed an issue with posting future blog posts
Browse files Browse the repository at this point in the history
  • Loading branch information
haacked committed Jan 2, 2012
1 parent ba5ff5d commit ee73a35
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/Subtext.Framework/Data/DataHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
using Subtext.Extensibility.Interfaces;
using Subtext.Framework.Components;
using Subtext.Framework.Configuration;
using Subtext.Framework.Util;

//Need to remove Global.X calls ...just seems unclean
//Maybe create a another class formatter ...Format.Entry(ref Entry entry)
Expand Down Expand Up @@ -95,7 +96,7 @@ public static T ReadObject<T>(this IDataReader reader, T item, params string[] e
{
if (value != null && value.GetType() == typeof(DateTime) && property != null && property.Name != null && property.Name.EndsWith("Utc", StringComparison.OrdinalIgnoreCase))
{
property.SetValue(item, new DateTime(((DateTime)value).Ticks, DateTimeKind.Utc));
property.SetValue(item, ((DateTime)value).AsUtc());
continue;
}

Expand Down Expand Up @@ -130,8 +131,7 @@ public static T ReadObject<T>(this IDataReader reader, T item, params string[] e

public static DateTime ReadDateTimeUtc(this IDataReader reader, string columnName)
{
var dateTime = reader.ReadValue<DateTime>(columnName);
return new DateTime(dateTime.Ticks, DateTimeKind.Utc);
return reader.ReadValue<DateTime>(columnName).AsUtc();
}

public static T ReadValue<T>(this IDataReader reader, string columnName)
Expand Down
3 changes: 2 additions & 1 deletion src/Subtext.Framework/Infrastructure/TimeZoneWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#endregion

using System;
using Subtext.Framework.Util;

namespace Subtext.Infrastructure
{
Expand Down Expand Up @@ -64,7 +65,7 @@ public DateTime FromUtc(DateTime dateTime)
{
if (dateTime.Kind != DateTimeKind.Utc)
{
dateTime = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute, dateTime.Second, dateTime.Millisecond, DateTimeKind.Unspecified);
dateTime = dateTime.AsUtc();
}
return FromTimeZone(dateTime, TimeZoneInfo.Utc);
}
Expand Down
5 changes: 5 additions & 0 deletions src/Subtext.Framework/Util/TimeZones.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,10 @@ public static TimeZoneInfo GetById(this ReadOnlyCollection<TimeZoneInfo> timeZon
where timeZone.Id == timeZoneId
select timeZone).FirstOrDefault();
}

public static DateTime AsUtc(this DateTime dateTime)
{
return new DateTime(dateTime.Ticks, DateTimeKind.Utc);
}
}
}
2 changes: 1 addition & 1 deletion src/Subtext.Framework/XmlRpc/MetaWeblog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ private string PostContent(string username, string password, ref Post post, bool
entry.AllowComments = true;
entry.DisplayOnHomePage = true;

DateTime dateTimeInPostUtc = post.dateCreated != null ? post.dateCreated.Value : DateTime.UtcNow;
DateTime dateTimeInPostUtc = post.dateCreated != null ? post.dateCreated.Value.AsUtc() : DateTime.UtcNow;

if (publish)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Subtext.Web/Web.config
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<!-- Change the connectionStringName AppSetting to switch from one database to another. -->
<connectionStrings>
<clear />
<add name="subtextData" connectionString="Server=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Subtext2.6.mdf;Database=Subtext2.6;Trusted_Connection=True;User Instance=false;" />
<add name="subtextData" connectionString="Server=.\SQLEXPRESS;Database=SubtextData;Trusted_Connection=True;User Instance=false;" />
</connectionStrings>
<FullTextSearchEngineSettings type="Subtext.Framework.Configuration.FullTextSearchEngineSettings, Subtext.Framework">
<Parameters>
Expand Down
18 changes: 11 additions & 7 deletions src/UnitTests.Subtext/Framework/XmlRpc/MetaBlogApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,22 +130,26 @@ public void NewPost_WithFutureDate_SyndicatesInTheFuture()
var entryPublisher = new Mock<IEntryPublisher>();
entryPublisher.Setup(publisher => publisher.Publish(It.IsAny<Entry>())).Returns(42).Callback<Entry>(
entry => publishedEntry = entry);
DateTime now = DateTime.UtcNow;
var utcNow = DateTime.UtcNow;
var now = new DateTime(utcNow.Year, utcNow.Month, utcNow.Day, utcNow.Hour, utcNow.Minute, utcNow.Second, DateTimeKind.Unspecified);

var api = new MetaWeblog(subtextContext.Object, entryPublisher.Object);
var post = new Post();
post.categories = null;
post.description = "A unit test";
post.title = "A unit testing title";
post.dateCreated = now.AddDays(1);
var post = new Post
{
categories = null,
description = "A unit test",
title = "A unit testing title",
dateCreated = now.AddDays(1)
};

// act
string result = api.newPost(blog.Id.ToString(CultureInfo.InvariantCulture), "username", "password", post, true);
api.newPost(blog.Id.ToString(CultureInfo.InvariantCulture), "username", "password", post, true);

// assert
Assert.IsNotNull(publishedEntry);
Assert.Greater(publishedEntry.DateSyndicated, now.AddDays(.75));
Assert.LowerEqualThan(publishedEntry.DateSyndicated, now.AddDays(1));
Assert.AreEqual(publishedEntry.DatePublishedUtc.Kind, DateTimeKind.Utc);
}

[Test]
Expand Down

0 comments on commit ee73a35

Please sign in to comment.