Replies: 2 comments 13 replies
-
Apologies for the ramble. My thoughts on this question are pretty unstructured unfortunately, so I kind of went all over the place. Yeah, I don't think you're the first to bring this up. I think this is a tricky problem in general though and could have some pretty epic footguns if it isn't done right. With that said, there is some support for this internally, but it isn't exposed. Specifically for the Temporal ISO 8601 format: jiff/src/fmt/temporal/parser.rs Lines 16 to 32 in b8ca1f7 And this type is created by this routine: jiff/src/fmt/temporal/parser.rs Lines 191 to 240 in b8ca1f7 Now, this only covers
Beyond that, there are some other pretty gnarly questions here. One that comes to mind is: what format is looked for? Is this just the Temporal 8601 format? Or does it also include RFC 2822? What about custom And if the goal is to be maximally flexible, then there is also the question of ambiguity. Like, do you want to accept things like I basically feel like there is an interesting problem to solve here, but I'm not sure how best to go about it. I actually ran into a similarish problem when integrating Jiff into gitoxide: But it's not quite the same as your problem. Instead, in gitoxide, it's more like, "there's a bunch of different formats we can accept here, so we just try them each." Is that something that Jiff should make easier? How closely related is it to your problem? I'm... not sure. In terms of ideas, probably With all that said, I do wonder if for your specific use case, there is perhaps a simple decision tree you can use here. If you limit yourself to what the
I think that covers all of your types, but it doesn't quite span the full set of supported formats. For example, Jiff will happily parse Or alternatively, just try parsing in order of least flexible to most flexible:
This is the easiest approach. And I believe it will get all cases correct. (Not 100% certain of that.) But it may not necessarily be the fastest. |
Beta Was this translation helpful? Give feedback.
-
I've got my if let chain kind of working but I'm struggling with determining if strings passed in have offsets and/or time zones. Am I right that there isn't really anything like that in jiff publicly available? I see rfc9557.rs, which seems to have most of what I'm looking for, but I can't seem to reach it. I'd just rather not reinvent the wheel if I don't have to. I've got this below already, but your code seems much more thorough. fn has_time_zone(input: &str) -> bool {
input.contains('[') && input.contains(']')
}
fn has_offset(input: &str) -> bool {
input.contains('T')
&& (input.split('T').last().is_some_and(|f| f.contains('+'))
|| input.split('T').last().is_some_and(|f| f.contains('-')))
} |
Beta Was this translation helpful? Give feedback.
-
As someone working on a repl with date commands, I may have a little different use case for dealing with datetime. After looking through the jiff source and docs, it seems that if you know what you have to begin with, it's pretty easy to understand and well documented how to deal with it. However, when you're in a repl with commands accepting most any input for date-type information, it's difficult to determine what you've been provided as input. Granted, I understand that "any input" isn't valid. Of course, there are rules we have to abide by for datetime.
I'm not sure this would be very helpful to others or not, but it would be very helpful to me to have some general parse routine that could figure out what was being passed in. Have I missed something like this in jiff?
Example: (just an easy to understand example. since some formats fit within others like, dates in datetimes, we'd have to try parsing in a particular order, if "this string" fits into "this type")
I have investigated using
strptime
/strftime
/BrokenDownTime
to try and hand crank such a function. I've also considered regex. I'm not sure what a good approach would be. Any advice would be appreciated.Beta Was this translation helpful? Give feedback.
All reactions