Extract data from recurring rules

I am dealing with an object that is structured like this:

const input = {
  "recurrence": {
    "rrule": [
      "RRULE:FREQ=DAILY;UNTIL=20230606T133000Z"
    ],
  }
};

My goal is to extract the value stored in FREQ and determine if it equals DAILY or YEARLY. Additionally, I need to access the value of UNTIL.

Answer №1

Here is an example of what your code could resemble:

let
   inputData = {
    "schedule": {
      "recurrenceRule": [
        "RRULE:FREQ=WEEKLY;UNTIL=20231231T235959Z"
      ],
    }
  },
  segments = inputData.schedule.recurrenceRule[0].split(';'),
  isWeekly = segments[0].split('=')[1] === 'WEEKLY',
  endDate = segments[1].split('=')[1];

console.log({
  isWeekly,
  endDate
});

Answer №2

Utilizing regular expressions to extract the values of FREQ and UNTIL from a given string.

const input = {
  "recurrence": {
    "rrule": [
      "RRULE:FREQ=WEEKLY;UNTIL=20230912T183000Z"
    ],
  }
};

const rrule = input.recurrence.rrule[0];
const freqMatch = rrule.match(/FREQ=([^;]+)/);
const untilMatch = rrule.match(/UNTIL=([^;]+)/);

if (freqMatch) {
  const freqValue = freqMatch[1];
  if (freqValue === "WEEKLY") {
    console.log("Frequency is WEEKLY");
  } else if (freqValue === "MONTHLY") {
    console.log("Frequency is MONTHLY");
  }
}

if (untilMatch) {
  const untilValue = untilMatch[1];
  console.log("UNTIL value:", untilValue);
}

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

Issue occurred in module.js:341 while attempting to include android platform to ionic using command line

For my hybrid app development using the Ionic framework, I made sure to install all required dependencies like node.js and cordova. Following their Getting started guide, I reached step 3 which instructs running this command within the app directory: > ...

Is it possible in HTML to create an "intelligent" overflow effect where text is truncated and replaced with an ellipsis "..." followed by a link to view the full content?

I have a <div> that has a limited size, and I am looking for a way to display multiline text in it. If the text exceeds the available space, I would like to add "..." at the end along with a link to view the full content on another page. Is there a ...

Looking to create a JSON array and iterate through its elements

I am in need of creating a state for multiple elements displayed on a web page. The states are limited to 1 or -1. My approach is to generate a JSON array on the server side and then embed it into my .aspx page like this: var someArray = { 100:-1, 1001: ...

"Unable to convert object into a primitive value" error message appears on Internet Explorer

Currently working on a webpage using Angular 7. The code is functioning perfectly in Chrome, however, I am facing an Exception error while running it in IE: An issue arises: Can't convert object to primitive value (polyfills.ts) The source of the er ...

Find the total duration of all items within an array by utilizing the Moment.js library

Within an array of objects, each object contains a field named "duration" that represents a string. Here is an example of one such object: { id: 14070 project: {id: 87, name: "Test project for time tracking"} issue: {id: 10940} user: {id ...

Expanding a Node.js class to incorporate additional static class elements

I have a query where I believe that extending a class might be the solution, but I am not entirely sure. Here is the scenario... There is a class defined as follows: class Field { apiName; /** * Creates an instance of Field with the given par ...

Generate a new entity by merging two objects containing keys that are identified by dots

I have a unique input as shown below: { survey.subObject1.key1: true, survey.subObject1.key2: "OTHER", survey.subObject2.key3: "[1,2]", survey.subObject2.key4: false, survey2.subObject3.key5: false, survey2.subObject3.key6: false } I a ...

What causes the axios Library to fail in initiating a request if the API call does not begin with "https://"?

This issue has been resolved, but I still want to ask it in order to gain a better understanding of the underlying processes. So, I am using an API to retrieve data on the current weather in a specific city. The API call (as per the provider's documen ...

The function angular.isDefined(obj) will fail to work when the variable "obj" is not defined

Typically, I find myself using the slightly cluttered typeof obj !== "undefined" expression. But recently, I came across the angular.isDefined(obj) function. According to the documentation, it should return false if the object is not defined. However, in ...

ng-grid cell onclick callback

Currently, I am working with ng-grid and am attempting to define a callback function for when a cell is clicked. During this callback, it is crucial for me to identify the specific row and column of the cell that was clicked. Upon exploring various options ...

Ways to prompt the debugger to pause whenever a specific script file is called during execution in Edge/Chrome debugger

I am currently in the process of debugging a Typescript web application, which is quite new to me as I have never delved into web development before. This particular project entails multiple script files and various libraries. While running the applicatio ...

What is the best way to transfer data from a PHP array to a jQuery array?

I can't seem to grasp the concept of transferring a PHP array to a jQuery array. I am trying to achieve something similar to this: var jQueryArray = <?php $phpArray; ?>; Could someone please provide guidance on how I can accomplish this? ...

What steps do I need to take in order to set up InfluxDB with Nest

As a beginner in the world of software development, I am eager to expand my knowledge and skills. Has anyone had experience operating influxdb with nestjs? If so, I would greatly appreciate it if you could share your past experiences. Thank you for takin ...

Is there a way for me to showcase information?

I am currently facing an issue with displaying user information retrieved from my database using AngularJS. The code snippet below shows how I am trying to get the user data: angular.module('listController',[]) .controller('listCtrl' ...

JavaScript's blank identifier

One interesting feature in Golang is the use of the _ (Blank Identifier). myValue, _, _ := myFunction() This allows you to ignore the 2nd and 3rd return values of a function. Can this same concept be applied in JavaScript? function myFunction() { re ...

What methods does JUMflot use to update points or select items? Interested in adding objects to an array and redrawing them without altering the original item

My goal is to use a button to push a line into an array and have JUMflot redraw those lines without affecting the original line being pushed in. Initially, I attempted this using the following code snippet (the generator ID represents the button and optio ...

What is Angular's approach to managing the @ symbol in view paths?

I found some interesting data lake sources on AWS. I came across their package.js file, which includes the following code: '@package': { templateUrl: 'package/package.html', controller: 'PackageCtrl' } I am curious a ...

When rendering a PNG image with an alpha channel, three.js has been reported to leak pixels from the videocard

Struggling to come up with a suitable title for my question here.. I'm encountering an issue when loading PNG files from an external URL, specifically with one PNG that has a non-power-of-two alpha channel created in Gimp. When I load and use this PNG ...

Is it possible to change the Accept-Language header for rtk query endpoints?

Here is my custom baseQuery with the "Accept-Language" header set in the prepareHeaders function. import { fetchBaseQuery, retry } from '@reduxjs/toolkit/dist/query/react' import i18n from 'i18next'; export const baseQuery = ...

Extract data from THREE.js computed textures using GPUComputationRenderer

Experimenting with the GPUComputationRenderer on a customized version of this three.js example, I have been working on adjusting boid interactions using GPU shaders to handle, retrieve, and manipulate boid position and velocity data. I have reached a poin ...