Baremetrics / calendar

Date range picker for Baremetrics
MIT License
681 stars 79 forks source link

Future and customizable preset range #9

Closed tzi closed 8 years ago

tzi commented 9 years ago

Hi!

Thanks for sharing this awesome tool!

The preset range, like last month, are a really great idea. It would be great if we could set:

Cheers, Thomas.

kalepail commented 9 years ago

I think this would be a great addition! I'm gonna add the help wanted label and anyone who wants to tackle this feel free to submit a PR.

jclusso commented 9 years ago

I've tacked a few on here for today, last 24 hours and last 7 days. This isn't expandable and probably not the cleanest solution, but maybe it's useful for someone else.

Around line 215

if (typeof month_count == 'number') {
    first_day = moment(date).subtract(is_last_day ? month_count - 1 : month_count, 'month').startOf('month');

    if (month_count == 12)
        first_day = moment(date).subtract(is_last_day ? 11 : 12, 'month').startOf('month').startOf('day');
} else if (month_count == 'all') {
    first_day = moment(self.earliest_date);
    last_day = moment().startOf('day');
} else if (month_count == 'week') {
    first_day = moment(self.latest_date).subtract(6, 'day');
    last_day = moment(self.latest_date);
} else if (month_count == 'today') {
    first_day = moment(self.latest_date).startOf('day')
    last_day = moment()
} else if (month_count == 'hour') {
    first_day = moment().subtract(24, 'hour')
    last_day = moment()
} else {
    first_day = moment(self.latest_date).subtract(29, 'day');
    last_day = moment(self.latest_date);
}

Around line 725

'<ul class="dr-preset-list" style="display: none;">' +
'<li class="dr-list-item" data-months="today">Today <span class="dr-item-aside"></span></li>' +
'<li class="dr-list-item" data-months="hour">Last 24 hours <span class="dr-item-aside"></span></li>' +
'<li class="dr-list-item" data-months="week">Last 7 days <span class="dr-item-aside"></span></li>' +
'<li class="dr-list-item" data-months="days">Last 30 days <span class="dr-item-aside"></span></li>' +
'<li class="dr-list-item" data-months="1">Last month <span class="dr-item-aside"></span></li>' +
'<li class="dr-list-item" data-months="3">Last 3 months <span class="dr-item-aside"></span></li>' +
'<li class="dr-list-item" data-months="6">Last 6 months <span class="dr-item-aside"></span></li>' +
'<li class="dr-list-item" data-months="12">Last year <span class="dr-item-aside"></span></li>' +
'<li class="dr-list-item" data-months="all">All time <span class="dr-item-aside"></span></li>' +
mlisbit commented 8 years ago

I made a pull request. You can pass in a history_options array containing, labels, days/weeks/months or years, and an option to round to nearest selected day/week/month/year.

jclusso commented 8 years ago

@mlisbit hourly support would be nice too!

kalepail commented 8 years ago

Added customizable presets in https://github.com/Baremetrics/calendar/releases/tag/v1.0.6 Not ever really planning on adding hour support. That would be more like an addon rather then a feature for a date picker.