DD.WellWorkover.Cloud/ConsoleApp1/Program.cs
2022-05-31 16:18:31 +05:00

67 lines
2.1 KiB
C#

using AsbCloudApp.Data;
using AsbCloudDb.Model;
using AsbCloudInfrastructure.Services.DailyReport;
using Mapster;
using Microsoft.EntityFrameworkCore;
using System;
using System.Linq;
namespace ConsoleApp1
{
class Cron
{
public DateTimeOffset Origin { get; set; }
public TimeSpan Period { get; set; }
public DateTimeOffset Next()
{
var delta = DateTimeOffset.Now - Origin;
var n = Math.Ceiling(delta / Period);
return Origin + n * Period;
}
}
class Program
{
static void Main(/*string[] args*/)
{
TypeAdapterConfig.GlobalSettings.Default.Config
.ForType<DateTimeOffset, DateTime>()
.MapWith((source) => source.DateTime);
TypeAdapterConfig.GlobalSettings.Default.Config
.ForType<DateTime, DateTimeOffset>()
.MapWith((source) => source == default ? new DateTime(0, DateTimeKind.Utc) : source);
TypeAdapterConfig.GlobalSettings.Default.Config
.ForType<TimeDto, TimeOnly>()
.MapWith((source) => source == default? default: source.MakeTimeOnly());
TypeAdapterConfig.GlobalSettings.Default.Config
.ForType<TimeOnly, TimeDto>()
.MapWith((source) => new (source));
var sh = new ScheduleDto{
ShiftStart = new TimeDto { Hour = 11, Minute = 30, }
};
var en = sh.Adapt<Schedule>();
var aa = en.Adapt<ScheduleDto>();
// use ServiceFactory to make services
var op = ServiceFactory.MakeWellOperationsService();
var d = op.FirstOperationDate(90);
var period = TimeSpan.FromHours(5);
var c = new Cron
{
Period = period,
Origin = new DateTimeOffset(2022, 5, 8, 0, 0, 7, TimeSpan.FromHours(5)),
};
Console.WriteLine($"origin: {c.Origin} next: {c.Next()}");
Console.WriteLine("End of Test");
Console.ReadLine();
}
}
}