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

fix(VCalendar): remove default sorting of weekdays #19205

Merged
merged 1 commit into from
Feb 21, 2024

Conversation

hareland
Copy link
Contributor

@hareland hareland commented Feb 9, 2024

Ensuring that a custom ordered weekdays will display properly and not be sorted.
See https://vuetifyjs.com/en/components/calendars/#usage

Description

Ensuring that a custom ordered weekdays will display properly and not be sorted.

Markup:

See https://vuetifyjs.com/en/components/calendars/#usage

<template>
  <div>
    <v-sheet
        tile
        height="54"
        class="d-flex"
    >
      <v-select
          v-model="type"
          :items="types"
          dense
          variant="outlined"
          hide-details
          class="ma-2"
          label="View Mode"
      ></v-select>
      <v-select
          v-model="weekday"
          :items="weekdays"
          dense
          variant="outlined"
          hide-details
          label="weekdays"
          class="ma-2"
      ></v-select>
    </v-sheet>
    <v-sheet>
      <v-calendar
          ref="calendar"
          v-model="value"
          :weekdays="weekday"
          :view-mode="type"
          :interval-start="0"
          :events="events"
          title="test"
      ></v-calendar>
    </v-sheet>
  </div>
</template>
<script>
import {useDate} from 'vuetify'

export default {
  data: () => ({
    type: 'month',
    types: ['month', 'week', 'day'],
    weekday: [1, 2, 3, 4, 5, 6, 0],
    weekdays: [
      { title: 'Sun - Sat', value: [0, 1, 2, 3, 4, 5, 6] },
      {title: 'Mon - Sun', value: [1, 2, 3, 4, 5, 6, 0]},
      { title: 'Mon - Fri', value: [1, 2, 3, 4, 5] },
      { title: 'Mon, Wed, Fri', value: [1, 3, 5] },
    ],
    value: [new Date()],
    events: [],
    colors: ['blue', 'indigo', 'deep-purple', 'cyan', 'green', 'orange', 'grey darken-1'],
    titles: ['Martha', 'Oliver', 'Edgars'],
  }),
  mounted() {
    const adapter = useDate()
    this.getEvents({
      start: adapter.startOfDay(adapter.startOfMonth(new Date())),
      end: adapter.endOfDay(adapter.endOfMonth(new Date()))
    })
  },
  methods: {
    getEvents({start, end}) {
      const events = []

      const min = start
      const max = end
      const days = (max.getTime() - min.getTime()) / 86400000
      const eventCount = this.rnd(days, days + 20)

      for (let i = 0; i < eventCount; i++) {
        const allDay = this.rnd(0, 3) === 0
        const firstTimestamp = this.rnd(min.getTime(), max.getTime())
        const first = new Date(firstTimestamp - (firstTimestamp % 900000))
        const secondTimestamp = this.rnd(2, allDay ? 288 : 8) * 900000
        const second = new Date(first.getTime() + secondTimestamp)

        events.push({
          title: this.titles[this.rnd(0, this.titles.length - 1)],
          start: first,
          end: second,
          color: this.colors[this.rnd(0, this.colors.length - 1)],
          allDay: !allDay,
        })
      }

      this.events = events
    },
    getEventColor(event) {
      return event.color
    },
    rnd(a, b) {
      return Math.floor((b - a + 1) * Math.random()) + a
    },
  },
}
</script>

Ensuring that a custom ordered weekdays will display properly and not sorted.
@hareland hareland changed the title Ensure no default sorting of weekdays in VCalendar when a custom one is provided. Fix no default sorting of weekdays in VCalendar when a custom one is provided. Feb 9, 2024
@hareland hareland changed the title Fix no default sorting of weekdays in VCalendar when a custom one is provided. Remove default sorting of weekdays in VCalendar Feb 9, 2024
@MajesticPotatoe MajesticPotatoe added T: bug Functionality that does not work as intended/expected C: VCalendar VCalendar labs labels Feb 13, 2024
@MajesticPotatoe MajesticPotatoe changed the title Remove default sorting of weekdays in VCalendar fix(VCalendar): remove default sorting of weekdays Feb 13, 2024
@KaelWD KaelWD force-pushed the master branch 3 times, most recently from cd170f8 to 98e57dc Compare February 14, 2024 06:14
@johnleider johnleider added this to the v3.5.x milestone Feb 21, 2024
@johnleider johnleider merged commit dd007f9 into vuetifyjs:master Feb 21, 2024
9 of 10 checks passed
VIXI0 pushed a commit to VIXI0/vuetify that referenced this pull request Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: VCalendar VCalendar labs T: bug Functionality that does not work as intended/expected
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants