Added timezone support

This commit is contained in:
Mia Rose Winter 2024-01-23 13:55:27 +01:00
parent 62458cbdd4
commit 7c3fecf70b
Signed by: miawinter
GPG key ID: 4B6F6A83178F595E
3 changed files with 14 additions and 3 deletions

File diff suppressed because one or more lines are too long

View file

@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Wave.Data;
@ -9,6 +10,11 @@ public class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options
protected override void OnModelCreating(ModelBuilder builder) {
base.OnModelCreating(builder);
var dateTimeOffsetUtcConverter = new ValueConverter<DateTimeOffset, DateTimeOffset>(
model => model.ToUniversalTime(),
utc => utc.ToLocalTime()
);
builder.Entity<ApplicationUser>(user => {
user.Property(u => u.FullName).HasMaxLength(64);
user.Property(u => u.AboutTheAuthor).HasMaxLength(512);
@ -36,9 +42,13 @@ public class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options
.IsRequired(false).OnDelete(DeleteBehavior.SetNull);
article.Property(a => a.CreationDate)
.IsRequired().HasDefaultValueSql("now()");
.IsRequired().HasDefaultValueSql("now()")
.HasConversion(dateTimeOffsetUtcConverter);
article.Property(a => a.PublishDate)
.HasConversion(dateTimeOffsetUtcConverter);
article.Property(a => a.LastModified)
.IsRequired().HasDefaultValueSql("now()");
.IsRequired().HasDefaultValueSql("now()")
.HasConversion(dateTimeOffsetUtcConverter);
article.HasQueryFilter(a => !a.IsDeleted);
});

View file

@ -13,6 +13,7 @@ services:
links:
- database:db
environment:
- "TZ=Europe/Berlin"
- "WAVE_ConnectionStrings__DefaultConnection=Host=db; Username=wave; Password=development"
- "WAVE_ConnectionStrings__Redis=redis,password=development"
volumes: