How to get the current year from freemarker template - date

I have use the ${.now} to get the current time stamp inside the freemarker templates, but I want to know how can I get only the year?

Like ${.now?string('yyyy')}. (Note that this will return a string, which is what you want if you only want to print it. If by any chance you need a number, so that you can do arithmetic with it, then it's .now?string('yyyy')?number.)

Related

Google spreadsheet month name (MMMM) without declension

I want to display formatted month name in the basic form (nominative) as a label. In Czech language (and several next Slavic languages) we use declension. So if I use =TEXT(NOW();"MMMM") the cell shows month name in genetive instead of nominative (i.e. srpna instead of srpen).
Q: How to format the date in the nominative? The acceptable solution will offer some native way how to solve it but not:
manipulating with strings (month names are too complex)
having some another list with month names
calling own formula (Google script)
Maybe there is no native way how to solve this and it will be implemented in the future, so Google Script seems to be the easiest hotfix for now. And because I'm expecting many answers with the script, I'm putting the one here but this question is not about the javascript/google-script.
function monthName(date) {
var months = ["Leden","Únor","Březen","Duben","Květen", "Červen","Červenec","Srpen","Září","Říjen","Listopad","Prosinec"];
return months[date.getMonth()];
}

How can I compare and check date of program and the system date in MVS 2012 Coded UI test?

I am trying to compare and check the date if it is today's date or not in a spesific program. I tried to use assertion method but when I use it the time will remain same if you try it next day. The main problem that I need to know when open a page from program It should be today's date and should be passed. if you know already anything about it please let me know also :)
Thanks yo!
Use System.DateTime.Now.ToString("yyyy-MM-dd") as one argument of the assertion. You may need to use a different format rather in the ...ToString() method. The exact format depends on how the date is shown on the screen.
This could be done using "StringAssert" to verify that your programs date string contains today's date string, while ignoring the time:
var programDateString = "7/25/2016 12:00:00"; //this is an example of your date retrieved from the application with time included
var todaysDate = System.DateTime.Today.ToShortDateString(); //short date string
StringAssert.Contains(programDateString, todaysDate);

How can i get only the date and time in selenium IDE

I'm using selenium IDE and i would like to capture only the date and time from a field that was updated
Example:
Updated by James in 07/05/2015 - 09:50
I need to get only this date and the time from the record updated
Is there a way to do this ?
Thanks
Well you can do it with storeEval(). You can use JavaScript to manipulate stored variables. Lets assume that you stored that whole text in variable updated
${updated} == "Updated by James in 07/05/2015 - 09:50"
Now we just need to get that variable and get part of its text:
Command: storeEval()
Target: storedVars['updated'].split(' ')[4]
Value: date
Basically we get updated and we split it into array using space as separator, and then we get 4th element of array, which contains date and store in it new variable date.
Now:
${date} == "07/05/2015"
The same you can do with time.

Getting last day of the current month

I can get the last day in php using cal_days_in_month(CAL_GREGORIAN, 03, 2014); function and then assign it to view. But I want to know is it possible to get the last day in current month using smarty date_format function?
Thanks in advance
I'm not sure you can solve this only using the date_format function. I wouldn't do it anyway, since this put way too much application logic into the template.
But... if you want to do this anyway, just add a template function to get what you want.
PHP:
$tpl = new Smarty();
$tpl->registerPlugin("function","lastdayofmonth", "smarty_function_lastdayofmonth");
$tpl->display('your_template.tpl');
function smarty_function_lastdayofmonth($params, Smarty_Internal_Template $template) {
return date("Y-m-t", strtotime($params['date']));
}
Smarty:
{assign var='datevar' value='2014-03-06'}
{lastdayofmonth date=$datevar}
Output:
2014-03-31
Keep in mind, this is just an easy example. There are more than one way to use plugins within Smarty.

How do I validate dates in a Perl CGI-script?

I'm creating a small reporting script in Perl CGI. I want to have the start/end date there to filter the events on the report. So now I wonder how to validate the input in some easy, Perl-way.
The way I generate the form with those fields is:
print textfield({-name=>'start_date', -value=>$start_date});
print textfield({-name=>'end_date', -value=>$end_date});
Then it goes to the database query.
Is there a simple, Perl-ish way to validate those dates? Not only as having the right number of characters, as this is simple enough via a regexp, but I'd like to report some error if the user enters 29.02.1999 or so.
I'll just go ahead and own up to being crazy, but what I like to do is use Time::Local, and flip the time back to epoch time, and then, when it's a nice clean integer, you can impose whatever sort of sanity check you like on it.
For general form validation you should use a nice framework like Data::FormValidator which has a Data::FormValidator::Constraints::DateTime module for date validation
Disclosure: I'm the author of Data::FormValidator::Constraints::DateTime
FormFu seems to be the popular library for handling forms in Perl these days. I believe it replaces the CGI HTML generation code, but it is quite powerful.
It includes a bunch of code for validating common data types, including dates.
You can calculate dates in Perl with Time::Local, which can be set to accept invalid times and still calculate the correct date (e.g. the 32th day of a month) or the check the dates and reject invalid dates.
I nearly always opt to convert something like this into DateTime object. And I use something like DateTimeX::Easy to help ease the process:
use DateTimeX::Easy;
my $start_date = DateTimeX::Easy->new( '30th Oct 2009' );
my $from_date = DateTimeX::Easy->new( 'today' );
say $start_date->dmy;
say $from_date->dmy;
# => 30-10-2009
# => 01-10-2009
The only caveat is that DateTime and its associated modules are a bit hefty on memory which is something you may want to keep an eye on when using it in CGI.
/I3az/