Tips for setting up date ranges in Fullcalendar

Currently, I am in the process of developing a fire department shift calendar using fullcalendar. I am faced with the task of altering the CSS for specific dates at irregular intervals that do not correspond to typical days of the week.

In this particular scenario, each shift consists of three 24-hour periods within a nine-day cycle. Each day within a shift is denoted by a distinct color on the calendar. For reference, please see the following example: Shift Calendar Example

While I have successfully managed to modify the CSS for date cells and repeat them based on days of the week as illustrated in the code snippet below:

events: [{
            title:"Shift One",
            id: "one",
            allDay: true,
            rendering: 'background',
            color: 'blue',
            dow: [1,4]   // Repeat monday and thursday
            }]

I am now inquiring whether it is possible to establish a pattern involving days 1,3,5 and replicate this pattern on day 10?

Answer №1

It seems that a solution like this is effective https://jsfiddle.net/wavzxkjw/

The color pattern for shift days starting on 2017-01-01 repeats every 18 days, allowing us to calculate the color for any given day based on that.

However, the initial code block does not support calculations prior to 2017-01-01

$(document).ready(function() {
  $('#calendar').fullCalendar({
    defaultDate: '2017-01-01',
    dayRender: function(date, cell) {
      $(cell).css('background-color', determineColorForDay(date));
    }
  });

  function determineColorForDay(date) {
    var colorPattern = [
      'red', 'goldenrod', 'red', 'goldenrod', 'black', 'goldenrod', 'black',
      'red', 'black', 'red', 'goldenrod', 'red', 'goldenrod', 'black',
      'goldenrod', 'black', 'red', 'black'
    ];
    var index = Math.abs(moment('2017-01-01').diff(date, 'days')) % colorPattern.length;
    return colorPattern[index];
  }
});

Below is an improved version with better clarity and added functionality for past and future date calculations. The function name has been updated for better representation of its purpose https://jsfiddle.net/wavzxkjw/2/

$(document).ready(function() {
  $('#calendar').fullCalendar({
    defaultDate: '2017-01-01',
    dayRender: function(date, cell) {
      $(cell).css('background-color', determineColor(date));
    }
  });

  function determineColor(date) {
    var patternStart = '2017-01-01'; 
    var colorPattern = [
      'red', 'goldenrod', 'red', 'goldenrod', 'black', 'goldenrod', 'black',
      'red', 'black', 'red', 'goldenrod', 'red', 'goldenrod', 'black',
      'goldenrod', 'black', 'red', 'black'
    ];
    var patternLength = colorPattern.length; 
    var daysFromStart = Math.abs(moment('2017-01-01').diff(date, 'days')) % patternLength;
    var index = 0; 
    if (date.format('YYYY-MM-DD') < patternStart) {
      index = (patternLength - (daysFromStart % patternLength)) % patternLength;
    } else {
      index = daysFromStart % patternLength;
    }
    return colorPattern[index];
  }
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Stay afloat at the bottom of the webpage without using xhtml

Currently working on Moss 2007 and in need of creating a floating button at the bottom of the screen. This button should move down as I scroll down and up when scrolling back up. Although it can be easily achieved with xhtml, the challenge lies in not bei ...

Ways to achieve an arched shadow effect for an image using React and Tailwind CSS?

Looking to add a unique touch to my React project with a shadow effect resembling an arch shape at the top of an image using Tailwind CSS. The ultimate goal is to create a semi-transparent arch-shaped shadow covering the top portion of the image, similar t ...

Unable to apply .png image using the content property in a Symfony project

I have a png image located in src/AppBundle/Resources/public/img To set the png image using the css content property, I used this code: content: url(../../public/assets/img/optional-checked.png); However, I encountered an error: GET http://127.0.0.1:80 ...

React Native: The behavior of the 'top' property is consistent, while the 'bottom' property is not performing as anticipated

Within my React Native application, I have implemented the following code: <View style={{ width: 50, height: 50, borderWidth: 1, }} > <View style={{ width: 5, height: 5, backgroundColor: 'red', top: 10, ...

There is no element available to input text using send_keys in Selenium

Currently learning about selenium, please pardon any errors. Thank you :) I am trying to scrape a website that allows users to create blogs on 'tistory' using selenium. In order to publish an article, I need to choose between default mode, mark ...

Utilizing CSS to position an image at both the top and bottom of a webpage

I have been struggling to find a solution to this particular issue. My goal is to position an image at both the top and bottom of the page using a background property. I understand that by making the positioning relative, the image will be placed at the bo ...

Eliminate the horizontal scrollbar generated by a certain div

I'm working on the following HTML structure: <div id="container"> <div id="content"></div> </div> The container div is set at a width of 1050px and has a shadow background that repeats vertically. The content div is 950px ...

Combining keyframe properties in a more efficient way using less code

While attempting to develop a LESS mixin for CSS3 keyframes, I encountered the typical way of chaining IDs and classes: #idOne, #idTwo, .classOne, .classTwo { ... } Nothing groundbreaking there. What I'm currently working on is crafting the foll ...

What is the best way to change the maxWidthLg of Material UI's .MuiContainer?

I need to remove the max-width that is set in the theme. When I look at it in Chrome and uncheck the option, it functions as desired: @media (min-width: 1280px) .MuiContainer-maxWidthLg { max-width: 1280px; } How can I achieve this? I have attempted ...

The margin-bottom attribute does not display any vacant area

I recently attempted to center the inner box within the outer box in this codepen. To achieve this, I utilized a workaround by applying margin-bottom: 20px;. However, it appears that this approach did not generate any visible space between the bottom line ...

The background colors are not extending to the full width of the screen

I am facing an issue in my CSS code while trying to create a footer. The background color is not filling the width of the screen, and I had encountered the same problem earlier. Here is how it looks: (https://i.sstatic.net/5VxYU.png) HTML Code: *{ ma ...

Having Trouble with Your Instafeed Script

I've been working on a project that involves integrating an Instagram feed into a website. However, I'm facing difficulties getting it to function properly. Here's the code that I have implemented. <script type="text/javascript"> ...

Bug on a Safari browser when using a dotted border on a table

Issue in Safari and Chrome browsers: CSS: TABLE { width: 100%; clear: both; border: 0px; border-collapse: collapse; } TABLE TH, TABLE TD { padding: 10px; text-align: center; border: 1px dotted #898989; } ...

Is there a way to make the text scroll up automatically when it overflows?

I have a straightforward div element that occupies the header's height but currently has a fixed height of 400px for testing purposes. Here is how it currently appears: https://i.sstatic.net/gg6kQ.png I am utilizing the type-it library to dynamical ...

Any tips or hacks for successfully implementing vw resizing on the :before pseudo-element in webkit browsers?

When using vw sizes on webkit browsers, a well-known bug can occur where they do not update when the window is resized. The typical workaround for this issue has been to employ javascript to force a redraw of the element by reassigning the z-index upon res ...

Ways to activate a hover effect on an external element

Hello everyone! This is my first time posting here and I've been struggling to find a solution with my limited knowledge. I could really use some help on this: Is there a way to trigger a hover effect on an element that is not related (no parent, ch ...

Achieving a transparent inner box-shadow effect on hover: a step-by-step guide

Is there a way to make the black ring transparent upon hover by changing box-shadow: 0 0 0 5px #000, 0 0 0 10px green to box-shadow: 0 0 0 5px transparent, 0 0 0 10px green? It doesn't seem to be working for me. Any suggestions on how to achieve this ...

Enhancing websites with CSS3 and VueJS for fluid and captivating background gradients transitions

After implementing a logic in the application, the gradient is now changing dynamically. <template> <div :style="`background-image: ${backgroundImage}`" class="background"> <snackbar /> <nuxt /> <default-footer /&g ...

Enhance data table by displaying a set number of rows that do not completely fill the table's height

I'm currently attempting to implement a v-data-table with fixed header and footer. However, I've encountered an issue where if I set the table height to be larger than the row height, the table takes on the defined height and the footer ends up b ...

How can I resolve the issue of a lengthy link spanning two lines in Internet Explorer, while displaying correctly in other browsers on a Bootstrap navigation

Currently in the process of developing a responsive website with Bootstrap. The navigation buttons at the top are displaying correctly in Chrome, Safari, and Firefox, but in IE, the button labeled "Public Consultation" is wrapping onto two lines. I suspec ...