You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
date.date_sub(other_date)=>durationdate.dur_sub(duration)=>other_datedate.dur_add(duration)=>other_dateduration.dur_sub(other_duration)=>third_durationduration.dur_add(other_duration)=>third_durationdate.date_{lt/gt/le/ge/eq/ne}(other_date)=>boolduration.dur_{lt/gt/le/ge/eq/ne}(other_date)=>bool# intervals can also be specified directly as stringsr.interval(date,other_date)=>intervalr.interval(date,duration)=>intervaldate.during(interval)=>bool
We should also update the drivers to automatically render native dates/durations/intervals as the appropriate strings.
So, for example, in Ruby you could get all rows inserted in the last day with:
Why reimplementing date manipulation primitives would be necessary? Shouldn't suffice to have queries take native date types and have the driver convert to a wire format?
@hcarvalhoalves suppose you wanted a query that says something like "Give me every event that happened on a Monday". In order for that to work on the server side, it would need a db-level function that determines the day of the date, otherwise you'd have to transfer all the data to the client first and do the processing on the client.
@coffeemug Right, I get what you mean now. I just didn't get where the above methods fit in your example though. I expected date manipulation would look something like this:
I would like to propose a few modifications and additions to @mlucy's proposal.
I'm going to call these objects times instead of dates.
In the iso8601 representation, the time component should be optional as well as the time zone component.
The P and T prefixes are optional for durations. One can write "1M" or "1:30" instead of "P1M" and "PT1:30". Durations can also be represented simply as a number of seconds.
All operations assume that all days have exactly 86400 seconds. "23:60" is considered equal to "23:59".
r.run() takes an additional time_zone argument that specifies the default time zone used in the query. The client drivers automatically set the time_zone to the local time zone of the client. The default time zone is only used where it is explicitly mentioned in this proposal. If time_zone is set to the empty string, time zone defaulting is disabled and all operation that would require using the default time zone fail.
When only one of time or other_time has a time zone, the other value is considered to be in the default time zone. If both time and other_time have no time zone, neither does the result.
There are no intervals. during simply takes two arguments.
Times default to the default time zone if the time zone component is missing, unless all times have no time zones.
time.date() => time # the date component
time.time_of_day() => duration # the time component
time.time_zone() => string # time zone component
time.year() => number
time.month() => number
time.day() => number
time.week_day() => number # 0 = Sunday, 1 = Monday, ..., 6=Saturday
time.year_day() => number # 1-366
time.hour() => number
time.minute() => number
time.seconds() => number # floating point
duration.totalSeconds() => number
If the time is not present, the corresponding accessors return null. Ditto for the time zone.
r.time(year, month, day, hour, minute, seconds, tz) => time
r.time(year, month, day, hour, minute, seconds) => time
r.time(year, month, day) => time
Equivalent to time.time_sub("1970-01-01T00:00Z").totalSeconds()
r.now() => string
r.now(tz) => string
The current time in the tz time zone. If tz is not specified, use the default time zone. If the default time zone is not specified, use "Z".
time.format_time(format) => string
string.parse_time(format) => time
Format and parse times like strftime and strptime.
time.with_time_zone() => time
time.with_time_zone(tz) => time
time.set_time_zone(tz) => time
with_time_zone returns the same time in a different time zone. If the time has no time zone, it converts from the default time zone. With no arguments, it converts to the default time zone.
set_time_zone simply changes the time zone component.
Instead of using iso8601 string representation, times could instead be represented as a number of seconds since epoch and durations as a number of seconds. There are a few advantages:
using regular comparison and arithmetic operators instead of time_* and dur_*
using existing r.between instead of adding a new r.during
faster: no need to parse and format the time for each operation
There are also some disadvantages:
debugging is harder with seemingly opaque numbers rather than with nicely formatted strings
time zone information is lost, all times would be stored as UTC
representing a local time (with no time zone) is impossible
A better representation would be a new native type instead of a pseudo-type. This would have all these advantages and none of these disadvantages.
FYI, this issue looks like the only one in 1.8-required that's non-trivial and wide open (since we didn't discuss it much). Let's try to hammer this out. (P.S. my feedback on the specific proposal coming soon)
The P and T prefixes are optional for durations. One can write "1M" or "1:30" instead of "P1M" and "PT1:30". Durations can also be represented simply as a number of seconds.
This is ambiguous. In ISO8610 P1M means one month and PT1M means one minute.
"23:60" is considered equal to "23:59".
What's the motivation for this? That sound wacky.
duration.totalSeconds() => number
Could we call this dur_seconds for consistency?
r.sunday = 0
r.january = 1
Why is sunday numbered from 0 when january is numbered from 1?
time.epoch_time() => number
This name sounds slightly off to me. See below for discussion of how I think we should handle ISO8601 vs. epoch time.
Format and parse times like strftime and strptime.
This seems strange to have in the server. Shouldn't people be doing this in the clients once they've retrieved the date? Also, we'd be violating the standard unless we want the clients to send the whole locale to the server.
with_time_zone
Could we call this in_time_zone? It seems less ambiguous to me.
Instead of using iso8601 string representation, times could instead be represented as a number of seconds since epoch and durations as a number of seconds.
I think this is the biggest thing left to decide. Here's what I think we should do (although I need to think about it more):
Store everything internally as seconds since epoch. People know how to deal with this, it's easy, and it always sorts correctly. Use negative numbers for dates before 1970.
Have the functions dur_to_iso8601 and time_to_iso8601 for when people want to do regexp matching or something. Have the functions dur_to_epoch and time_to_epoch for when people have an ISO8601 string that they want in seconds. (Maybe with better names?)
Make all the functions (date_add, dur_sub, etc.) polymorphic, and let them accept either numbers (which are interpreted as seconds) or ISO8601 strings, but have them always return seconds since epoch.
Sorry to complicate matters, but I must. First, a few random thoughts:
I think that if we implement things like time_sub, instead of adding a proper time type and making sub polymorphic, we will very quickly grow to regret this decision.
I also think that on the driver side people should be able to operate with standard time/date types. E.g. r.expr(datetime.now()) should work in Python. They should be able to say table.insert({time: datetime.now()}), and get a native Python datetime object if they get the row back IMO. (at the very least, we should consider this carefully)
I propose the following:
Store time object like this on the server: { __reql_type__: 'time', ms_since_epoch_utc: X }
Whenever possible, use existing operations for math and logic (i.e. make add, gt, etc. polymorphic on time)
In the drivers, convert __reql_type__: 'time' back to native object (e.g. datetime in Python, Date in JS, etc.)
I think the server shouldn't ever store timezone information, just milliseconds since epoch in UTC. When the user says something like r.row('time_field').getDay.eq('Monday') they either pass the timezone they want via run (which the drivers would default to local timezone), or the server assumes they're speaking in UTC if the driver passes nothing.
The user can translate things to string representations on the server and store it in attributes, but those are strings, not times. They can't run time ops on it unless they call r.parse_time.
So, in this one particular case the __rql_type__ solution works fairly well, because our naive ordering on objects exactly matches the ordering we want (since _ is less than all letters and ms_since_epoch_utc will sort correctly).
So I wouldn't be incredibly opposed to doing it that way. The only large cost I can think of is that people could no longer use times as primary keys.
—
Reply to this email directly or view it on GitHubhttps://github.com//issues/977#issuecomment-22366007
.
@neumino that wouldn't be very clean. We should host a francophone version of ReQL on a different port and make sure that all user facing text (including server generated error messages) is written in idiomatic French.
Activity
AtnNn commentedon Jun 10, 2013
Can we spend some more time on this and add separate data types?
jdoliner commentedon Jun 10, 2013
@AtnNn I'm in your boat on this one but let's wait until we have the discussion phase.
coffeemug commentedon Jun 11, 2013
Moving back to backlog. Nested objects are more important.
Linicks commentedon Jun 11, 2013
Having built in Date types and tools would be a major +1 :)
perone commentedon Jun 24, 2013
+1
hcarvalhoalves commentedon Jun 28, 2013
Why reimplementing date manipulation primitives would be necessary? Shouldn't suffice to have queries take native date types and have the driver convert to a wire format?
coffeemug commentedon Jun 28, 2013
@hcarvalhoalves suppose you wanted a query that says something like "Give me every event that happened on a Monday". In order for that to work on the server side, it would need a db-level function that determines the day of the date, otherwise you'd have to transfer all the data to the client first and do the processing on the client.
hcarvalhoalves commentedon Jun 29, 2013
@coffeemug Right, I get what you mean now. I just didn't get where the above methods fit in your example though. I expected date manipulation would look something like this:
No?
Sorry if my questions are stupid, I'm still figuring out RethinkDB, I'm not sure what's possible or not.
coffeemug commentedon Jun 29, 2013
Yep, this is exactly right. Barring some syntactic debate, this is exactly how we'd do it, I think.
AtnNn commentedon Jul 2, 2013
I would like to propose a few modifications and additions to @mlucy's proposal.
I'm going to call these objects times instead of dates.
In the iso8601 representation, the time component should be optional as well as the time zone component.
The P and T prefixes are optional for durations. One can write "1M" or "1:30" instead of "P1M" and "PT1:30". Durations can also be represented simply as a number of seconds.
All operations assume that all days have exactly 86400 seconds. "23:60" is considered equal to "23:59".
r.run() takes an additional time_zone argument that specifies the default time zone used in the query. The client drivers automatically set the time_zone to the local time zone of the client. The default time zone is only used where it is explicitly mentioned in this proposal. If time_zone is set to the empty string, time zone defaulting is disabled and all operation that would require using the default time zone fail.
When only one of time or other_time has a time zone, the other value is considered to be in the default time zone. If both time and other_time have no time zone, neither does the result.
There are no intervals.
duringsimply takes two arguments.Times default to the default time zone if the time zone component is missing, unless all times have no time zones.
If the time is not present, the corresponding accessors return null. Ditto for the time zone.
A constructor.
Equivalent to time.time_sub("1970-01-01T00:00Z").totalSeconds()
The current time in the tz time zone. If tz is not specified, use the default time zone. If the default time zone is not specified, use "Z".
Format and parse times like strftime and strptime.
with_time_zone returns the same time in a different time zone. If the time has no time zone, it converts from the default time zone. With no arguments, it converts to the default time zone.
set_time_zone simply changes the time zone component.
Instead of using iso8601 string representation, times could instead be represented as a number of seconds since epoch and durations as a number of seconds. There are a few advantages:
There are also some disadvantages:
A better representation would be a new native type instead of a pseudo-type. This would have all these advantages and none of these disadvantages.
coffeemug commentedon Jul 2, 2013
FYI, this issue looks like the only one in 1.8-required that's non-trivial and wide open (since we didn't discuss it much). Let's try to hammer this out. (P.S. my feedback on the specific proposal coming soon)
mlucy commentedon Jul 2, 2013
This is ambiguous. In ISO8610
P1Mmeans one month andPT1Mmeans one minute.What's the motivation for this? That sound wacky.
Could we call this
dur_secondsfor consistency?Why is sunday numbered from 0 when january is numbered from 1?
This name sounds slightly off to me. See below for discussion of how I think we should handle ISO8601 vs. epoch time.
This seems strange to have in the server. Shouldn't people be doing this in the clients once they've retrieved the date? Also, we'd be violating the standard unless we want the clients to send the whole locale to the server.
Could we call this
in_time_zone? It seems less ambiguous to me.I think this is the biggest thing left to decide. Here's what I think we should do (although I need to think about it more):
dur_to_iso8601andtime_to_iso8601for when people want to do regexp matching or something. Have the functionsdur_to_epochandtime_to_epochfor when people have an ISO8601 string that they want in seconds. (Maybe with better names?)date_add,dur_sub, etc.) polymorphic, and let them accept either numbers (which are interpreted as seconds) or ISO8601 strings, but have them always return seconds since epoch.coffeemug commentedon Jul 2, 2013
Sorry to complicate matters, but I must. First, a few random thoughts:
time_sub, instead of adding a propertimetype and makingsubpolymorphic, we will very quickly grow to regret this decision.r.expr(datetime.now())should work in Python. They should be able to saytable.insert({time: datetime.now()}), and get a native Pythondatetimeobject if they get the row back IMO. (at the very least, we should consider this carefully)I propose the following:
{ __reql_type__: 'time', ms_since_epoch_utc: X }add,gt, etc. polymorphic on time)__reql_type__: 'time'back to native object (e.g.datetimein Python,Datein JS, etc.)getYearandsetYear)r.row('time_field').getDay.eq('Monday')they either pass the timezone they want viarun(which the drivers would default to local timezone), or the server assumes they're speaking in UTC if the driver passes nothing.r.parse_time.mlucy commentedon Jul 2, 2013
So, in this one particular case the
__rql_type__solution works fairly well, because our naive ordering on objects exactly matches the ordering we want (since_is less than all letters andms_since_epoch_utcwill sort correctly).So I wouldn't be incredibly opposed to doing it that way. The only large cost I can think of is that people could no longer use times as primary keys.
What do you think, @AtnNn ?
138 remaining items
wmrowan commentedon Aug 7, 2013
@neumino
time.toISO8601()neumino commentedon Aug 7, 2013
Err, I should have ack with insensitive case. Thanks @wmrowan
wmrowan commentedon Aug 7, 2013
@neumino I think implementing
flooris a better solution to your problem then truncating the output ofsecondsaddingmilliseconds.neumino commentedon Aug 8, 2013
The review for docs has been completed and merge in
dates.mlucy commentedon Aug 8, 2013
This is finally in next.
jdoliner commentedon Aug 8, 2013
Commit hash?
On Thu, Aug 8, 2013 at 4:30 PM, Michael Lucy [email protected]:
coffeemug commentedon Aug 8, 2013
Slow clap
mlucy commentedon Aug 8, 2013
f8ae1a8
coffeemug commentedon Aug 8, 2013
Ok, so @mglukhovsky just pointed out that slow clap is usually a sarcastic clap. Let's write this one off to cultural differences :)
mglukhovsky commentedon Aug 8, 2013
🎆 Can't wait to play with this!
jdoliner commentedon Aug 8, 2013
I think the comedy of errors that made up this issue's circumstances might justify the slow clap here by american standards.
neumino commentedon Aug 8, 2013
That's pretty cool :)
I suggest now that we should have a flag "lang" in the driver, so I can use
r.lundiinstead ofr.mondayetc.wmrowan commentedon Aug 9, 2013
@neumino that wouldn't be very clean. We should host a francophone version of ReQL on a different port and make sure that all user facing text (including server generated error messages) is written in idiomatic French.
AtnNn commentedon Aug 9, 2013
Before we can support French and other languages that are not ASCII we need to fix our string encoding (#1181)