Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Marisa Goergen committed Sep 1, 2023
2 parents 11d927a + a6d7e43 commit 8f8b9fd
Show file tree
Hide file tree
Showing 9 changed files with 215 additions and 136 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.1.4
6.2.3
1 change: 0 additions & 1 deletion src/Moryx.Model.Sqlite/SqliteModelConfigurator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Moryx.Model.Configuration;
using Moryx.Tools;
using Moryx.Model.Sqlite.Attributes;

namespace Moryx.Model.Sqlite
Expand Down
25 changes: 20 additions & 5 deletions src/Moryx.Model/Annotations/DateTimeKindAnnotation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
using System;
using System.Linq;
using System.Reflection;
using System.Threading;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Moryx.Model.Attributes;
using Newtonsoft.Json.Linq;

namespace Moryx.Model.Annotations
{
Expand All @@ -23,13 +25,26 @@ public static class DateTimeKindAnnotation
private const string AnnotationName = "DateTimeKind";

private static readonly ValueConverter<DateTime, DateTime> UtcConverter =
new ValueConverter<DateTime, DateTime>(v => v, v => DateTime.SpecifyKind(v, DateTimeKind.Utc));

new ValueConverter<DateTime, DateTime>(v => ConvertToUtc(v), v => DateTime.SpecifyKind(v, DateTimeKind.Utc));
private static readonly ValueConverter<DateTime, DateTime> LocalConverter =
new ValueConverter<DateTime, DateTime>(v => v, v => DateTime.SpecifyKind(v, DateTimeKind.Local));

new ValueConverter<DateTime, DateTime>(v => ConvertToUtc(v), v => ConvertToLocal(v));
private static readonly ValueConverter<DateTime, DateTime> UnspecifiedConverter =
new ValueConverter<DateTime, DateTime>(v => v, v => DateTime.SpecifyKind(v, DateTimeKind.Unspecified));
new ValueConverter<DateTime, DateTime>(v => ConvertToUtc(v), v => DateTime.SpecifyKind(v, DateTimeKind.Unspecified));

private static DateTime ConvertToUtc(DateTime dateTime)
{
if (dateTime.Kind == DateTimeKind.Utc)
return dateTime;
else
return TimeZoneInfo.ConvertTimeToUtc(dateTime, TimeZoneInfo.Local);
}

private static DateTime ConvertToLocal(DateTime timeUtc)
{
var result = TimeZoneInfo.ConvertTimeFromUtc(timeUtc, TimeZoneInfo.Local);
result = DateTime.SpecifyKind(result, DateTimeKind.Local);
return result;
}

/// <summary>
/// Adds the date time kind converter to the model builder.
Expand Down
7 changes: 7 additions & 0 deletions src/Moryx.TestTools.Test.Model/Entities/CarEntity.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Copyright (c) 2023, Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0

using System;
using System.Collections.Generic;
using Moryx.Model;
using Moryx.Model.Attributes;

namespace Moryx.TestTools.Test.Model
{
Expand All @@ -14,6 +16,11 @@ public class CarEntity : ModificationTrackedEntityBase

public virtual byte[] Image { get; set; }

[DateTimeKind(DateTimeKind.Local)]
public DateTime ReleaseDateLocal { get; set; }

public DateTime ReleaseDateUtc { get; set; }

public virtual ICollection<WheelEntity> Wheels { get; set; }
}
}
7 changes: 6 additions & 1 deletion src/Moryx/Bindings/TextBindingResolverFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public static class TextBindingResolverFactory
/// </summary>
public static ITextBindingResolver Create(string parameterWithBindings, IBindingResolverFactory resolverFactory)
{
//null check to make sure the parameterWithBinding is not null
if (parameterWithBindings == null)
return new NullResolver(parameterWithBindings);

// Parse bindings
var matches = Regex.Matches(parameterWithBindings, BindingRegex);

Expand Down Expand Up @@ -102,7 +106,8 @@ public string Resolve(object source)
foreach (var resolver in _resolvers)
{
var resolvedReference = resolver.Value.Resolve(source);
result = result.Replace(resolver.Key, resolvedReference?.ToString() ?? "'null'");
result = resolvedReference is null ?
result : result.Replace(resolver.Key, resolvedReference.ToString());
}
return result;
}
Expand Down
Loading

0 comments on commit 8f8b9fd

Please sign in to comment.