Fixes : U4-2055 Unpublish Date Bug in Umbraco 6.0.3 -> with unit test to ensure that all dates are formatted as ISO date standards when used in SQL
This commit is contained in:
22
src/Umbraco.Core/DateTimeExtensions.cs
Normal file
22
src/Umbraco.Core/DateTimeExtensions.cs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Umbraco.Core
|
||||||
|
{
|
||||||
|
public static class DateTimeExtensions
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the DateTime as an ISO formatted string that is globally expectable
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="dt"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string ToIsoString(this DateTime dt)
|
||||||
|
{
|
||||||
|
return dt.ToString("yyyy-MM-dd HH:mm:ss");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -456,7 +456,10 @@ namespace Umbraco.Core.Persistence.Querying
|
|||||||
return ((decimal)value).ToString(CultureInfo.InvariantCulture);
|
return ((decimal)value).ToString(CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
if (fieldType == typeof (DateTime))
|
if (fieldType == typeof (DateTime))
|
||||||
return "'" + EscapeParam(((DateTime)value).ToString(CultureInfo.InvariantCulture)) + "'";
|
{
|
||||||
|
return "'" + EscapeParam(((DateTime)value).ToIsoString()) + "'";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (fieldType == typeof(bool))
|
if (fieldType == typeof(bool))
|
||||||
return ((bool)value) ? Convert.ToString(1, CultureInfo.InvariantCulture) : Convert.ToString(0, CultureInfo.InvariantCulture);
|
return ((bool)value) ? Convert.ToString(1, CultureInfo.InvariantCulture) : Convert.ToString(0, CultureInfo.InvariantCulture);
|
||||||
|
|||||||
@@ -466,7 +466,10 @@ namespace Umbraco.Core.Persistence.Querying
|
|||||||
return ((decimal)value).ToString(CultureInfo.InvariantCulture);
|
return ((decimal)value).ToString(CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
if (fieldType == typeof (DateTime))
|
if (fieldType == typeof (DateTime))
|
||||||
return "'" + EscapeParam(((DateTime)value).ToString(CultureInfo.InvariantCulture)) + "'";
|
{
|
||||||
|
return "'" + EscapeParam(((DateTime)value).ToIsoString()) + "'";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (fieldType == typeof(bool))
|
if (fieldType == typeof(bool))
|
||||||
return ((bool)value) ? Convert.ToString(1, CultureInfo.InvariantCulture) : Convert.ToString(0, CultureInfo.InvariantCulture);
|
return ((bool)value) ? Convert.ToString(1, CultureInfo.InvariantCulture) : Convert.ToString(0, CultureInfo.InvariantCulture);
|
||||||
|
|||||||
@@ -140,6 +140,7 @@
|
|||||||
<Compile Include="CoreBootManager.cs" />
|
<Compile Include="CoreBootManager.cs" />
|
||||||
<Compile Include="DatabaseContext.cs" />
|
<Compile Include="DatabaseContext.cs" />
|
||||||
<Compile Include="DataTableExtensions.cs" />
|
<Compile Include="DataTableExtensions.cs" />
|
||||||
|
<Compile Include="DateTimeExtensions.cs" />
|
||||||
<Compile Include="DictionaryExtensions.cs" />
|
<Compile Include="DictionaryExtensions.cs" />
|
||||||
<Compile Include="Dictionary\CultureDictionaryFactoryResolver.cs" />
|
<Compile Include="Dictionary\CultureDictionaryFactoryResolver.cs" />
|
||||||
<Compile Include="Dictionary\ICultureDictionaryFactory.cs" />
|
<Compile Include="Dictionary\ICultureDictionaryFactory.cs" />
|
||||||
|
|||||||
@@ -12,6 +12,22 @@ namespace Umbraco.Tests.Persistence.Querying
|
|||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class QueryBuilderTests : BaseUsingSqlCeSyntax
|
public class QueryBuilderTests : BaseUsingSqlCeSyntax
|
||||||
{
|
{
|
||||||
|
[Test]
|
||||||
|
public void Dates_Formatted_Properly()
|
||||||
|
{
|
||||||
|
var sql = new Sql();
|
||||||
|
sql.Select("*").From<DocumentDto>();
|
||||||
|
|
||||||
|
var dt = new DateTime(2013, 11, 21, 13, 25, 55);
|
||||||
|
|
||||||
|
var query = Query<IContent>.Builder.Where(x => x.ExpireDate <= dt);
|
||||||
|
var translator = new SqlTranslator<IContent>(sql, query);
|
||||||
|
|
||||||
|
var result = translator.Translate();
|
||||||
|
|
||||||
|
Assert.IsTrue(result.SQL.Contains("[expireDate] <= '2013-11-21 13:25:55'"));
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Can_Build_StartsWith_Query_For_IContent()
|
public void Can_Build_StartsWith_Query_For_IContent()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user