Deprecation warning for moment timezone - angularjs

var viewValue = "GMT";
return moment(moment().tz(viewValue).format('LLL'));
Above return throw below error, can you please let me know how to fix below issue:
Deprecation warning: value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are discouraged and will be removed in an upcoming major release. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info.

The statement moment().tz('GMT').format('LLL') results in a string like this:
May 3, 2018 7:29 AM
The above string is not in a valid ISO format. That's why you receive this warning because if you pass this to the moment constructor, you're creating a MomentJS object again.
To mitigate, you need to specify the format of the string to parse it correctly:
moment(moment().tz('GMT').format('LLL'), 'MMM DD, YYYY HH:mm A');

As warning clearly shows that returned value (Date format) from your code is not supported by momentjs. This format is deprecated and will be removed in future.
So solution for this is to choose any of the format from below link:
Check Supported ISO 8601 strings & The RFC 2822 date time format here http://momentjs.com/docs/#/parsing/string/

Related

momentjs format time in seperate hours an minutes

I use momentjs inside angular js and I acount the duration in seconds and I can format it in HH:mm format as 03:35 but I cannot find in documentaion and google to how show it in format 3h 35m could anybody point me to right documentation???
This should get what you're after:
moment().format("H[h] mm[m]");
Take a look at Format from the momement.js docs. The [] is used to escape characters in format strings.

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]))

Adding new date formats to ExtJS

Ext.Date contains formats a and A for am/pm or AM/PM, respectively.
I want to add a format, call it b, for a/p without the m. I have searched parseFunctions and formatFunctions but did not find where the old format is defined.
Can anyone shed some light on this matter?
Have a look at formatCodes in Ext.Date:
The base format-code to formatting-function hashmap used by the format
method. Formatting functions are strings (or functions which return
strings) which will return the appropriate value when evaluated in the
context of the Date object from which the format method is called. Add
to / override these mappings for custom date formatting.

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

Getting a currency format pattern from AngularJS filter

I'm interested in creating a filter that would accept an amount, ISO 4217 currency code, and fraction size, and return the amount in that format. I noticed that AngularJS has goog.i18n.currency.getGlobalCurrencyPattern in i18n/closure/currencySymbols.js, but I'm relatively new to Angular and not sure if it is possible to use it?
The currency pattern and symbols are just that. It determines how to display a number. It will not convert it from XXX to XXX. You will have to do the converting part based on the current conversion rates.
As far as using the built-in currency formatting, there are multiple ways: in the template, in the code.
In the template:
<div>{{myCurrencyValue | currency:'XXX'}}</div>
In the code:
var formatted = $filter('currency')(myCurrencyValue, 'XXX')
In both cases, 'XXX' is optional [and is symbol] and will use the default currency for current locale
Example: http://jsfiddle.net/TheSharpieOne/N7YuP/
More information can be found here: Currency Docs
UPDATE
Example with ISO 4217 codes using custom filter: http://jsfiddle.net/TheSharpieOne/N7YuP/3/
Note: ISO 4217 doesn't dictate the currency symbols, I used this for symbol reference and mapped them.

Resources