-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
123 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
namespace GCPCostNotifier.Services; | ||
|
||
public class CalculatedDateTimeOffsets | ||
{ | ||
/// <summary> | ||
/// 計算に用いる基準日 | ||
/// </summary> | ||
public required DateTimeOffset ReferenceDateTimeOffset { get; init; } | ||
|
||
/// <summary> | ||
/// 基準日から算出した課金区間の開始日時 | ||
/// </summary> | ||
public required DateTimeOffset StartOffsetDateTimeOffset { get; init; } | ||
|
||
/// <summary> | ||
/// 基準日から算出した課金区間の終了日時 | ||
/// </summary> | ||
public required DateTimeOffset EndOffsetDateTimeOffset { get; init; } | ||
|
||
/// <summary> | ||
/// 基準日から算出した課金区間の開始日時のパーティション(課金情報のテーブルの絞り込みに使用する) | ||
/// </summary> | ||
public required DateTimeOffset PartitionStartDateTimeOffset { get; init; } | ||
|
||
/// <summary> | ||
/// 基準日から算出した課金区間の終了日時のパーティション(課金情報のテーブルの絞り込みに使用する) | ||
/// </summary> | ||
public required DateTimeOffset PartitionEndDateTimeOffset { get; init; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
namespace GCPCostNotifier.Services; | ||
|
||
using NodaTime; | ||
using NodaTime.Extensions; | ||
|
||
public class DateTimeCalculationService : IDateTimeCalculationService | ||
{ | ||
public CalculatedDateTimeOffsets CalculateDateTimeOffsetsForYesterday(DateTimeOffset targetDateTimeOffset) | ||
{ | ||
// 基準日は必ず現在の日付の0時0分0秒にする | ||
var targetZonedDateTime = targetDateTimeOffset.ToZonedDateTime(); | ||
var referenceDateTime = targetZonedDateTime.Date.AtStartOfDayInZone(targetZonedDateTime.Zone); | ||
|
||
// 開始日はぴったり1日前の日時に指定、終了日は指定された日時にする | ||
var startOffsetDateTime = referenceDateTime.Plus(Duration.Negate(Duration.FromDays(1))); | ||
var endOffsetDateTime = referenceDateTime; | ||
|
||
// パーティションの日付は開始日はUTCに変換した日付の0時0分0秒、終了日は指定された日時にする | ||
var partitionStartDateTimeUtc = | ||
startOffsetDateTime.ToOffsetDateTime().InZone(DateTimeZone.Utc).Date.AtStartOfDayInZone(DateTimeZone.Utc); | ||
var partitionEndDateTimeUtc = endOffsetDateTime.ToOffsetDateTime().InZone(DateTimeZone.Utc); | ||
|
||
return new CalculatedDateTimeOffsets | ||
{ | ||
ReferenceDateTimeOffset = referenceDateTime.ToDateTimeOffset(), | ||
StartOffsetDateTimeOffset = startOffsetDateTime.ToDateTimeOffset(), | ||
EndOffsetDateTimeOffset = endOffsetDateTime.ToDateTimeOffset(), | ||
PartitionStartDateTimeOffset = partitionStartDateTimeUtc.ToDateTimeOffset(), | ||
PartitionEndDateTimeOffset = partitionEndDateTimeUtc.ToDateTimeOffset() | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace GCPCostNotifier.Services; | ||
|
||
public interface IDateTimeCalculationService | ||
{ | ||
public CalculatedDateTimeOffsets CalculateDateTimeOffsetsForYesterday(DateTimeOffset targetDateTimeOffset); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters