Determine the amount of time that can be allocated based on the attributes contained within the object

I am faced with a JSON structure like the one below:

var meetings = [
  {
    id: '1',
    start_time: "2020-11-15T08:30:00+00:00",
    end_time: "2020-11-15T14:15:00+00:00"
  },
  {
    id: '2',
    start_time: "2020-11-15T19:30:00+00:00",
    end_time: "2020-11-15T20:30:00+00:00"
  },
];

The two meetings are scheduled as follows: first from 08:30 to 14:15, and second from 19:30 to 20:30

In a day, there are 24 available hours for work, which means:

start_time = '00:00:00';
end_time = '23:59:00';

However, the required format should be:

var start_time = '2020-11-15T00:00:00+00:00';
var end_time = '2020-11-15T23:59:00+00:00';

How can I calculate the available hours considering the already scheduled meetings? For example, if the first meeting is from 08:30 to 14:15 and the second is from 19:30 to 20:30, the resulting JSON with available hours would be:

[
  {
    start_time:'2020-11-15T00:00:00+00:00',
    end_time:'2020-11-15T08:30:00+00:00'
  },

  {
    start_time:'2020-11-15T14:15:00+00:00',
    end_time:'2020-11-15T19:30:00+00:00'
  },

  {
    start_time:'2020-11-15T20:30:00+00:00',
    end_time:'2020-11-15T23:59:00+00:00'
  }
]

Answer №1

If functional programming is your preference for parsing and formatting, consider utilizing resources such as https://momentjs.com/ or . When it comes to calculations, you can possibly convert timestamps, perform operations, and then revert back to the desired format for presentation.

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

Angular workout with a handful of challenges

I'm struggling to complete an angular exercise that involves the following tasks: /* MAKE CHANGES TO THE CODE TO ACHIEVE THE FOLLOWING Activate the Band Name field only if all other fields are populated Update the bandName() validator so that it is ...

Click the navigation bar to toggle it on and off

I have a script that creates a navbar. Currently, the dropdown menu only opens when hovered over. The issue arises when accessing this on a mobile browser, as the dropdown menu does not open. How can I modify this script to make the dropdown menu open wh ...

There seems to be an issue with the border displaying correctly within the div element

I am currently working on developing a tag input system, but I am encountering some CSS issues. What I am aiming for is to have a green border that surrounds and contains the 2 divs inside it, however, this is not happening as expected. You can see the fi ...

initiating a submission upon the occurrence of an onchange event on an input field of type "file"

I have encountered an issue while trying to submit a form using the onchange event of an input element with type file. The problem is that it submits an empty form even when a file has been chosen. Here is the code snippet: var form = document.createElem ...

Retrieve Unformatted Text with CKEditor5

I am familiar with how to retrieve data using the CKEditor5 API as outlined in the documentation and on another discussion post on StackOverflow. However, I am encountering difficulties when attempting to retrieve plain text from the editor. The code I ha ...

What is the best way to prevent code execution until a value is returned by $.get?

My attempt to read data from a file and store it in an array using jQuery's get function has hit a snag. Since the get function is asynchronous, the code that comes after the $.get call runs before the data is defined. How can I make sure that the cod ...

"Encountered a problem while setting up the Mailgun webhook to handle both multipart and URL encoded

I have been working on creating a web hook listener for Mailgun, and I encountered an issue when I realized that Mailgun can post webhooks using either multipart or x-www-form-urlencoded content-types. Currently, my code uses Multer to handle multipart b ...

Requirements for Method Decorators - The complete path of the class module using the decorator must be provided

Upon running the decorator (method decorators) function, we are provided with access to target, methodName, and descriptor. I am seeking the module path for target in this specific scenario. Essentially, I want the file path that points to the module that ...

Tips for creating Firestore rules for a one-on-one messaging application

After creating a one to one chat app for a website using Firebase and Firestore, I am now looking to set up the Firebase Firestore rules for the same. The functionality of the app involves checking if the user is [email protected], then retrieving chatids ...

Issues arise in TypeScript 5.1.3 with lodash due to type errors involving excessively deep type instantiation, which may potentially be infinite

Recently, I made updates to my Ionic/Angular project and now it is running Angular version 16.1.3 along with TypeScript version 5.1.3. In addition to this, my project also includes the following dependencies: "lodash-es": "^4.17.21", ...

The antithesis of jQuery's .parents() selector

I am currently developing a userscript for a webpage with an old-fashioned design consisting mainly of tables. My goal is to access a long table of fields so that they can be filled in automatically by the script. To simplify, the structure is as follows: ...

Mastering the art of writing protractor scenarios

In a hypothetical scenario where an Angular app consists of two pages - one for contacts (featuring a table with contacts and an "add new contact" button) and another for adding a new contact, the following steps can be outlined: Click on the "add" butto ...

Modifying the color of the error icon in Quasar's q-input component: a step-by-step guide

https://i.stack.imgur.com/4MN60.png Is it possible to modify the color of the '!' icon? ...

The creation of a Firebase user account with the specified email and password

I'm currently facing an issue while creating a new user with email and password using firebase authentication. The problem arises when I try to access the displayName from the returned async call before the updateProfile function, as it returns a null ...

Angular Pipe displays values properly, but ngFor fails to render them

I am using a pipe to filter my ngFor loop with exact matches that are passed through by clicking on the filter argument. Below is the code for my pipe: transform(values: any[], criteria: string, group): any[] { if (!values) { ...

Ways to display success message following JavaScript validation

I've been working on creating a form that displays a success message after JavaScript validation checks are successful. To show the success message, I'm utilizing Bootstrap alert. I split my code into two files - one for common validation functio ...

Implement a loading spinner to display each time a computed method is invoked in a Vue.js

Whenever a checkbox is checked, my filtering method gets triggered. I am trying to implement a loader that displays while the filter process is ongoing and then shows the results. However, I have encountered an issue where the loader remains visible at all ...

Avoiding memory leaks in Reactjs when canceling a subscription in an async promise

My React component features an async request that dispatches an action to the Redux store from within the useEffect hook: const fetchData = async () => { setIsLoading(true); try { await dispatch(dataActions.fetchData(use ...

I am getting a HTTP 405 error indicating that the method is not allowed, and it appears to

In my Javascript program, I requested this URL using the library epson-2.6.0.js, which is the Epson SDK for JavaScript specifically designed for thermal printers. My target device is a TM U220 connected via ethernet. GET XHR http://192.168.199.15:8008/soc ...

Stop accidental form submissions on iOS devices by disabling the return button

In my Ionic 3 application running on iOS, I encountered a bug that allows users to submit a form even when the submit button is disabled. Despite trying different solutions from this source, I have not been successful in resolving it. To prevent accidenta ...