TYPO3, Fluid template. Display a div if the date of today is between 05/01 and 10/01 - date

I want to display a div if the date of today is between "05/01" and "10/01". Could someone please help me with it? :)
I could only display it when the date is between "01/01" and "10/01" by writing this code:
<f:if condition="{f:format.date(date: '10/01' format: 'm/d')} < {f:format.date(date: 'now', format: 'm/d')}">
<f:then><div>The Store is closed.</div></f:then>
<f:else><div>The Store is open!</div></f:else>
</f:if>
Many thanks in advance!

Combine two conditions by "&&"
<f:if condition="{f:format.date(date: 'today', format: 'Y-m-d')} >=
{f:format.date(date: '2019/02/27', format: 'Y-m-d')} && {f:format.date(date:
'today', format: 'Y-m-d')} <= {f:format.date(date: '2019/03/01', format: 'Y-m-d')}">
<f:then>
<div>The Store is closed.</div>
</f:then>
<f:else>
<div>The Store is open!</div>
</f:else>
</f:if>
Condition 1 (date of today equal or larger Feb 27):
{f:format.date(date: 'today', format: 'Y-m-d')} >= {f:format.date(date: '2019/02/27', format: 'Y-m-d')}
Condition 2 (date of today less or equal March 01):
{f:format.date(date:'today', format: 'Y-m-d')} <= {f:format.date(date: '2019/03/01', format: 'Y-m-d')}

Related

format month of grouped news items in Typo3

I have news items, grouped by year and month. Here the code:
<f:groupedFor each="{paginatedNews}" as="groupedNews1" groupBy="yearOfDatetime" groupKey="year">
<f:groupedFor each="{groupedNews1}" as="groupedNews" groupBy="monthOfDatetime" groupKey="month">
<div style="border:1px solid blue;padding:10px;margin:10px;">
<h1>{month} {year} </h1>
<f:for each="{groupedNews}" as="newsItem">
<f:render partial="List/Item" arguments="{newsItem: newsItem,settings:settings,iterator:iterator}" />
</f:for>
</div>
</f:groupedFor>
</f:groupedFor>
Unfortunately, month and year are displayed in numbers in frontend, e.g.
03 2019
..(some news items)
02 2019
...
01 2019
However, what I need is this:
March 2019
...
February 2019
...
January 2019
How can I achieve this?
On the original EXT:news this method has been used:
Look at the template EXT:news/Resources/Private/Templates/News/DateMenu.html
<f:translate key="month.{month}" />
on the EXT:news/Resources/Private/Language/locallang.xlf you will find:
<trans-unit id="month.01" xml:space="preserve">
<source>January</source>
</trans-unit>
And so forth.

Change/set date in Freemarker

I have to use two dates to get some data (somenumbers): start_date and end_date.
The end_date should be now but I want the start_date to be the 1st of the current month, which means the start_date's date should always be 1st. Is it possible to do something like:
<#assign end_date = .now>
<#assign start_date = .now?replace('dd', 01)>
replace(,) can be used but for only strings or only numbers.
Well, if absolutely necessary, I'd do it somehow like:
<#assign end_date = .now?date >
<#assign now_string = .now?date?iso_local >
<#assign start_string = now_string[0..7] + "01" >
<#assign start_date = start_string?date.iso >
(The code can be shortened, I made it a bit "talkative" for better understanding of my intention.)
Anyway, such things do not belong to View, they should be done in your Controller.
This worked for me!
<#assign today = .now?date?iso("Europe/Zurich")/>
<#assign monthStart = today[0..7] + "01" />

Watir,click on a date from a date picker 62 days from current date

I need to click on a date that is 62 days later than the current date.
The next button for the months is clickable so I have been able to move the calendar to 2 months later but unable to select the date.
Eg if the current date is 4 July then I need to select 6th Sept.
My code at the moment looks somewhat like this.
b.element(:name, "policyperiod_endDate").click <-- datetime picker's click
b.element(:xpath, "(//button[#type='button'])[50]").click <-- next month
b.element(:xpath, "(//button[#type='button'])[50]").click
b.element(:link,"06").click <--doesnt select 08
b.element(:xpath, "(//button[#type='button'])[68]").click <-selects fixed cell n
how to select 06?
The outer HTML is like this:
input type="text" class="pull-left pdr35 ng-isolate-scope ng-pristine ng- invalid ng-invalid-required" datepicker-popup="yyyy-MM-dd" is-open="datePickerOpts.datepickers.policyperiod_startdate[1]" ng-model="policyIVOs.policyEndDate" name="**policyperiod_endDate**" datepicker-options="dateOptions" show-button-bar="false" close-on-date-selection="true" show-weeks="false" ng-click="open($event, 'policyperiod_startdate', 1)" min-date="policyEndMin" max-date="policyEndMax" required="" readonly=""

Get date based on month, year, day and week number (ColdFusion)

I found a similar answer to my question, but it was in SQL and kinda went over my head (Given year, month, day and week number how to find the date?(Sql Server 2005 Set based)).
I'm writing a schedule creation app where a user will select the month, day of week (Sun-Sat, aka 1-7), and choose optionally if this will recur throughout the month each week.
Given that, I'm trying to write a function in ColdFusion that will return the actual date if I pass in the month, day, week number, and year. Dates always confuse the heck out of me.
So I know this is an old post but here are some current options in script or tag.
Week Number<br />
<cfscript>
myDateTime = now();
WriteOutput(week(myDateTime & "<br/>"));
</cfscript>
<br />
Day of week<br />
<cfscript>
mydayofweek = (DayOfWeek(myDateTime));
WriteOutput(DayOfWeek(myDateTime & "<br/>"));
</cfscript>
<br />
Day of year<br />
<cfscript>
WriteOutput(DayOfYear(myDateTime & "<br/>"));
</cfscript>
<br />
Days in month<br />
<cfscript>
WriteOutput(DaysInMonth(myDateTime & "<br/>"));
</cfscript>
<br />
<!--- What date are we working with --->
<cfset workingdt = '2022-5-05' />
<!--- Get the week start date. --->
<cfset dtWeekStart = (workingdt - DayOfWeek( workingdt ) + 1) />
<!--- Get the week end date. --->
<cfset dtWeekEnd = (workingdt + (7 - DayOfWeek( workingdt ))) />
<!--- Get the working week --->
<cfset dtworkingweek = '#week(workingdt)#' />
<br />
<!--- Output the dates: --->
<cfoutput>
Today: #DateFormat( workingdt )#<br />
Week Start: #DateFormat( dtWeekStart )#<br />
Week End: #DateFormat( dtWeekEnd )#<br />
Week Number: #dtworkingweek#<br />
</cfoutput>
<br />

Fluid compare dates

I want to compare two dates. I want to make a condition which checks if the date in my database is older than the date in two days.
Here are my two variables:
{<f:format.date format="d.m.Y">+2 days</f:format.date>}
{<f:format.date format="d.m.Y">{day.valid}</f:format.date>}
I want to solve this in the template, not in the model or the controller.
Assign your date to variable »yourdate«.
<f:if condition="{f:format.date(date: '+2 days', format: 'Y-m-d')} < {f:format.date(date: yourdate, format: 'Y-m-d')}">
<f:then>
yourdate is smaller than now + 2 days.
</f:then>
<f:else>
yourdate is greater than or equal to now + 2 days.
</f:else>
</f:if>
Here is my current solution which adds in a current date and does some calculations with the date from the content.
In the controller, add the current date to the data:
$this->view->assign('date_now', new \DateTime());
This is available as {date_now} in fluid then:
<f:if condition="{f:format.date(date: date_now, format: '(Y-m-d)')} > {f:format.date(date: '{event.date}-4 weeks', format: '(Y-m-d)')}">
<f:then>
<p>Event date is past</p>
</f:then>
<f:else>
<p>Event date is upcoming</p>
</f:else>
</f:if>
Note how on the right side, where some calculation is done, additional quotes and curly brackets come in ('{event.date}-4 weeks').
PS I prefer the Y-m-d format to U for a date comparison, as we don't want to compare the current time – just the date.
Convert the date to an unix timestamp using format="U" and compare them. You need to add a variable which contains the comparing date.
<f:if condition="{f:format.date(date: day.valid, format: 'U')} > {f:format.date(date: date_compare, format: 'U')}">
Date is valid
</f:if>
Actually: because DateTime has a getTimestamp method (http://php.net/manual/en/datetime.gettimestamp.php, since 5.3.0) which perfectly conforms to the supported getter method naming in Fluid, the following is perfectly possible. Given $date1 and $date2 are both DateTime instances assigned to the template:
<f:if condition="{date1.timestamp} < {date2.timestamp}">...</f:if>
Will compare the two dates as unix timestamp integers without the need to format the dates. So for your case, assign a $date = (new \DateTime('now'))->modify('+2 days'); from your controller action and compare to that in Fluid. Or just assign the time() timestamp and compare directly to that, skipping the DateTime usage.