i18next ICU Format - Format dates within the message file - internationalization

I would like to format a date by specifying the format within the message file.
I'm struggling to find any examples for doing this in the documentation. I can use short/medium/long but I would like to use more specific formats.
I've found some examples elsewhere formatting dates like so:
{
"postedOn": "Posted on {{ date, MM/DD/YYYY }}"
}
As I'm using ICU format I've tried using:
{
"postedOn": "Posted on { date, MM/DD/YYYY }"
}
but it just prints out Posted on { date, MM/DD/YYYY } without replacing the values.
What is the correct way of specifying the date format with ICU format?

Related

How to convert yyyy-mm-ddThh:mm:ss [+-] hh:mm to timestamp yyyy-mm-dd hh:mm:ss in Datastge?

How to convert yyyy-mm-ddThh:mm:ss [+-] hh:mm to timestamp yyyy-mm-dd hh:mm:ss in Datastge?
Eg:
From
2021-01-26T01:07:00-05:00
To
2021-01-26 01:07:00
Depending on the original data type you could use string functions
and StringToTimestamp
Otherwise you could check out Date and Time functions as well.
If the data type is string, convert the "T" to a space " " using Convert() function.
Use Left() function to get rid of the "+/- hh:mm".
If the data type is timestamp, do nothing until you need to display it; the internal representation of a timestamp does not have a "T" in it. If you're writing it to a text file, for example, use TimestampToString() function to specify your desired format, although the default format may well suit your need.

Convert String to Date Object Ruby

I'm trying to comvert a string in my logs to a date object.
My string is 2018-09-18 11:42:50,286000201 which is the format YYYY-MM-DD hh:mm:ss,nnnnnnnnn
I'm trying to convert in to an object using the time library in ruby. The function I am using is Time.strptime('2018-09-18 11:42:50,286000201, '%Y-%m-%d %H:%M:%S,%9N')
Ruby is giving me an invalid striptime format. Any help would be appreciated. Cheers.
remove the 9, %N expects 9 digits bt default
Time.strptime('2018-09-18 11:42:50,286000201, '%Y-%m-%d %H:%M:%S,%N')
doc: http://ruby-doc.org/stdlib-2.1.1/libdoc/time/rdoc/Time.html#method-c-strptime

Validate Date FORMAT (not date string) using MomentJS?

I've seen that you can use an ".isValid()" function to check that a given string is in a date format:
moment('2007-05-05', 'YYYY-MM-DD', true).isValid()
But is there a way to confirm that the format is correct? For example:
'YYYY-MM-DD' should return true, but
'YYYY-MM-DDsadsadl' should return false since the characters at the end of the string aren't valid DateTime chars.
We're working on a tool that allows a user to input an existing date format, and then a second input to enter the desired format, but we need validation to ensure the string can properly parse and convert, but they aren't entering a specific date.
The application must accept any and all possible date formats.
Use the following function to validate your format.
validFormat = function(inputFormat){
var validation = moment(moment('2017-06-17').format(inputFormat), inputFormat).inspect();
if(validation.indexOf('invalid') < 0)
return true;
else
return false;
}
Do spend some time to understand this. This simply does a reverse verification using inspect(). The date 2017-06-17 can be replaced by any valid date.
This Moment Js Docs will help you identify the valid formats.
Just make a call to this function as
validFormat('YYYY MM DD')
const getIsValid = inputFormat => moment(moment().format(inputFormat), inputFormat).isValid()
Explanation:
moment().format(inputFormat) - Create a date string from the current time from that format
This is then wrapped with moment() to make that string a moment date object, defining the format to parse it with. Finally we call the isValid() property on that moment date object. This ensures we are able to both create and parse a moment with our custom format.

Correct strptime format for Input Type Time on Rails 4

Want to use the
<input name=attendance[something] type="time">
For time input. However cant make it seem to match with a Datetime object; for manipulation before insertion to ActiveRecord
myTimeIn = Time.strptime(params[attendance][something],"%H:%M")
keeps getting
invalid strptime format - `%H:%M'
What is the correct format for a input type=time field?
Looks like the value of params[attendance][something] may be blank or not of the correct format. You could do something like below to avoid the error:
t = params[attendance][something]
myTimeIn = Time.strptime(t,"%H:%M") if t =~ /\d{1,2}:\d{2}/
As per this HTML example, the value produced by <input/> of type time is HH:MM

Invalid date (ArgumentError) when trying to convert to epoch time

I have a DateTime string in the format 24/May/2015:06:51:33
How can I convert it to epoch time?
I tried converting it using the method mentionedin this stackoverflow question but it seems that DateTime format is wrong. Then I tried converting my Date to another format using
DateTime.parse("24/May/2015:06:51:33").strftime("%Y-%m-%dT%H:%M:S%%z")
but that doesn't seem to work as well. Any help on how to do this? Note that I don't have my date variable in the date format. So I have to convert it from a string.
UPDATE
By doesn't seem to work I mean that the following error is thrown:
/home/keshav/Desktop/a.rb:6:in `parse': invalid date (ArgumentError)
from /home/keshav/Desktop/a.rb:6:in `<main>'
You can convert your DateTime object to an epoch timestamp like so:
datetime = DateTime.strptime("24/May/2015:06:51:33", "%d/%b/%Y:%H:%M:%S")
epoch = datetime.to_time.to_i
# => 1432450293
Hope it helps!

Resources