Skip to content

DateRangeComponent Documentation

Props

PropTypeDefaultRequiredDescription
valueObject{ startDate: "", endDate: "", dateType: "today", isBS: false, yearType: "" }NoThe v-model binding object containing date range configuration
searchOnLoadBooleanfalseNoWhether to automatically trigger the search event when component mounts
enableYearBooleanfalseNoWhether to show the year selector dropdown for fiscal year selection

Value Object Properties

PropertyTypeDescriptionFormat
startDateStringStart date of the rangeYYYY-MM-DD (always in AD)
endDateStringEnd date of the rangeYYYY-MM-DD (always in AD)
dateTypeStringCurrently selected date type option IDSee Date Type Options
isBSBooleanWhether Nepali calendar (BS) is currently activetrue or false
yearTypeStringSelected fiscal year (only relevant when enableYear is true)Fiscal year in YYYY format

Events

EventPayloadTriggerDescription
@inputUpdated value objectAny value changeStandard v-model event emitted when component state changes
@searchCurrent value objectSearch button click or predefined date type selectionEmitted when user initiates search or selects a predefined date range

Event Payload Structure

Both events emit the same payload structure:

javascript
{
  startDate: "2024-01-01",    // String: Start date in AD format
  endDate: "2024-01-31",      // String: End date in AD format  
  dateType: "month_to_date",  // String: Selected date type ID
  isBS: false,                // Boolean: Calendar system flag
  yearType: "2081"            // String: Selected fiscal year (when enableYear is true)
}

Date Type Options

The component provides the following predefined date range options (all calculations are based on BS/Nepali fiscal year):

OptionIDDescription
Year to dateyear_to_dateFrom fiscal year start to today
Quarter to datequarter_to_dateFrom current quarter start to today
Month to datemonth_to_dateFrom month start to today
Week to dateweek_to_dateFrom week start to today
TodaytodayCurrent date only
Last 30 dayslast_30_daysPrevious 30 days from today
Last 90 dayslast_90_daysPrevious 90 days from today
First quarter (Q1)first_quarterFull Q1 of fiscal year (respects yearType when enableYear is true)
Second quarter (Q2)second_quarterFull Q2 of fiscal year (respects yearType when enableYear is true)
Third quarter (Q3)third_quarterFull Q3 of fiscal year (respects yearType when enableYear is true)
Fourth quarter (Q4)fourth_quarterFull Q4 of fiscal year (respects yearType when enableYear is true)
CustomcustomManual date selection (automatically set when user picks dates manually)

Year Selection Feature

When enableYear prop is set to true, the component displays an additional dropdown for fiscal year selection:

  • Year Range: Shows 9 fiscal years (4 years before current, current year, and 4 years after)
  • Display Format: Shows fiscal years in YY/YY format (e.g., "80/81" for 2080/2081)
  • Default Selection: Defaults to current fiscal year
  • Quarter Integration: When a fiscal year is selected, quarterly options (Q1-Q4) use the selected year instead of current year
  • Storage Behavior: When enableYear is true, localStorage persistence is disabled to prevent conflicts

Year Type Options Format

The year dropdown is populated with fiscal year options in the following format:

javascript
{
  title: "80/81",    // Display format: last 2 digits of start/end year
  id: 2080           // Actual fiscal year start year
}

Local Storage Persistence

The component automatically saves user preferences to localStorage under the key dateRangeComponentValue. This includes:

  • Selected date range
  • Calendar system preference (AD/BS)
  • Date type selection

Note: Local storage persistence is disabled when enableYear prop is true to prevent conflicts with year-specific data.

On component initialization, it will restore previous settings if available, with the following priority:

  1. Explicitly passed props
  2. localStorage saved values (only when enableYear is false)
  3. Default values

Validation Features

  • Date Range Validation: Prevents start date from being greater than end date
  • Error Notifications: Shows toast notifications for validation errors (requires $toastr to be available)

Calendar System Toggle

  • Bootstrap Switch: Uses Bootstrap Switch for AD/BS toggle
  • Automatic Conversion: Seamlessly converts dates between calendar systems
  • Visual Labels: Shows "AD" and "BS" labels on the toggle switch

Basic Usage

vue
<template>
  <DateRangeComponent
    v-model="dateRange"
    :searchOnLoad="true"
    @search="handleSearch"
  />
</template>

<script>
import DateRangeComponent from './DateRangeComponent.vue'

export default {
  components: {
    DateRangeComponent
  },
  data() {
    return {
      // Component will use localStorage or defaults if properties are empty
      dateRange: {
        startDate: "",        // Optional: Will use today's date if not provided
        endDate: "",          // Optional: Will use today's date if not provided
        dateType: "",         // Optional: Will default to "today"
        isBS: undefined       // Optional: Will default to false
      }
    }
  },
  methods: {
    handleSearch(dateRangeData) {
      console.log('Search triggered:', dateRangeData)
      // dateRangeData contains: { startDate, endDate, dateType, isBS }
      // All dates are in AD format regardless of display calendar
      
      // Perform your search/filter operations here
      this.fetchData(dateRangeData.startDate, dateRangeData.endDate)
    }
  }
}
</script>

Usage with Year Selection

vue
<template>
  <DateRangeComponent
    v-model="dateRange"
    :enableYear="true"
    :searchOnLoad="false"
    @search="handleSearch"
    @input="handleDateChange"
  />
</template>

<script>
export default {
  data() {
    return {
      dateRange: {
        startDate: "",
        endDate: "",
        dateType: "first_quarter",
        isBS: false,
        yearType: "2081"          // Specific fiscal year
      }
    }
  },
  methods: {
    handleSearch(data) {
      console.log('Searching with range and year:', data)
      // data will include yearType when enableYear is true
    },
    handleDateChange(data) {
      console.log('Date range updated:', data)
      // Real-time updates including year changes
    }
  }
}
</script>

Advanced Usage with Initial Values

vue
<template>
  <DateRangeComponent
    v-model="dateRange"
    :searchOnLoad="false"
    @search="handleSearch"
    @input="handleDateChange"
  />
</template>

<script>
export default {
  data() {
    return {
      dateRange: {
        startDate: "2024-01-01",      // Specific start date
        endDate: "2024-03-31",        // Specific end date
        dateType: "first_quarter",    // Preset to Q1
        isBS: true                    // Start with Nepali calendar
      }
    }
  },
  methods: {
    handleSearch(data) {
      // Handle search operations
      console.log('Searching with range:', data)
    },
    handleDateChange(data) {
      // Handle any date range changes (real-time updates)
      console.log('Date range updated:', data)
    }
  }
}
</script>

Important Notes

  • Props Date: The date always need to be passed in AD format all the nepali calculation are done inside the component itself
  • Date Format Consistency: All dates are internally stored and emitted in AD format (YYYY-MM-DD) regardless of the display calendar system
  • Fiscal Year Based: All predefined date ranges are calculated based on Nepali fiscal year (Shrawan to Ashar)
  • Automatic Search: Search is automatically triggered when selecting predefined date types
  • Custom Mode: Manually selecting dates automatically switches to "Custom" mode
  • Persistence: User preferences are automatically saved and restored between sessions (disabled when enableYear is true)
  • Validation: Built-in validation prevents invalid date ranges and shows user-friendly error messages
  • Year Selection: When enableYear is true, quarterly date ranges respect the selected fiscal year instead of using current year
  • Year Range: The year selector shows 9 fiscal years centered around the current year (4 before, current, 4 after)