superset icon indicating copy to clipboard operation
superset copied to clipboard

Time grain (week) starts from Sunday

Open mahedi0244 opened this issue 10 years ago • 13 comments

I am using caravel for a while and when I add a slice where the visualization type is "Time Series", I noticed that the week starts from Sunday by default. It can be changed easily to start the week on Monday, instead of Sunday. Is the caravel community thinking about adding a feature to select the start date or I can change it to Monday by default if you suggest.

mahedi0244 avatar Aug 17 '16 17:08 mahedi0244

@mahedi0244 nice finding! Is this on the python or js side? maybe we can have do it based on the locale?

xrmx avatar Aug 18 '16 09:08 xrmx

@xrmx this is the part that I had to change and it seems like working https://github.com/mahedi0244/caravel/commit/7743cb2001ed6fde3b47778b0702f16ed14d1989

mahedi0244 avatar Aug 18 '16 15:08 mahedi0244

@mahedi0244 so it looks like that just removing the - 1 DAY would be enough no?

Also note to self: this is db specific

xrmx avatar Aug 21 '16 16:08 xrmx

@xrmx DAYOFWEEK(created_at) —>returns 1 for Sunday, 2 for Monday and so on.

DATE_SUB(created_at, INTERVAL DAYOFWEEK(created_at) - 1 DAY) —> will subtract days in such a way so it returns the previous Sunday

If I just replace "DAYOFWEEK(created_at) - 1 DAY" with “WEEKDAY(created_at) - 0 DAY” , the week will start on Monday, as WEEKDAY(created_at) returns 0 for Monday, 1 for Sunday and so on.

mahedi0244 avatar Aug 22 '16 16:08 mahedi0244

@mahedi0244 thanks for the explanation! but why - 0 day then is weekday is fine on its own?

xrmx avatar Aug 22 '16 16:08 xrmx

@xrmx “WEEKDAY(created_at) DAY” will also work

mahedi0244 avatar Aug 22 '16 17:08 mahedi0244

Just add a new grain "week (starting Monday)". You then need to re-label the current one to "week (starting sunday)"

mistercrunch avatar Aug 30 '16 05:08 mistercrunch

I've been using superset for a while, just wondering if there is a feature on the dashboard that can alter time grain as we desired?

I mean the time grain config is the best, just wondering if we can also change it on dashboard view for various users.

daudryc avatar Feb 09 '17 03:02 daudryc

Notice: this issue has been closed because it has been inactive for 438 days. Feel free to comment and request for this issue to be reopened.

mistercrunch avatar Apr 23 '18 05:04 mistercrunch

@mistercrunch could you please reopen this?

xrmx avatar Apr 23 '18 07:04 xrmx

I need this feature too

ismael-benitez avatar Aug 22 '18 15:08 ismael-benitez

We have this for some database, it's just a matter of adding the proper expression for your database engine. Here's how it's done on Presto: https://github.com/apache/incubator-superset/blob/master/superset/db_engine_specs.py#L718

Which engine are you all interested in? Note that the key used in the time_grain_functions should match the ones defined here: https://github.com/apache/incubator-superset/blob/master/superset/db_engine_specs.py#L69-L72

mistercrunch avatar Aug 22 '18 16:08 mistercrunch

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. For admin, please label this issue .pinned to prevent stale bot from closing the issue.

stale[bot] avatar Apr 10 '19 16:04 stale[bot]