-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from mannylopez/manny-lopez--timeTestHelper
Move time date and timezone helpers to TimeTestHelper
- Loading branch information
Showing
6 changed files
with
196 additions
and
194 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
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,46 @@ | ||
// Created by manny_lopez on 7/22/24. | ||
|
||
import Foundation | ||
|
||
enum TimeTestHelper { | ||
|
||
enum TimeZoneOption { | ||
case utc | ||
case pacific | ||
case tokyo | ||
|
||
static func createTimeZone(timeZone: TimeZoneOption) -> TimeZone { | ||
switch timeZone { | ||
case .utc: | ||
TimeZone(identifier: "UTC")! | ||
case .pacific: | ||
TimeZone(identifier: "America/Los_Angeles")! | ||
case .tokyo: | ||
TimeZone(identifier: "Asia/Tokyo")! | ||
} | ||
} | ||
} | ||
|
||
/// Creates a Date from the given arguments. Default is in UTC timezone. | ||
static func formatDate( | ||
year: Int, | ||
month: Int, | ||
day: Int, | ||
hour: Int = 00, | ||
minute: Int = 00, | ||
second: Int = 00, | ||
timeZone: TimeZone = TimeZoneOption.createTimeZone(timeZone: .utc)) | ||
-> Date | ||
{ | ||
var components = DateComponents() | ||
components.year = year | ||
components.month = month | ||
components.day = day | ||
components.hour = hour | ||
components.minute = minute | ||
components.second = second | ||
components.timeZone = timeZone | ||
|
||
return Calendar.current.date(from: components)! | ||
} | ||
} |
Oops, something went wrong.