Skip to content

Commit

Permalink
T #98 unfinished attempt to fix timing and dates
Browse files Browse the repository at this point in the history
  • Loading branch information
HueByte committed Oct 9, 2022
1 parent 7f16552 commit 1dc5835
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/Huppy/Huppy.Core/Services/Reminder/ReminderService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class ReminderService : IReminderService
private readonly IEventLoopService _eventService;
private readonly InteractionService _interactionService;
private DateTime FetchingDate => DateTime.UtcNow + FetchReminderFrequency;
public TimeSpan FetchReminderFrequency { get; } = new(1, 0, 0);
public TimeSpan FetchReminderFrequency { get; } = new(0, 0, 30);
private readonly ReminderProto.ReminderProtoClient _reminderClient;
public ReminderService(IEventLoopService eventService, ILogger<ReminderService> logger, DiscordShardedClient discord, InteractionService interactionService, ITimedEventsService timedEventsService, ReminderProto.ReminderProtoClient reminderClient)
{
Expand Down Expand Up @@ -50,7 +50,6 @@ public async Task RegisterFreshRemindersAsync()
{
var reminders = await _reminderClient.GetReminderBatchAsync(new ReminderBatchInput()
{
StartDate = Miscellaneous.DateTimeToUnixTimestamp(DateTime.UtcNow),
EndDate = Miscellaneous.DateTimeToUnixTimestamp(DateTime.UtcNow + FetchReminderFrequency)
});

Expand Down
2 changes: 1 addition & 1 deletion src/Huppy/Huppy.Core/Utilities/Miscellaneous.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static DateTime UnixTimeStampToDateTime(ulong unixTimeStamp)
{
// Unix timestamp is seconds past epoch
DateTime dateTime = new(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
dateTime = dateTime.AddSeconds(unixTimeStamp).ToLocalTime();
dateTime = dateTime.AddSeconds(unixTimeStamp);
return dateTime;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static DateTime UnixTimeStampToDateTime(ulong unixTimeStamp)
{
// Unix timestamp is seconds past epoch
DateTime dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
dateTime = dateTime.AddSeconds(unixTimeStamp).ToLocalTime();
dateTime = dateTime.AddSeconds(unixTimeStamp);
return dateTime;
}

Expand Down
3 changes: 1 addition & 2 deletions src/HuppyService/HuppyService.Service/Protos/reminder.proto
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ message GetReminderInput {
}

message ReminderBatchInput {
uint64 StartDate = 1;
uint64 EndDate = 2;
uint64 EndDate = 1;
}

message ReminderUserInput {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ public override async Task<ReminderModel> AddReminder(ReminderModel request, Ser
_logger.LogInformation("Registering fresh bulk of reminders");

// fetch reminders between dates
var remindDateStart = Miscellaneous.UnixTimeStampToDateTime(request.StartDate);
//var remindDateStart = Miscellaneous.UnixTimeStampToDateTime(request.StartDate);
var remindDateEnd = Miscellaneous.UnixTimeStampToDateTime(request.EndDate);

var remindersQueryable = await _reminderRepository.GetAllAsync();

var reminders = await remindersQueryable
.Where(reminder => remindDateStart < remindDateEnd)
.Where(reminder => reminder.RemindDate < remindDateEnd)
.ToListAsync();

if (!reminders.Any()) return new();
Expand Down

0 comments on commit 1dc5835

Please sign in to comment.