Skip to content

Commit

Permalink
fix Date.between(_ from: _ to:)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimonker committed Apr 23, 2023
1 parent fb7ca28 commit 61f52a0
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Sources/Fakery/Faker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public final class Faker {
name = Name(parser: parser)
phoneNumber = PhoneNumber(parser: parser)
team = Team(parser: parser)
number = Number()
number = Number(parser: parser)
bank = Bank(parser: parser)
date = Date()
date = Date(parser: parser)
hobbit = Hobbit(parser: parser)
car = Car(parser: parser)
programmingLanguage = ProgrammingLanguage(parser: parser)
Expand Down
10 changes: 9 additions & 1 deletion Sources/Fakery/Generators/Date.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ import Foundation

extension Faker {
public final class Date: Generator {

private let number: Number

public required init(parser: Parser) {
self.number = Number(parser: parser)
super.init(parser: parser)
}

public func backward(days: Int) -> Foundation.Date {
return todayAddingDays(-days)
}
Expand All @@ -13,7 +21,7 @@ extension Faker {
public func between(_ from: Foundation.Date, _ to: Foundation.Date) -> Foundation.Date {
let fromInSeconds = from.timeIntervalSince1970
let toInSeconds = to.timeIntervalSince1970
let targetInSeconds = Number().randomDouble(min: fromInSeconds, max: toInSeconds)
let targetInSeconds = number.randomDouble(min: fromInSeconds, max: toInSeconds)
return Foundation.Date(timeIntervalSince1970: targetInSeconds)
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Fakery/Generators/Generator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extension Faker {
let parser: Parser
let dateFormatter: DateFormatter

public required init(parser: Parser = Parser()) {
public required init(parser: Parser) {
self.parser = parser
dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd"
Expand Down
2 changes: 1 addition & 1 deletion Tests/Fakery/Generators/DateSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ final class DateSpec: QuickSpec {
var date: Faker.Date!

beforeEach {
date = Faker.Date()
date = Faker.Date(parser: Parser())
}

describe("#between") {
Expand Down
2 changes: 1 addition & 1 deletion Tests/Fakery/Generators/NumberSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ final class NumberSpec: QuickSpec {
var number: Faker.Number!

beforeEach {
number = Faker.Number()
number = Faker.Number(parser: Parser())
}

it("creates contionusly increasing ids") {
Expand Down

0 comments on commit 61f52a0

Please sign in to comment.