Skip to content
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

truncate command for dates #3710

Open
mlucy opened this issue Feb 1, 2015 · 9 comments
Open

truncate command for dates #3710

mlucy opened this issue Feb 1, 2015 · 9 comments

Comments

@mlucy
Copy link
Member

mlucy commented Feb 1, 2015

@coffeemug asked for this and can maybe give more information.

@mlucy mlucy added this to the subsequent milestone Feb 1, 2015
@coffeemug
Copy link
Contributor

Currently I can run:

> r.now().day()
2

> r.now().month()
2

// etc.

I want to be able to do:

> r.now().day({prefix: true})
"2015-02-02"

> r.now().month({prefix: true})
"2015-02"

// etc.

This would make it easier to group by month or day, whereas right now I would have to construct the group manually and it's enough of a pain to do it that RethinkDB isn't a great tool for such operations.

@coffeemug
Copy link
Contributor

Also note, the above is meant to illustrate what I want to do, not to dictate the API. We might want to come up with a different API to do it (for example, do we want to return strings or something else?), but I don't understand dates and times well enough to propose something sensible.

@marshall007
Copy link
Contributor

I'd much rather see a command that allows arbitrary formatting, something like:

> r.now().format("YYYY-MM-DD")
"2015-02-02"

> r.now().format("YYYY-MM")
"2015-02"

@VeXocide
Copy link
Member

VeXocide commented Feb 2, 2015

date has a nice format that might work, http://man7.org/linux/man-pages/man1/date.1.html.

@coffeemug
Copy link
Contributor

I really like the format command.

One concern I have with it is that whenever I format things like this I always find myself digging through documentation to find a correct string to represent what I want, which always annoys me. It doesn't seem very... conducive to quick and dirty time series grouping queries, though it might be a matter of good docs.

@VeXocide
Copy link
Member

VeXocide commented Feb 2, 2015

For the record, this is probably related to #3353 and #3387.

@danielmewes
Copy link
Member

I think I would prefer a format term over having a prefix opt arg.
Even though you might have to look up the placeholders to use in the format string, it is much more flexible and has a lot of other use cases as well.

@marshall007
Copy link
Contributor

@coffeemug: One concern I have with it is that whenever I format things like this I always find myself digging through documentation to find a correct string to represent what I want, which always annoys me.

Agreed, I think one solution would be to allow passing a "human-readable" unit (i.e. year, month, day, etc) which would give you an ISO 8601 formatted date up to and including the unit specified.

So .format('day') would just be an alias to .format('YYYY-MM-DD').

@timmaxw
Copy link
Member

timmaxw commented Feb 2, 2015

I think that YYYY-MM-DD is an easy enough format string to remember. The problem that I usually have with date format strings is that they look like %Y-%m-%d, not to be confused with %y-%m-%d, %Y-%M-%d, or %Y-%m-%D, all of which are valid format strings that do different things. If we design our format syntax so that YYYY-MM-DD literally works and does what it looks like, I think it would be OK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants