Skip to content

Commit

Permalink
Fix calendar month timezone with (-), get posts for prev&next month o…
Browse files Browse the repository at this point in the history
…n month
  • Loading branch information
lao9s committed May 9, 2024
1 parent 2476102 commit 4632757
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
18 changes: 10 additions & 8 deletions resources/js/Components/Calendar/Month/CalendarMonth.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const props = defineProps({
const emit = defineEmits(['dateSelected'])
const selectedDate = ref(new Date(props.initialDate));
const selectedDate = ref(new Date(`${props.initialDate}T00:00:00`));
const days = computed(() => {
return [
Expand Down Expand Up @@ -81,26 +81,26 @@ const previousMonthDays = computed(() => {
? firstDayOfTheMonthWeekday - props.weekStartsOn
: props.weekStartsOn ? 6 : 0;
const previousMonthLastMondayDayOfMonth = getDate(subDays(new Date(currentMonthDays.value[0].date), visibleNumberOfDaysFromPreviousMonth))
const previousMonthLastMondayDayOfMonth = getDate(subDays(new Date(`${currentMonthDays.value[0].date}T00:00:00`), visibleNumberOfDaysFromPreviousMonth))
const previousMonth = subMonths(selectedDate.value, 1);
return [...Array(visibleNumberOfDaysFromPreviousMonth)].map(
(day, index) => {
const date = new Date(`${getYear(previousMonth)}-${(getMonth(previousMonth) + 1).toString().padStart(2, '0')}-${(previousMonthLastMondayDayOfMonth + index).toString().padStart(2, '0')}`);
const date = new Date(`${getYear(previousMonth)}-${(getMonth(previousMonth) + 1).toString().padStart(2, '0')}-${(previousMonthLastMondayDayOfMonth + index).toString().padStart(2, '0')}T00:00:00`);
return {
date: format(date, 'yyyy-MM-dd'),
isDisabled: isDatePast(date, props.timeZone),
posts: []
posts: getDayPosts(date)
};
}
);
})
const currentMonthDays = computed(() => {
return [...Array(numberOfDaysInMonth.value)].map((day, index) => {
const date = new Date(`${year.value}-${month.value}-${(index + 1).toString().padStart(2, '0')}`);
const date = new Date(`${year.value}-${month.value}-${(index + 1).toString().padStart(2, '0')}T00:00:00`);
return {
date: format(date, 'yyyy-MM-dd'),
Expand All @@ -120,16 +120,18 @@ const nextMonthDays = computed(() => {
const nextMonth = addMonths(selectedDate.value, 1);
return [...Array(visibleNumberOfDaysFromNextMonth)].map((day, index) => {
const date = new Date(`${getYear(nextMonth)}-${(getMonth(nextMonth) + 1).toString().padStart(2, '0')}-${(index + 1).toString().padStart(2, '0')}T00:00:00`);
return {
date: format(new Date(`${getYear(nextMonth)}-${(getMonth(nextMonth) + 1).toString().padStart(2, '0')}-${(index + 1).toString().padStart(2, '0')}`), 'yyyy-MM-dd'),
date: format(date, 'yyyy-MM-dd'),
isDisabled: false,
posts: []
posts: getDayPosts(date)
};
});
})
const getWeekday = (date) => {
return getDay(typeof date === 'string' ? new Date(date) : date);
return getDay(typeof date === 'string' ? new Date(`${date}T00:00:00`) : date);
}
const getDayPosts = (date) => {
Expand Down
4 changes: 2 additions & 2 deletions resources/js/Components/Calendar/Month/MonthDayItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const props = defineProps({
})
const label = computed(() => {
return format(new Date(props.day.date), 'd');
return format(new Date(`${props.day.date}T00:00:00`), 'd');
})
const style = computed(() => {
Expand All @@ -40,7 +40,7 @@ const style = computed(() => {
const add = () => {
const now = utcToZonedTime(new Date().toISOString(), props.timeZone);
let scheduleAt = `${props.day.date} ${format(now, 'H:mm')}`;
let scheduleAt = `${props.day.date} ${format(now, 'HH:mm')}`;
router.visit(route('mixpost.posts.create', {schedule_at: scheduleAt}));
}
Expand Down
4 changes: 2 additions & 2 deletions src/Builders/Filters/PostScheduledAt.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public static function apply(Builder $builder, $value): Builder
$date = Carbon::parse($value['date']);

if ($value['calendar_type'] === 'month') {
return $builder->whereYear('scheduled_at', $date->year)
->whereMonth('scheduled_at', $date->month);
return $builder->whereDate('scheduled_at', '>=', $date->clone()->startOfMonth()->subDays(10)->toDateString())
->whereDate('scheduled_at', '<=', $date->clone()->endOfMonth()->addDays(10)->toDateString());
}

if ($value['calendar_type'] === 'week') {
Expand Down

0 comments on commit 4632757

Please sign in to comment.