Metime 0.2.6

dotnet add package Metime --version 0.2.6
NuGet\Install-Package Metime -Version 0.2.6
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Metime" Version="0.2.6" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Metime --version 0.2.6
#r "nuget: Metime, 0.2.6"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Metime as a Cake Addin
#addin nuget:?package=Metime&version=0.2.6

// Install Metime as a Cake Tool
#tool nuget:?package=Metime&version=0.2.6

Metime

Helper framework for timezone calculations. Business services marked with special attribute is injected aspect injector in build time. All of the service methods are wrapped by timezone conversion logic. Parameters of the method are converted to UTC(if not already) and results of the method are converted to Local(if not already).

Special thanks to the AspectInjector

Motivation

Well.. Enterprise applications's timezone management suck. There are probably some resources on different timezones and these resources should be viewed in their own timezones instead of one global timezone. This framework trying to ease the pain.

Installation

Available on NuGet

PM> Install-Package Metime

Startup.cs

using Metime.Extensions;

public class Startup
{
    public void ConfigureServices(IServiceCollection services) 
    {
        ...
        services.AddMetime<DefaultResolver>();
        services.AddCustomResolver<CustomEntity, CustomEntityResolver>();
        ...
    }
    
    public void Configure(IApplicationBuilder app) 
    {
        ...
        app.UseMetime();
        ...
    }
}

Important Notes

  • If you are assigning UTC value to the property (like CreatedAt), you should do it inside service method so it doesn't converted to UTC again by mistake.
  • Database entities should have Kind = TimezoneFormat.UTC and request DTOs should have Kind = TimezoneFormat.Local default values.
  • You can add custom resolver per entity; however, properties must be marked with [UseCustomResolver] attribute as well.
  • Date only properties can be marked with [IgnoreTimezone] attribute.

Usage

Detailed example can be found in example project.

Services that marked with the ConvertTimezone will process all of the methods available. Their parameters (DateTime objects are not considered only objects implementing ITimezoneConvertible are) and result objects will be processed.

using Metime.Attributes;

[ConvertTimezone]
public class BlogService : IBlogService 
{
    ...
}

Objects that needs to be processed needs to implement ITimezoneConvertible. Since datetimes are stored in UTC format, it's default value should be UTC. This way, queried results will have default UTC value.

using Metime.Models;

public class Blog : ITimezoneConvertible
    {
        ...
        public DateTime PostedAt { get; set; }
        [NotMapped] public TimezoneFormat Kind { get; set; } = TimezoneFormat.UTC;
    }

License

MIT License

Copyright (c) 2022 Metin ÖZTÜRK

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.2.6 343 12/24/2021