Parsing of ISO 8601 time intervals in Javascript [closed] - javascript

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I am building a front end component to allow users to choose a date\time range and optionally use time periods as per the ISO 8601 specification.
The component will need to bind to any existing values already set by the user, and so I am looking at how to parse out the time interval period piece for a string such as:
"2007-03-01T13:00Z/P1Y2M10DT2H30M"
I am unsure how to extract the numerical parts of the time interval piece so I can get some sort of object\array, keyed by the letters perhaps so I can easily determine number of years (Y), months (M), etc.
I could have a go at my own regex, but I suspect someone out there has already done this.
I'm wanting to give users a series of number inputs and just set these for any existing period values the user has set previously.
Can anyone suggest any approaches here?
I hope this makes sense!
Thanks

Try this:
var dateStr = '2007-03-01T13:00Z/P1Y2M10DT2H30M';
var date = new Date(Date.parse(dateStr.split('/')[0]));

Related

How to recursively calculate the diff between two objects in a way that can be applied to generate either object from the other? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 months ago.
This post was edited and submitted for review 8 months ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
I start with two complex objects, a and b, which can each contain anything, including other serializable objects or arrays. I want to get the diff of a and b in a way that I can 'apply' that patch to a to get b, or 'apply it in reverse' to b to get a. In other words, I want to be able to make a round trip, no matter how complex either object.
The reason I need this is that I want to be able to return to the various states of a record in a database over time. Every time the record changes, I want to store a patch, and I want to be able to play through the patches forward or backward to get to any previous state of that record.
Assuming I need to write this myself, I'm curious if there's an accepted standard for diff patches so that the tool I'd create might adhere to some sort of standards.
Any help would be greatly appreciated.

How to store javascript code in database? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I created a webshop for an online game where the users can buy in-game stuff. I have some special items which will be only availabe for a short period of time and I want to print out how much time left to buy it.
I wrote a JS code to countdown for a date, and now I want to store it in the database. Which is the best way to do it? Just a varchart with extremely long length? Or is it a more elegant way to deal with this?
You can use Function.prototype.toString method to convert a function into a string and then later use eval to execute the function.
You should use text type rather than varchar as it will likely be longer than maximum varchar length.
However, I would strongly discourage you to do this. A better approach would be to store something like a expiration date timestamp and calculate the availability based on that value.

List of Timezones in JSON format [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I'm looking for a list of time zones that corresponds to major cities. Like what java.util.TimeZone can provide.
I mean, I want to resolve the America/Los_Angeles identifier to UTC-8:00 in javascript.
Is there already an existing JSON file or format that has this feature?
I came across to this which is close to what I'm looking.
UPDATE
Solution: Detect the ID of the current user timezone using moment.js (Did not answer my question directly but solved my problem)
I think, this will be benefit for you
http://momentjs.com/timezone/

Generating random id using current date [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm doing a bank oriented project. I have to generate Account Number using current date.
Example:
account no-20150409001.
'2015'-Year,
'04'-Month,
'09'-Date,
'001'-represents the number of the new member opening the account on that particular date
This number should change in every branch to avoid same account number.
How to do so?
and this is my code
http://jsfiddle.net/Jegannath/z9na41o5/#&togetherjs=ynHxlyDeO1
If this is really a bank related project, do not rely on client side JavaScript for something as critical as the account number generation.
Is there a reason for the "random" number requirement? If not, stick with a sequence, it is a lot easier to ensure uniqueness.
On the server side, using a branch prefix as suggested by #kuldeep.kamboj should cover collision.
You can use something like yyyyMMddBBnnnn where yyyy = year, MM = month, dd = day, BB = branch number, and nnnn as a sequence that resets per day.
Not sure,this is correct advise,
Go with branch code prefix and timestamp in suffix, this might be developer friend also, because in future after 30 year easily you can tell his account created date with the help of timestamp.
As well timestamps is kind of random number.
advisable is server side code.

Javascript Calendar with Drag select for multiple days [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
Anyone know of a Javascript Calendar that supports drag selection for multiple days? Need to be able to do it over months as well, not just restricted to one month.
Thanks a lot in advance, the ones here are no good for my problem:
http://www.javascript-examples.com/javascript-calendars/
a jquery datepicker
http://www.filamentgroup.com/examples/datepicker/
which, although doesn't support drag, gives you the ability to get a date range for more than one month
or -even better- you can use the DatePicker component from jQuery UI
http://ui.jquery.com/repository/latest/demos/functional/#ui.datepicker
(search for Date ranges)
This is de Best javascript Calendar i've found.
http://www.dynarch.com/projects/calendar/

Categories