-
-
Notifications
You must be signed in to change notification settings - Fork 932
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
faker.time
module to simplify time (not datetime) usecases
#3107
Comments
Thank you for your feature proposal. We marked it as "waiting for user interest" for now to gather some feedback from our community:
We would also like to hear about other community members' use cases for the feature to give us a better understanding of their potential implicit or explicit requirements. We will start the implementation based on:
We do this because:
|
faker.time
module to simplify time (not datetime) usecases
Could you explain which issues you are encountering with the date module when generating times other than Maybe these issues also apply to the date module in general and just haven't been raised yet.
IMO it is unlikely that we add a method like this, because it is likely a user dependent structure. e.g. maybe you use As a workaround for that, I can recommend the const [ rangeFrom, rangeTo ] = faker.date.betweens({ from, to, count: 2);
return {
from: toTime(rangeFrom),
to: toTime(rangeTo ),
}
IMO the format parameter is unlikely, because there are too many possible variations to it, that we might end up with a full date formatting library. e.g. one user wants the time formatted like this: This is currently my main concern with the time module. |
@douglasg14b Could you please answer these questions/respond to the suggestions? Or are the additions to the following section sufficient? |
Hi, sorry, my github notifications as skuffed (nearly 1000/d for work, and when not SSOd like when home github shows me zero other notifications for some reason). If I am mentioned I get a push notification though. That said:, the issue I was encountering was:
I think these are two different problems.
|
Would the following solve your issue: const someDate = new Date(faker.date.soon().toISOString().substring(0, 10)).valueOf();
const timeAtThatDay = faker.date.between({from: someDate, to: someDate + 86400000 - 1000}); The main issue we have here is that the it is unclear, which timezone the time (of day) should be in. The example assumes local timezone. I assume some usecases apply to subsets of days. e.g. working hours. const timeAtThatWorkDay = faker.date.between({from: someDate + 9 * 60 * 60 * 1000, to: someDate + 17 * 60 * 60 * 1000}); But what if you want the times to be alligned in a 15minute grid? Maybe a custom/user defined function can produce these results more easily? const slottedTimeAtThatWorkDay = new Date(someDate + 9 * 60 * 60 * 1000 + faker.number.int({multipleOf: 15, min: 0, max: 8 * 60}) * 60 * 1000) I could see usefulness for Is any of this what you need? Any ideas on how to solve the timezone issue?
IMO that is out of scope for faker |
@douglasg14b Could you please explain your needs in more detail/check whether the above would help you in any way? |
The above does solve it, technically. However, it's not elegant and means that functions to fake the (standardized) data are still present in mocking locations 🤔 But I see your point though.
Why is this? A format is faked data, which is somewhat omnipresent in the concept of fakerjs. What makes this different? There are light libs that accept semi-standardized string format inputs for date/times, like dayjs. Making such a surface area, ideally, straightforward. In this case we had a need to fake fragments of an ISO 8601 timestamp. As well as faking 24 hour time strings (ie. 14:13). Often in sequence. This was largely solved at the time it was needed, but it was a surprise that some of the date & time faking wasn't part of the fakerjs API. So I made this suggestion. Especially helpful utilities like faking time between two times, or after/before. Ie. Having controls over the variance of the faked date/times. |
What is the input and output format for the methods? HH:mm? HH:mm:ss.S? Are partial inputs allowed? Is 23:00 - 01:00 allowed? Which methods do you need?
Which options do you need for those methods (please include types)? |
Clear and concise description of the problem
Generating fakes specifically for times, not necessarily dates. These will only produce times, and not consider dates.
The date fucntions do perform this utility to some degree but require additional work to achieve which could be baked into a time module directly.
Suggested solution
in module
faker.date
or in a new modulefaker.time
it would have fucntions for:faker.time.between
faker.time.after
faker.time.range
These should accept a format argument that allows the time output to be formatted as 24/12h time (or others)
Alternative
Users build their own time fucntions that work on top of
faker.date
Additional context
Naive examples from my own use:
The text was updated successfully, but these errors were encountered: