question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

unable to get different dates with FuzzyDateTime

See original GitHub issue

Hello, In Django tests, i have

class EventFactory(factory.django.DjangoModelFactory):
    ...
    dtstart = FuzzyDateTime(datetime.datetime(2008, 1, 1, tzinfo=UTC), datetime.datetime(2009, 1, 1, tzinfo=UTC),
                        force_hour=10,
                        force_minute=30,
                        force_second=0, force_microsecond=0).evaluate(2, None, False)

and i use it:

self.event = EventFactory.create()
self.event2 = EventFactory.create()
self.event3 = EventFactory.create()

Displaying the resulting dtstart, i got: dtstart: “2008-07-21 10:30:00+00:00” dtstart: “2008-07-21 10:30:00+00:00” dtstart: “2008-07-21 10:30:00+00:00” The dates are the same, that’s not what i expect.

What i don’t understand is when i try it in python shell, everytime i call FuzzyDateTime(…), the rresult is always different.

Am i missing something?

thanks in advance for help,

gerard

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
rbarroiscommented, Apr 25, 2015

Hi,

To get a end_dt, simply do the following:

class MyFactory(factory.Factory):
    start_dt = factory.fuzzy.FuzzyDateTime(
        datetime.datetime(2008, 1, 1, tzinfo=UTC),
        datetime.datetime(2009, 1, 1, tzinfo=UTC),
    )
    end_dt = factory.LazyAttribute(lambda o: o.start_dt + datetime.timedelta(hours=1))

As to the sequence, this is easy to design by overriding the rule for start_dt when calling create_batch:

EventFactory.create_batch(N,
     start_dt=factory.Sequence(lambda n: start_dt + datetime.timedelta(hours=n)),
)
0reactions
rbarroiscommented, Oct 20, 2015

Hi,

I’m closing this issue for now; feel free to re-open it if you need more help on this topic!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Factory-boy fuzzy DateTimeField always the same date when ...
I am using factory-boy for creating instances of a Django model, and I am always getting the same value returned when using factory.fuzzy....
Read more >
Complete documentation for the fuzzy date/time parser
It tries to match common formats, but there are a ton of ways to write dates out, so it can't always get it...
Read more >
How do you store "fuzzy dates" into a database?
Store all dates in normal DATE field in the database and have additional accuracy field how accurate DATE field actually is.
Read more >
Fuzzy attributes — Factory Boy stable documentation
It is expected that successive calls of that function return various values. ... The FuzzyDate fuzzer generates random dates within a given inclusive...
Read more >
Fuzzy Datetime Compare - Forums - SQLServerCentral
The problem: I have two data sources, Google Analytics and our own internal Application Form. Each source records the exact same goal/event, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found