Azure policy - liquid template - convert milliseconds to formatted date - azure-management-api

How can I convert milliseconds date to formatted date.
I tried the following :
<set-body template="liquid">
{
"date" : "{{ "1610924400000" | Date: "MM/dd/yyyy" }}"
}
</set-body>
But it prints :
{"date": "1610924400000"}
Is it possible ? How can i do this pls ?

You should use "%m/%d/%Y" instead of "MM/dd/yyyy".
Liquid templates use the same format as Python's strftime. You can find the documentation about it here.

Related

How can I set execution date in HttpSensor (Airflow)?

I try to pass execution date to httpsensor operator.
is_api_available = HttpSensor(
task_id='is_api_available',
http_conn_id='data_available',
endpoint='api/3/action/date= {{I want to set date in here}}'
)
I can get execution date parameter in python operator like this:
print("my start date : ",kwargs['execution_date'] )
it works but how can I get it in other operators?
thanks in advance
You can use Jinja template with the variable {{ ds }}, it format the datetime as YYYY-MM-DD
for more macros you can see at https://airflow.apache.org/docs/apache-airflow/stable/templates-ref.html
is_api_available = HttpSensor(
task_id='is_api_available',
http_conn_id='data_available',
endpoint='api/3/action/date={{ ds }}')
api/3/action/date=2022-06-25

Is it possible to change the date format in Allure Reports?

My Allure reports display the date in a MM/dd/yyyy format.
I would like to change the format to be dd/MM/yyyy.
Is it possible to set a different date format in allure reports?
Yep, you can do this in the settingsFactory.js, which can be found at:
allure-generator\src\main\javascript\utils\settingsFactory.js
Here is an example of setting this to the en (English) and au (Australia) locale.
import LocalStorageModel from '../data/localstorage/LocalStorageModel';
const globalSettingsDefaults = {
language: 'en-AU',
sidebarCollapsed: false,
sideBySidePosition: [50, 50]
}

Datetime object into readable format Jinja

I am trying to format a datetime value into a human readable format
For example:
value = 2019-12-17T08:12:58.472+00:00
expected result = 17/12/2019.
The code has to be in Jinja. Been trying to do the following, but getting an error message:
{{ 2019-12-17T08:12:58.472+00:00 | from.strftime('%Y-%m-%d') }}
Can anybody help?
This works for me to pull out a date in your requested "human readable" format %d/%m/%Y:
>>> from jinja2 import Template
>>> from datetime import datetime
>>> t = Template("Hello, {{ your_jinja_date_var.strftime('%d/%m/%Y') }}!")
>>> t.render(your_jinja_date_var=datetime.now())
'Hello, 17/12/2019!'
Here are the API docs where you can find other incredible features of jinja.
Your strftime function from your question above does imply standard ISO date conventions %Y-%m-%d. If you'd like that date format:
>>> t = Template("Hello, {{ your_jinja_date_var.strftime('%Y-%m-%d') }}!")
>>> t.render(your_jinja_date_var=datetime.now())
'Hello, 2019-12-17!'
And to top it off, here's a nice tutorial article on the topic which I found useful, from the Real Python platform.
<p>Last seen: {{ user.last_seen.strftime('%d-%m-%Y, %T') }}</p>
This worked for me for Date and Time both.

TWIG date function displaying incorrect datetime

I am displaying a list of datetimes from my database and using twig to format. This was working until today.
If I dump this: {{ dump(time.clockedIn) }}
I get this:
DateTime {#612 ▼
+"date": "2017-02-03 17:54:20.000000"
+"timezone_type": 3
+"timezone": "America/New_York"
}
When I dump this: {{ dump(time.clockedIn|date("m/d/Y h:m:s a")) }}
I get this: "02/03/2017 05:02:20 pm"
I cannot find out why this changed. Any ideas?
Try this instead:
{{ dump(time.clockedIn|date("m/d/Y g:i:s a")) }
As per the Twig date documentation, you should be using g:i:s a.
Note that this documentation references PHP's date function, where you'll see the proper format characters that you can use.

How to format time in yaml in symfony

I'm using symfony 1.4 doctrine. I have an output in my database/browser that looks something like this:
Start time: 12:00:00 End time: 05:00:00
Now I want to change this format like this:
Start time: 12:00 pm End time: 5:00 pm
I tried to convert this in yaml in the backend application like this:
apps/backend/modules/reservation/config/generator.yaml
//some yaml code
fields:
startime: { date_format: h:i A }
endtime: { date_format: h:i A }
I use this format but it did'nt work, probably I set in the schema.yml their data types in "time" format:
reservation/config/doctrine/schema.yml
//some yaml code
columns:
startime: { type: time, notnull: true }
endtime: { type: time, notnull: true }
I set my startime and endtime to time format just to get the time value only for my project. I did'nt set it to date type because it will affect my front end application. For example if I input 5:00 the display will be 12:00 am, its because I use date type.
To turn this 5:00:00 to 5:00 pm/am in display, I set it into time data type and I use this syntax like this which I used in showSuccess and Indexsuccess template.
<?php echo date('g:i A', strtotime($reservation_application->getStartime()));
this code will format 00:00:00 into 12:00 am or something. but it doesnt change (00:00:00) in the data base. ONLY in display.
Is there a way to format this 00:00:00 into 12 hr format in the yaml file? Many thanks
When you save a time, it's always stored without any culture information. (And as soon as you're going to create a multilingual website, you'll be glad of that!).
That said, it's best to use the DateHelper when formatting dates in the view. This has a format_date function. When you're using this function, don't forget to set the default_culture in the settings.yml (or set the correct culture in the sfUser).
For example format_date($date, 't'); prints the current time, in the users culture.
For an overview of which patterns you can use, see this page.

Resources