Skip to content

Commit d329226

Browse files
authored
Merge pull request #9 from HodStudio/feature/UseUtcTimeToLogDates
Adds possibility to use UTC time
2 parents 3e47c0c + a2f5c7d commit d329226

3 files changed

Lines changed: 12 additions & 2 deletions

File tree

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,15 @@ public SchoolContext()
131131
}
132132
```
133133

134+
### If you don't want to use UTC for log time
135+
As the library can be used in several places with different timezones, the default configuration is to use Utc. However, if your application is only used in one timezone, you can configure the library to use the time in the current timezone.
136+
```cs
137+
public SchoolContext()
138+
{
139+
UseUtcTime = false;
140+
}
141+
```
142+
134143
## Examples
135144
The source code contains two examples: one for .Net 4.5 and another for .Net Core 2.2. Both of them are the official tutorials projects from Microsoft. For more information about them, please, take a look at the links below:
136145
- .Net 4.5: https://docs.microsoft.com/en-us/aspnet/mvc/overview/getting-started/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application

src/HodStudio.EntityFrameworkDiffLog/Repository/LoggingContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ internal static async Task LogChangesAsync(this LoggingDbContext context, string
5353

5454
private static async Task LogChangesAsync(this LoggingDbContext context, string userId, bool asyncOperation)
5555
{
56-
var logTime = DateTime.Now;
56+
var logTime = context.UseUtcTime ? DateTime.UtcNow : DateTime.Now;
5757
var changes = context.ChangeTracker.Entries()
5858
.Where(x => entityStates.Contains(x.State)
5959
&& GetEntityType(x.Entity.GetType()) != null)
@@ -81,7 +81,7 @@ internal static async Task LogChangesAddedEntitiesAsync(this LoggingDbContext co
8181

8282
private static async Task LogChangesAddedEntitiesAsync(this LoggingDbContext context, string userId, bool asyncOperation)
8383
{
84-
var logTime = DateTime.Now;
84+
var logTime = context.UseUtcTime ? DateTime.UtcNow : DateTime.Now;
8585
var jdp = new JsonDiffPatch();
8686

8787
foreach (var item in context.AddedEntities)

src/HodStudio.EntityFrameworkDiffLog/Repository/LoggingDbContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public partial class LoggingDbContext
1717
protected string LogEntriesSchemaName { get; set; } = "dbo";
1818

1919
public bool IdGeneratedByDatabase { get; set; } = true;
20+
public bool UseUtcTime { get; set; } = true;
2021

2122
public DbSet<LogEntry> LogEntries { get; set; }
2223

0 commit comments

Comments
 (0)