Skip to content

Commit

Permalink
Merge pull request #200 from raffacabofrio/master
Browse files Browse the repository at this point in the history
Tornando a hora do job mais precisa.
  • Loading branch information
raffacabofrio authored Jan 18, 2019
2 parents 3904a71 + f290610 commit c41e3ec
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
6 changes: 4 additions & 2 deletions ShareBook/ShareBook.Api/Controllers/BookController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ protected void SetDefault(Expression<Func<Book, object>> defaultOrder)
public IActionResult Ping() {
var result = new
{
ServerDateTime = DateTime.Now,
SaoPauloDateTime = DateTimeHelper.ConvertDateTimeSaoPaulo(DateTime.Now),
ServerNow = DateTime.Now,
SaoPauloNow = DateTimeHelper.ConvertDateTimeSaoPaulo(DateTime.Now),
ServerToday = DateTime.Today,
SaoPauloToday = DateTimeHelper.GetTodaySaoPaulo(),
Message = "Pong!"
};
return Ok(result);
Expand Down
9 changes: 9 additions & 0 deletions ShareBook/ShareBook.Helper/DateTime/DateTimeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,22 @@ static public class DateTimeHelper
{
static private readonly string SaoPauloTimezoneId = "E. South America Standard Time";

// hora agora.
static public TimeSpan GetTimeNowSaoPaulo()
{
var now = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.FindSystemTimeZoneById(SaoPauloTimezoneId));
var today = new DateTime(now.Year, now.Month, now.Day);
return now - today;
}

// data-hora de hoje a meia noite.
static public DateTime GetTodaySaoPaulo()
{
var nowSP = GetTimeNowSaoPaulo();
var todaySP = DateTime.Now.AddHours(nowSP.Hours * -1).AddMinutes(nowSP.Minutes * -1).AddSeconds(nowSP.Seconds * -1);
return todaySP;
}

static public DateTime ConvertDateTimeSaoPaulo(DateTime d) => TimeZoneInfo.ConvertTime(d, TimeZoneInfo.FindSystemTimeZoneById(SaoPauloTimezoneId));
}
}
2 changes: 1 addition & 1 deletion ShareBook/Sharebook.Jobs/Jobs/GenericJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public DateTime GetDateLimitByInterval(Interval i)
{
case Interval.Dayly:
{
result = result.AddDays(-1);
result = DateTimeHelper.GetTodaySaoPaulo();
break;
}
case Interval.Hourly:
Expand Down

0 comments on commit c41e3ec

Please sign in to comment.