Time Flies Zone - Date Error

The code snippet provided demonstrates that calling

moment.tz('30 3 14:59', 'w d HH:mm', 'America/Los_Angeles');
successfully parses the date and time. However, changing the time to anything between 15:00 and 23:59 results in an Invalid date error.

var validTime = moment.tz('30 3 14:59', 'w d HH:mm', 'America/Los_Angeles');
console.log(validTime.format()); // 2018-07-25T14:59:00-07:00


var invalidTime = moment.tz('30 3 15:00', 'w d HH:mm', 'America/Los_Angeles');
console.log(invalidTime.format()); // Invalid date

https://jsfiddle.net/084e2k91/26/

What could be causing this issue?

Answer №1

It's intriguing to note that I'm facing the same issue as well. It appears to be a bug in the moment.js library, where date conversion from different time zones is not working correctly. However, using do instead seems to resolve the issue temporarily. Perhaps we should consider using do until we can report and address this problem on GitHub.

Furthermore, it's worth mentioning that do is equivalent to d, which is specified in the documentation. Both options return the same day value, but one as a number and the other as a string.

After conducting more tests, I've noticed that the issue starts occurring in IST after 18:30. The exact cause remains unclear to me, but it could potentially be linked to the application of timezone adjustments to real-time values, leading to errors. For instance, while in IST, 00:00 - 5:30 corresponds to the problematic timeframe when the error occurs.

To address this, the updated code snippet should look like this:

var myTime1 = moment.tz('30 3 14:59', 'w d HH:mm', 'America/Los_Angeles');
console.log(myTime1.format());

var myTime = moment.tz('30 3rd 14:59', 'w do HH:mm', 'America/Los_Angeles');
console.log(myTime.format());

// In IST, the issue arises from 18:30 onwards
var myTime1 = moment.tz('30 3 19:30', 'w d HH:mm', 'America/Los_Angeles');
console.log(myTime1.format());

var myTime1 = moment.tz('30 3rd 19:30', 'w do HH:mm', 'America/Los_Angeles');
console.log(myTime1.format());
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.21/moment-timezone-with-data-2012-2022.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

Issue when activating Materialize Bootstrap

I'm facing an issue with my code. I have implemented a feature where a modal should be triggered after a user successfully adds a new user. However, I am using Materialize and the modal is not being triggered. Below is a snippet of my code: <div i ...

I specialize in optimizing blog content by omitting the final line within a React framework

https://i.stack.imgur.com/WKOXT.png Currently, I have 4 lines and the 5th line in the current input field. This is my React code snippet: import { FC, useEffect, useState } from "react"; interface BlogWitterProps {} const BlogWitter: FC<B ...

Incorporate and interpret a custom JSON object within my Shopify Liquid theme

In an attempt to integrate custom data into my Shopify liquid theme, I stored a JSON file in the assets folder. My goal is to retrieve and parse this JSON object within a jQuery method from a JavaScript file also located in the assets folder. Despite try ...

Guide to sending a HTTP POST request with parameters in typescript

I need assistance sending a POST request using parameters in the following format: http://127.0.0.1:9000/api?command={"command":"value","params":{"key":"value","key":"value","key":"value","key":value,}} I attempted to do this but encountered an issue: l ...

"Material-Table does not have the ability to insert a new row

Just started learning JS and React. I'm attempting to integrate Material-table with an add row button, but encountering issues where the added row is not reflecting. Every time I refresh the page, the rows are reset. I suspect there's a problem w ...

In TypeScript, there is a curious phenomenon where private properties seem to be mimicking the

Here is an example of an issue I encountered while working with private properties in TypeScript. I expected that only the public properties would be visible in my object output, similar to normal encapsulation. My aim here is to include the property wit ...

Utilizing AJAX to input information into the database with Magento

I'm just starting to learn about ajax and I may be approaching this problem incorrectly. Essentially, I have a javascript variable that needs to be added to the database. Here is what I have so far... onInit: function() { window.fcWidget.on(&apos ...

Logs from console.log() statements in Firebase functions are missing

I've encountered an issue with the function below where the console.log() statements do not appear in the Firebase logs. When I remove everything after the db.collection call, the initial console.log() statements are visible. However, once I reintrodu ...

A guide on harnessing the power of the fetch API to retrieve data from an external

In the process of developing a fetchBill function, I have assigned the URL https://randomapi.com/api/006b08a801d82d0c9824dcfdfdfa3b3 to a variable named api. This function utilizes the browser's fetch function to send an HTTP request to the specified ...

What are some strategies for retrying an Apollo Client query after a failure?

When working with Next.js server-side rendering (SSR), I often encounter a query failure on the first try due to the backend not being fully ready. In such cases, I would like to retry the fetch using ApolloClient. const PREVIEW = { query: MY_PREVIEW_ ...

Issue with VueUse useStorage function failing to update stored object properties

Having difficulty updating a property in an object stored in localStorage using the useStorage function. Inside the App.vue file: routeStore.query = { tab: 'products', subTab: 1, search: '', article: '', } console.log ...

How can I best fill the HTML using React?

After attempting to follow various React tutorials, I utilized an API to fetch my data. Unfortunately, the method I used doesn't seem to be very efficient and the code examples I found didn't work for me. I am feeling quite lost on how to proper ...

Error: When attempting to submit to MondoDB, a TypeError occurred stating that property '_id' cannot be created on the number '1'

After retrieving 25 new comments in JSON format from a subreddit, my code converts it to a string, removes special characters, and generates a dictionary to track word frequency. The challenge lies in deciding whether to treat each word as a separate entry ...

Establishing a minimum date based on the date selected in the earlier datepicker

My webpage features two date pickers, one for startdate and the other for enddate. The current setup requires that the second datepicker remains inactive until a change is made to the first one. The datepicker for enddate is initially set with the startin ...

Using a custom jQuery function within an Angular component class

I have a custom query function that I wrote in a JavaScript file located under the source folder (/src/assets/inlineedit.js) of my Angular application. Here is the content of the file: $.fn.inlineEdit = function(replaceWith, connectWith) { $(this).ho ...

Use Selenium to close the Flipkart tab, open a pop-up window, and navigate back to the

WebDriver driver = new FirefoxDriver(); driver.get("https://www.flipkart.com"); driver.manage().window().maximize(); String parentWindowHandler = driver.getWindowHandle(); // Saving the parent window String subWindowHandler = null; Set<String> handle ...

Developing a simple component

Is there a variance in performance when working with dumb components in React? There are two methods to achieve the same outcome. function Comp(props) { ... } const Comp = props => { ... } ...

Displaying React components for a brief duration of time

I have an existing React component where I need to display another component for a specific duration. Upon mounting or data loading of the parent component, the child component should become visible after 1-2 seconds and then disappear after a few more sec ...

Refreshing local storage memory on render with a custom Next.js hook

I recently developed a custom Next.js hook named useLocalStorage to store data in local storage. Everything is working fine, except for one issue - the local storage memory gets refreshed with every render. Is there a way to prevent this from happening? ...

Is there a way to send a non-JSON value to an angular.js http.post function?

Struggling to send two parameters using the HTTP POST method in Angular.js. Here is the code I have implemented: Controller var installerApp = angular.module('installerApp', []); installerApp.controller('InstallerCntlr',function($scop ...