Program that opens a specific URL on the initial Friday of each month, but exclusively during the hours of 8am to 10

Hey there! I'm currently working on a Virtual Tour Software project using Javascript, and I have a specific requirement. I need to create an action that opens a URL (containing a photo panorama) only during a particular time frame - specifically, the first Friday of every month between 8am and 10am. Any suggestions on how to achieve this? Thanks a lot, Michal

Here's what I have come up with so far:

var startDate = new Date('Jun 5, 2020 8:00:00').getTime();
var endDate = new Date('Jun 5, 2020 10:00:00').getTime();

setInterval(function() {
var now = new Date().getTime();
var isVisible = now > startDate && now < endDate;
var hotspot = this.getPanoramaOverlayByName(this.getMediaByName('Panorama'), 'Hotspot');
if(hotspot && hotspot.get('enabled') != isVisible)
hotspot.set('enabled', isVisible);
}.bind(this), 1000);`

The issue I am facing is that I have to manually update the "startDate" and "endDate" variables each time. I am looking for a way to automate this process so that it is visible on every First Friday of the month.

Answer №1

In order to identify the date that falls on a Friday and is within the first 7 days of any given month and year, you can utilize the getday() and getdate() functions available in JavaScript. Here's an example of how you can incorporate this into your code:

var d = new Date();
var startDate = d.getDate(); // retrieves the date
var isFriday = d.getDay();   // retrieves the day index
var n = d.getHours();         // add this line to retrieve hours
if((startDate <= 7 && isFriday === 5) && (n >= 8 && n <= 10)) 
{
   setInterval(function() {
     var hotspot = this.getPanoramaOverlayByName(this.getMediaByName('Panorama'), 'Hotspot');
     if(hotspot && hotspot.get('enabled') !== true)
         hotspot.set('enabled', true);
   }.bind(this), 1000);
}

Give it a try!

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 NGRX state in Angular is not being properly saved by the local storage

Currently, I am utilizing NGRX for state management within my Angular application. While NGRX is functioning correctly, I have encountered an issue with using local storage to persist the NGRX state. Upon refreshing the browser, the NGRX data reverts back ...

Angular q.all: comparing immediate and delayed responses

Seeking advice on methodology: I currently utilize $q.all to handle multiple promises in a single return, processing all results as one request. For instance: $q.all([promise1(),promise2(),promise3(),promise(4),promise5()])..then(function(response){ ...} ...

"Troubleshooting Image Loading Issues in Next.js: A Guide to Reloading Unresponsive

https://i.sstatic.net/FLdrA.jpgHello, I am facing an issue with rendering 300 images from IPFS data. Occasionally, around 3-4 of the images fail to load and result in a 404 error. Even after refreshing the page, these unloaded images remain inaccessible. I ...

JS Issues with generating accurate dates in JS/JS Date perplexities

Creating a custom datepicker has been a challenging task for me. I'm facing difficulties in understanding how JS Date works and need some assistance to bridge this knowledge gap. The issue arises when I attempt to generate dates using a for loop, resu ...

What could be the reason for Safari generating larger videos than Chrome when utilizing the MediaDevices.getUserMedia() API?

Embarking on a small experiment to gauge the size of captured videos using the MediaDevices.getUserMedia() API. My Safari implementation yielded videos 5-10 times larger than those in Chrome. Here's the code snippet: index.html: <html lang=" ...

Learn how to use a function in Google Maps to calculate and display distances

I have a script obtained from this link here and I am trying to create a function that returns the distance. This is my current script: var calcRoute = function(origin, destination) { var dist; var directionsDisplay; var directionsService = ne ...

Having trouble loading the .php file with my Ajax request

Attempting to retrieve data from the postcode.php file and display it in a #postcodeList div, but encountering issues as nothing happens. Upon inspecting the postcode.php file, it seems to be outputting all the correct information. var loadicecream = do ...

What are the best practices for managing DOM manipulation with TypeScript instead of plain JavaScript?

I'm a beginner in Typescript and I want to incorporate the following JavaScript functionality into a Typescript file. http://jsfiddle.net/SgyEW/10/ $('.toggler').live('click', function() { var idname = ...

Tips for avoiding variable overwriting while utilizing it in a for loop to color objects

I am looking to enhance the efficiency of my function in creating HTML objects using native JS script. The current function paints text, but I want it to optimize. When running the function, I expect different iterations of text to be written in HTML thro ...

The slow rendering of Threejs is causing the browser to become unresponsive

Utilizing ThreeJS, I successfully created a captivating 3D scene with ten thousand particles arranged in a specific layout. Rendering these particles in the 3D world was seamless thanks to ThreeJS. However, I encountered an issue where the browser would di ...

Creating Blurry Text Effects in HTML (Step-by-Step Tutorial)

I have a basic text that is centered inside the canvas. However, it appears blurry and unattractive. Can anyone suggest how to enhance its appearance? // Populate the signature canvas with data var canvas = document.getElementById("signatureCanvas"); v ...

Placing a cookie prior to the page being refreshed or closed

Once again, I find myself turning to the SO community for assistance. I'm currently in the process of modifying a Joomla "quiz" component to meet my specific needs. My current goal is to alter the "refresh" behavior of the component. Essentially, eac ...

Sorting an array using the Insertion sort algorithm in JavaScript / An undefined function

Currently, I am in the process of developing a JavaScript file that includes an insertion sort function, a method to validate a sorted array and return true or false, and a reverse insertion sort function that operates from the end of the array index towar ...

What are the steps to start a project on a personal computer?

Utilized on   - Windows 7, 64-bit I am interested in exploring how the project functions with github.com - project. Query: How can I get the project to do this? Steps Taken:   1. Saved the project to the directory. c:\test\visualStudio ...

making a request using AJAX to retrieve an audio blob from an asynchronous API

I'm currently working with a legacy system and I am attempting to invoke an HTTP handler where I have implemented some logic to fetch an audio blob from an Azure service. However, I am facing difficulty in retrieving the content back to the client for ...

Craft a FormType showcase using the dynamic duo of Ajax and Jquery

If you'd like to check out the code snippet for reference, please visit: This view serves as the canvas where innovation blends with execution. As I embark on this journey towards dynamic form creation, every step counts. Thank you for being part of ...

Choose an image and save the selection information for the following page (Tarot card)

I'm in the process of creating a website that showcases multiple tarot cards. The goal is for users to select the cards they're interested in and have their chosen card displayed on the next page. I've implemented some code for selecting the ...

"Enhance the visualization of your data with Apexcharts by accurately coloring the columns

When attempting to color the graphic using an array, only one color is applied to all three columns, despite declaring a different color for each column. options: { chart: { type: 'bar', id: 'chart', }, colors: ['#3 ...

What scenarios call for utilizing "dangerouslySetInnerHTML" in my React code?

I am struggling to grasp the concept of when and why to use the term "dangerous," especially since many programmers incorporate it into their codes. I require clarification on the appropriate usage and still have difficulty understanding, as my exposure ha ...

Dynamic website content updating using AJAX and PHP with seamless table refreshing

I'm really struggling to find a solution for this issue and it's frustrating that I can't even find one example! So, here's the situation: I have a monitoring system (PHP / MySQL) that is refreshed using Javascript. The problem is that ...