React-Moment- Parsing ISO 8601 Time Left Into Readable Format - reactjs

I'm trying to take the 'timeLeft field from the eBay API and turn it into something that looks normal, like 3 Hours, 10 Minute and 5 seconds left.
The data looks something like this: P3DT6H28M15S
I'm trying to use the React Moment module but can't figure out exactly how to do this.
This is my latest test:
<Moment format="h:mm:ss">
{card.sellingStatus && card.sellingStatus[0].timeLeft}
</Moment>
But this is returning 'invalid date'.
I also try the following code just to see what HTML output looks like, but i'm trying a different output field
<Moment>{card.listingInfo && card.listingInfo[0].endTime}</Moment>
note that endTime looks like this
2019-11-09T19:45:32.000Z
but the above code is generating the same exact value for each item
Tue Jan 01 2019 00:00:00 GMT-0500
even though all of the endTime fields are different
Any ideas as to what I might be doing wrong here?

So i mostly accomplished what I needed by using the react-timeago npm module.
<TimeAgo
date={new Date(
card.listingInfo && card.listingInfo[0].startTime
).toLocaleDateString()}
/>

Related

AngularJS convert string date and integer time

I have a string with a full date like this: "2016/03/05 13:47:18 +0000".
I want covert it to "2016-03-05" or "05-March-2016" on Angular scope. I also have integer time duration = 421471 which I want to convert to a time format like "23:45" or "1 hour , 50 minute".
{{sound.created_at | date}}
{{sound.duration}}
How can I do that?
To solve your issue please use momentjs as very famous lib to deal everything about date in js.
To make it work well with Angularjs/4, please have a look here.

Unable to get date xAxis working with unix timestamp

I am having some trouble understanding the Anychart axis documentation.
Using this example https://jsfiddle.net/gvb29tc2/2/ i have some data points i want to plot using the unix date stamp for x-axis.
[
1497786600, // <- ID
'Sun Jun 18 2017 19:53:35 GMT+0800 (SGT)', // <- date
1497786815630, // <- unix date
...
]
I select it using x: new Date([2]), but i cant get it to display. Just outputs a single vertical line. Also, i wanted the major tick on 5min and minor on 2min. Can't get that working either.
Since all i am trying is a simple line chart, i think i'm missing something stupid. Can someone explain where i'm going wrong please ?
You shouldn't use any functions in mapping settings.
Right way is
x:[2]
After that you can work with mapped value as timestamp
https://jsfiddle.net/gvb29tc2/4/

Angular ng-repeat filter/search by formatted date

I have a list of date objects which I want to display like this:
<div ng-repeat="myDate in myDates | filter:dateFilter">{{myDate | date:'dd. MMMM yyyy'}}</div>
The dateFilter is bound to an input field.
Now the Problem is, when I type in "October" for example, no date is found because angular seems to be looking only into the date object which looks like this:
Thu Oct 27 2009 00:00:00 GMT+0200 (Mitteleuropäische Sommerzeit)
Is it possible to also search in the formatted date string "27. October 2009"?
You should implement your own filter function, which is quite easy to do: https://docs.angularjs.org/tutorial/step_09
That way you'll be able to implement any custom filtering logic you'd like to have.

Regular Expression date time using MVC Data Annotations

I'm mixing MVC Data Annotations and AngularJs validations ng-pattern.
What I've done so far is this thing:
[RegularExpression("/^[0-9]{4}-[0-9]{2}-[0-9]{2} 20|21|22|23|([0-1][0-9]):[0-5][0-9]:[0-5][0-9]$/", ErrorMessage = "Date format: yyyy-mm-dd hh:mm:ss")]
As you can see, I try to format date: yyyy-mm-dd hh:mm:ss.
I want to make it 24 hours time.
My problem is that form is getting valid when I type:
2015-21 , 2015-22 // 2015-20 is not valid, cannot understand why
2015-12-20 21 // I want user to enter minutes and seconds, because it also has datetimepicker, which is more useful and it sets format as I want
So, why my regular expression is not working as I expect?
Your regex does not work as expected because you did not use a ^ anchor (although I guess this expression is anchored, but still it is better to play it safe) and you did not enclose the alternatives into a group, and thus 21, 22, 23 are valid values.
Here is a fixed expression:
^[0-9]{4}-[0-9]{2}-[0-9]{2} (?:20|21|22|23|(?:[0-1][0-9])):[0-5][0-9]:[0-5][0-9]$
^^^ ^^
See demo
change your regex instead to be like this
^[0-9]{4}-[0-9]{2}-[0-9]{2} ((20|21|22|23)|([0-1][0-9])):[0-5][0-9]:[0-5][0-9]$
check this Demo
I only changed 20|21|22|23|([0-1][0-9]) in your regex to ((20|21|22|23)|([0-1][0-9]))

CakePHP: CakeTime i18nFormat for date and time

I'm using the CakeTime class for my localization of dates & times.
For dates it works like I want it to:
$timestring = $this->Time->format('Y-m-d H:i:s', time());
echo 'DateTime: '.$this->Time->i18nFormat($timestring);
// Result => DateTime: 11/08/2013
I want it to also display the time.
For example in the US they use AM/PM and in other places they use the 24 hour notation.
I've looked but can't seem to find a way to do this.
Any idea's?
Edit*
To be clear, the localization works perfectly for the dates(have the LC_TIME files), but the i18nFormat function only returns the date, and from what i saw, passing a format will use that format, not the localized one, example MM/DD/YYYY vs DD.MM.YYYY in a different locale
*Edit2:
The solution vicocamacho gave in the comments is the correct one
So to get the Date + Time in the localized form:
$this->Time->i18nFormat(time(), '%x %X') does the trick!
You can use the TimeHelper::i18nFormat method. You also can check this repo to find common date/time translations https://github.com/cakephp/localized be sure to store them in the APP/locale/<locale>/LC_TIMEdirectory

Resources