How to get current date in Helm - kubernetes

I need to get the current date in Helm with the following format YY-MM-DD. I'm trying {{ now | date }} but this returns an error because the number of arguments expected by date is two, not one.

Try Format the date to YEAR-MONTH-DAY:
{{ now | date "20060102150405" }}
Source here:
or add the following annotation :
annotations:
deploymentTime: {{ now | date "2006-01-02T15:04:05" }}

Related

Hugo, how to localized .groupByDate

In my template I sort by months my post like this:
{{ range (where site.RegularPages "Type" "in" site.Params.mainSections).GroupByDate "January, 2006" -}}
<h1>{{ .Key }}</h1> // output: March, 2022
{{ range (where .Pages ".Params.unlisted" "!=" "true") }}
<div>{{ time.Format "02 January" .Date }} - {{ .Title }}</div> // output: 01 Mars - This is the title of my post
{{ end }}
{{ end }}
For every post the time.Format localized my date in my language (here in French).
But the title witch is group by month is still in English (here it's the h1). How can I format my {{ .Key }} so it can be localized in my own language and show "Mars, 2022" instead of "March, 2022" ?
How about:
{{ time.Format "02 January" .Key }}
Or is there something I am missing?
Update: You can sort by months like this:
{{ range (where site.RegularPages "Type" "in" site.Params.mainSections).GroupByDate "1 2006" -}}
Then you can split your .Key by a space and create a manual lookup for your localized month. Not very pretty, but it gets the job done.
Since hugo version 0.97 it works as expected, we don't need some ugly hack to have the text in the corresponding language.
Now you can use .GroupByDate and it will use your language settings in your config file.

How to prevent duplicate blog post dates in shopify

I have a blog with posts on a shopify website. I want to get all the publication dates of posts, and I do it like this:
{% for article in blog.articles %}
{{ article.created_at }}
{% endfor %}
And this is the output result:
2022-02-01 14:50:06
2022-01-25 05:25:33
2022-01-25 05:24:48
The result shows that there are two posts with the date 2022-01-25 and one post with the date 2022-02-01. But all these dates have different seconds and minutes.
I want to remove seconds and minutes by setting the format to date: "%B %Y":
{{ article.created_at | date: "%B %Y" }}
And in the end I get this result:
February 2022
January 2022
January 2022
Now the question is: How do I prevent duplicate dates with the same format date: "%B %Y"?
I can easily solve this problem with javascript, but I want to know if it's possible to solve this problem using only shopify features.
I will be glad to any answer. Thanks!
You can store all the dates in as string
{%- capture dates -%}
{%- for article in blog.articles -%}
{{ article.created_at | date: "%B %Y" }},
{%- endfor -%}
{%- endcapture -%}
And split and uniq the values to get only the unique ones:
{% assign unique_dates = dates | split: ',' | uniq %}
This will remove any values that are repeating.
Hope this is what you are looking for.

How can I use Liquid / Jekyll to extract the date from an image's filename?

I understand that Jekyll auto-extracts the date from a post's filename.
How to the same with an image's filename please?
Let's assume the following format of the image filenames:
2020-12-10_A_the_rest_of_the_filename_of_the_image.jpg
2020-12-10_B_the_rest_of_the_filename_of_the_image.jpg
2020-12-10_C_the_rest_of_the_filename_of_the_image.jpg
2021-01-04_A_the_rest_of_the_filename_of_the_image.jpg
2021-01-04_B_the_rest_of_the_filename_of_the_image.jpg
Thus it only includes YYYY-MM-DD and then some further sorting/index information (such as a, b, c, ...), and then the rest of the image's filename.
The main goal is to be able to extract the date as follows:
10 Dec, 2020
10 Dec, 2020
10 Dec, 2020
04 Jan, 2021
04 Jan, 2021
To get the date part out of you file name, you could either use the slice or split filter.
If you do use the split filter, you will want to use the first filter, in order to take the first element of the created array.
To get the date format you want, you can just use the date filter.
With slice:
{{ "2020-12-10_A_the_rest_of_the_filename_of_the_image.jpg" | slice: 0, 10 | date: "%d %b, %Y" }}
With split:
{{ "2020-12-10_A_the_rest_of_the_filename_of_the_image.jpg" | split: "_" | first | date: "%d %b, %Y" }}
Those both results in: 10 Dec, 2020
Additionally, you might want to read the Ruby documentation about the date format available at: https://ruby-doc.org/stdlib-2.4.1/libdoc/time/rdoc/Time.html#method-c-strptime

Jekyll using pipe operator in where_exp

I am using Jekyll 3.8. My posts contain date attribute set. Some of them contain values from the past (e.g. 2001-01-01), some of them from the future (e.g. 2109-12-31).
What I would like to achieve is to display only posts that are in the past (so that their date is smaller than now). Now, I've managed to get it done using:
{% capture current_time %}{{'now' | date: '%s'}}{% endcapture %}
{% for post in site.posts %}
{% capture post_time %}{{post.date | date: '%s'}}{% endcapture %}
{% if post_time >= current_time %}
DISPLAY THE ITEM
{% endif %}
{% endfor %}
but it's not efficient.
I would like to have it done using where_exp filter. Now - is it possible?
My draft looks like:
{% capture current_time %}{{'now' | date: '%s'}}{% endcapture %}
{% assign filtered_posts = site.posts| where_exp:"post","post.date | date: '%s' >= current_time" %}
{% for post in filtered_posts %}
DISPLAY THE ITEM
{% endfor %}
but I'm receiving Liquid Exception: Liquid error (line 5): comparison of Time with String failed in source.md.
I suppose, that the problem lies in | date: '%s' from {% assign filtered_posts = site.posts| where_exp:"post","post.date | date: '%s' >= current_time" %}.
Therefore:
can I even use filters (pipe) in the where_exp expressions?
If not, then - can I somehow cast the post.date to string without filters, or cast current_time to string and make the comparision work at the same time?
I had a similar problem, which I described in detail in the Jekyll community forum. It is about getting a list of future events including today, and the OP's similar approach did not work here as well:
{% assign events_list = site.events | where_exp: "event", "event.date >= site.time | date: %F" %}
So I created a filter plugin in _plugins/to_time.rb, which converts a string to a Time object:
module Jekyll
module AssetFilter
def to_time(date_string)
DateTime.parse(date_string).to_time
end
end
end
Liquid::Template.register_filter(Jekyll::AssetFilter)
This first parses the string to a DateTime object and then uses this to_time function to make a Time object.
Then I assign a variable with the current time, apply the pipe operator with the filter I need, and then I add the to_time filter in the end:
{% assign today = 'now' | date: '%F' | to_time %}
Using now, then using %F to just get the date part of it, then converting it back to Time, so today will be todays date at 0:00 in the morning.
Then I can compare it with the date object from my events collection items:
{% assign events_list = site.events | where_exp: "event", "event.date >= today" %}
I cannot reproduce your error as where_exp is throwing an error because of the pipe in the comparison expression.
Nevertheless, you can compare post.date which is a Time object to site.time (generation time) to get posts that are in the past.
{% assign filtered_posts = site.posts | where_exp: "post","post.date <= site.time" %}

Strange date format in database

I have some very strange looking 18 character alphanumeric datetimes in a SQL database, they seem to be using Hexadecimal?
I can find out what the dates are through the application which uses them, but I was looking for a way to convert them via a query. Do you know how I would convert these with TSQL?
000B3E4Bh01F2D947h - 29/05/2018 09:04:52
000B3E0Dh03A16C1Eh - 23/05/2018 10:22:26
000B3E4Eh0248C3D8h - 01/06/2018 10:38:43
000B3E4Eh0249B449h - 01/06/2018 10:39:44
I assume the date and time are separated as below, but I don't know to convert the individual parts if anyone can help with this? Thanks!!
000B3E4Eh (date) - 0249B449h (time)
(The dates are in dd/mm/yyyy format)
Your hex values are separated as you have assumed (with the h used as a delimiter) and represent integer values to add to a baseline date and time value.
Using your 000B3E54h0221CBFEh - 07/06/2018 09:56:09 value this translates as:
Date portion: 000B3E54
Integer Value: 736852
Time portion: 0221CBFE
Integer Value: 35769342
These integer values are then added as days to the date 0001/01/00 (which SQL Server can't handle, hence the +/-1 below) and milliseconds to 00:00:00 respectively, which you can see working in this script:
select convert(int, 0x000B3E54) as DateIntValue
,dateadd(day,convert(int, 0x000B3E54)-1,cast('00010101' as datetime2)) as DateValue
,convert(int, 0x0221CBFE) as TimeIntValue
,cast(dateadd(millisecond,convert(int, 0x0221CBFE),cast('19000101' as datetime2)) as time) as TimeValue
,cast(datediff(day,cast('00010101' as datetime2),'20180607')+1 as binary(4)) as DateHexValue
,cast(datediff(millisecond,cast('20180607' as date),cast('2018-06-07 09:56:09.342' as datetime2)) as binary(4)) as TimeHexValue
Which outputs:
+--------------+-----------------------------+--------------+------------------+--------------+--------------+
| DateIntValue | DateValue | TimeIntValue | TimeValue | DateHexValue | TimeHexValue |
+--------------+-----------------------------+--------------+------------------+--------------+--------------+
| 736852 | 2018-06-07 00:00:00.0000000 | 35769342 | 09:56:09.3420000 | 0x000B3E54 | 0x0221CBFE |
+--------------+-----------------------------+--------------+------------------+--------------+--------------+
Note the judicious use of datetime2 values to ensure the right amount of milliseconds are output/returned, as SQL Server datetime is only accurate to the nearest 3 milliseconds.