Exclude weekends from DateTime

Currently working on a task list and aiming to set the default date to 3 days from now, excluding weekends. Utilizing Vue and thinking a computed property might be the solution?

DateTime.utc().plus({ days: 3 }).toFormat('yyyy-MM-dd HH:mm:ss'),

Seeking advice on how to skip setting the date to Saturday or Sunday. Have tried researching online with no luck in finding a workaround...

Answer №1

One effective solution is leveraging the luxon-business-day package.

However, if you prefer not to incorporate any additional dependencies, you can take the following steps:

  • Determine the date of the upcoming Saturday
  • Check if you need to account for a specific number of days
  • If necessary, calculate the difference in days to be added

const dayToAdd = 3;
const DateTime = luxon.DateTime;

var nextSaturday = DateTime.utc().startOf('week').plus({ week: 1 }).minus({days: 2});
var dayDifference = nextSaturday.diff(DateTime.utc(), ["days"]).toObject().days;


var addAfterWeekend = 0;
if (dayDifference < dayToAdd) {
  addAfterWeekend = dayToAdd - dayDifference;
}

var date = DateTime.utc().plus({ days: dayToAdd + addAfterWeekend });

console.log(date.toFormat('yyyy-MM-dd HH:mm:ss'));
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d5b9a0adbabb95e4fbe7e4fbe4">[email protected]</a>/build/global/luxon.min.js"></script>

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

The issue arises when attempting to utilize ExpressJS middleware in conjunction with NextJS Link feature

Incorporating Next with Express routes, I have set up a scenario where /a should only be accessible to authorized individuals, while /b is open to the public. ... other imports... const app = next({ isDev }) const handle = app.getRequestHandler() async f ...

Utilizing props to transfer data between components in ReactJS

I have a React application where I am binding text values when a specific div is clicked. However, I am now faced with the challenge of passing these text values to another component using props. This is what my code looks like: class PostOptionBar exten ...

The pagination messages in the Telerik Kendo UI Grid Vue do not appear to be functioning properly

I've been attempting to modify the pagination display message, but I'm encountering an issue. The default message currently looks like this: https://i.stack.imgur.com/MYmoz.png '{0} - {1} of {2} items' For example: "1 - 10 of 100 ...

automatically closing bootstrap alerts upon form submission

I'm working on an ajax form that sends data to a database and utilizes bootstrap alerts to notify the user when the process is successful. I want these alerts to automatically close after a certain period of time, consistently. Here's the issue: ...

I encountered an error while trying to deploy my next.js project on Vercel - it seems that the module 'react-icons/Fa' cannot be found, along with

I'm currently in the process of deploying my Next.js TypeScript project on Vercel, but I've encountered an error. Can someone please help me with fixing this bug? Should I try running "npm run build" and then push the changes to GitHub again? Tha ...

Node.js Link Management: A Guide to Updating Links

For some time now, I've been attempting to update the tabs on my navigation bar (including the links) when a user logs in. The issue arises on the index page, where users can access it both when logged in and not logged in. In my navigation bar, all t ...

Implement a global interceptor at the module level in NestJS using the Axios HttpModule

Is there a way to globally add an interceptor for logging outgoing requests in Angular? I know I can add it per instance of HttpService like this: this.httpService.axiosRef.interceptors.request.use((config) => ...) But I'm looking to add it once a ...

JavaScript code not functioning on WordPress website (no impact)

I've encountered a strange problem. Here is the code snippet: (function($){ $("#maps1").hover( function(){$("#kontakt_os_1").hide();} ); $("#maps2").hover( function(){$("#kontakt_os_2").hide();} ); $("#maps3").hover( ...

What steps can I take to avoid keypress events causing issues with the browser's input functionality?

Utilizing Bootstrap's modal component, I have implemented an "Add User" dialog within my web application. In order to streamline the user experience and enable quick data entry, I am aiming for the escape and enter keys to close and submit the form re ...

What is the best way to ensure that one method waits for another method to complete before proceeding?

Below is a React method that needs completion for uploading images to cloudinary and setting the URL in state before executing the API call addStudent. The order of execution seems correct at first glance, but the last API call crashes due to base64 data n ...

The method wrapper.setValue() is not suitable for use on EL-INPUT

Attempting to call a Vue component for unit testing with Jest, trying to set a value in an input text field. Below is the content of my "file.vue" file: <el-form-item label="Nombre" data-test="id-form"> <el-input v ...

Prisma and Next.js: Changes to content require re-deployment for updates to take effect

Just recently, I launched a new website on Vercel. My web application is being built with Prisma and Next.js. However, I'm currently facing an issue where the content doesn't update in real-time unless I manually re-deploy the application. Here&a ...

Material Design - The element provided is not valid: it should be a string for built-in components or a class/function for composite components, but instead it is an object

How are you today? I am currently working on a React project using Webpack and Babel. I encountered an issue when trying to incorporate Material UI components from https://mui.com/. Whenever I import a MUI component into my project, I receive the followin ...

Properly configuring paths in react-native for smooth navigation

When working on my React-Native project, I noticed that my import paths look something like this: import { ScreenContainer, SLButton, SLTextInput, } from '../../../../../components'; import { KeyBoardTypes } from '../../../../../enums ...

Vue.js and Element UI combine to display a custom HTML message in a MessageBox component

I am currently utilizing vue-js 2.3 along with element-ui. Specifically, my question pertains to the MessageBox component and you can access the documentation for it here Issue I am interested in incorporating an html message within the MessageBox. More ...

Bringing in SCSS using Typescript, React, and Webpack

I am trying to utilize .scss classes by importing them and applying them to the className property of a React component. Here is the structure of my project : root/ ... config/ ... webpack.config.js src/ ... global.d.ts app/ ...

Obtain merged types by accessing a particular property within a deeply nested object

My query is reminiscent of a post on Stack Overflow titled Get all value types of a double-nested object in TypeScript However, my specific requirement involves extracting union types from the values of a designated property. const tabsEnum = { IDCardRe ...

Tips for passing a function and an object to a functional component in React

I am struggling with TypeScript and React, so please provide clear instructions. Thank you in advance for your help! My current challenge involves passing both a function and an object to a component. Let's take a look at my component called WordIte ...

Update the statically generated page (data) with new information after it has been loaded on the client side

Consider a scenario where I have a webpage in Nuxt: data() { return { items: [] }; }, asyncData() { return axios.get('site.com/url') .then((response) => { return { ...

Troubleshooting issue: Django and Javascript - Why is my dependent dropdown feature not

I am new to using a combination of Javascript and Django. Below is the script I have written: <script> $(document).ready(function() { $("#source").change(function() { var el = $(this); var reg = ...