Icefaces datetimeentry starting year as 00 instead 20 when i enter two digit year - jsf-2

I’m using icefaces datetimeentry, everything works fine except one thing. When I enter two digit year like 19, it is showing as 0019 instead of 2019. Is there any help to convert it to 2019?
Do I need any converter or ajax call?

you must set the "pattern" attribute on the dateTimeEntry tag to a two digits year format (like "dd/MM/yy"). The default value for this property is "MM/dd/yyyy" (see icefaces taglib docs ) that yields 00yy when you set a two digits year (see SimpleDateFormat Javadoc).

Related

How to format multiple Date type columns in dd/mm/yyyy using Google Sheets Api in Ruby?

I have multiple date type columns like "User Joining Date", "Birthdate", "Arrival Date" etc. These dates are already in dd/mm/yyyy format.
But the issue is gsheet interprets date like 02/01/2019 as 1st February 2019 but interprets 13/01/2019 as 13th January 2019 which causes formatting issue.
02/01/2019 is left aligned whereas 13/01/2019 is right aligned. Moreover, this also causes sorting issues.
I've tried changing the locale and language of the spreadsheet but nothing helped.
You can always deliver the date in the way Google Sheets expects, in your case mm/dd/yyyy.
You can transform a Time, Date or DateTime instances into any format you want by using #strftime. This outputs a string in the provided format. Have a look at http://www.strftime.net/ for the different options and a live demo.
Alternatively you can use the localize functionality of Ruby on Rails. This can be done by calling:
I18n.l your_time_variable, format: :default

How to get date out of a cell containing the string "2017|03"?

Here is my data:
I am trying to build a SUMIFS formula to sum the sessions, if the month = "last month" (i.e., parsed out of these strings), and the Channel Grouping = "Display".
Here's what I have so far:
=SUMIFS(H3:H,F3:F,________,G3:G,"Direct")
Since this is a string, not a date, I am not sure how to get it to match "last month".
Why not build up a string like this (or just hard-code it?)
=sumifs(H3:H,F3:F,year(today())&"|"&text(month(today())-1,"00"),G3:G,"Direct")
This builds up a string equal to "2017|03" by taking the year from today's date (2017) and one less than the month number from today's date which at time of writing is April so 4-1=3. The text function formats it with a leading zero. So the whole thing is"2017" & "|" & "03" which gives "2017|03" - this is compared against column F.
Note: January would be a special case (existing formula would give "2018|00" for previous month to January 2018 so would need a bit of extra code to cover this case and make it fully automatic).
By 'hard-code it' I mean just put 2017|03 in as a literal string like this
=sumifs(H3:H,F3:F,"2017|03",G3:G,"Direct")
then just change it manually for different months.
Here is a more general formula
=sumifs(H3:H,F3:F,year(eomonth(today(),-1))&"|"&text(month(eomonth(today(),-1)),"00"),G3:G,"Direct")
Just change the -1 to -2 etc. for different numbers of months.
EDIT
In light of #Max Makhrov's answer, this can be shortened significantly to
=sumifs(H3:H,F3:F,text(eomonth(today(),-1),"YYYY|MM"),G3:G,"Direct")
I would like to add two more options:
1
This formula is slightly shorter and more powerrful, because it gives the full control over date format:
=TEXT(TODAY(),"YYYY|MM")
formula syntax is here:
https://support.google.com/docs/answer/3094139?hl=en
2
In your case converting date to string is more efficient because it calculates one time in the formula, so there's fewer calculations. But sometimes you need to convert text into date. In this case I prefer using regular expresions:
=JOIN("/",{REGEXEXTRACT("2017|03","(\d{4})\|(\d{2})"),1})*1
How it works
REGEXEXTRACT("2017|03","(\d{4})\|(\d{2})") gives 2 separate cells output:
2017 03
{..., 1} adds 1 to ... and adds it to the right:
2017 03 1
JOIN("/", ...) joins the ... input:
2017/03/1
This looks like date, but to make it real date, multimpy it by 1:
"2017/03/1"*1 converts string that looks like date into a number 42795 which is serial number for date 2017 march 01

Parse week strings for comparison using Java 8

I want to compare string representations of weeks, e.g. week "01/17" is before "02/17" and after "52/16".
The following code throws an exception, I guess because my string doesn't hint at the exact day of each week. However, I don't care - it could all be Mondays or Thursdays or whatever:
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("ww/YY", Locale.GERMANY);
LocalDate date1 = formatter.parse(str1, LocalDate::from);
Do I need to modify the parser? Or parse to some other format? Unfortunatley there is no object like YearMonth for weeks...
One solution would be to always default to the same day, say the Monday. You could build a custom formatter for that:
DateTimeFormatter fmt = new DateTimeFormatterBuilder()
.appendPattern("ww/YY")
.parseDefaulting(ChronoField.DAY_OF_WEEK, 1)
.toFormatter(Locale.GERMANY);
You can now build LocalDates representing the Monday of the given week:
LocalDate d1 = LocalDate.parse("01/17", fmt);
LocalDate d2 = LocalDate.parse("52/16", fmt);
System.out.println(d1.isAfter(d2));
which prints true because 01/17 is after 52/16.
I wasn't able to find a way for this to work with the DateTimeFormatter class, but I would like to suggest a different approach.
The Threeten Extra library contains a number of classes that were deemed too specific to include in the java.time library. One of them is the YearWeek class you mention.
Your problem can be solved by parsing the week-number and year manually from the input-string and then invoking the YearWeek creator-method like this:
YearWeek yw = YearWeek.of(year, monthOfYear);
tl;dr
YearWeek.parse( "2017-W01" )
ISO 8601
Or parse to some other format?
Yes, use another format.
Use the standard ISO 8601 formats when serializing date-time values to text. The standard includes support for week dates.
For a year-week that would be four year digits, a hyphen, a W, and two digits for the week of the year.
2017-W01
Get clear on your definition of a “week”. The ISO 8601 definition is that:
The Week # 1 contains the first Thursday of the year, and
Runs Monday-Sunday.
So years run either 52 or 53 weeks long. And note that under this definition, the first few days of the year may be in the prior year when week-numbering. Likewise, the last few days of the year may be in the following year when week-numbering.
If you want to indicate a particular day within that week, append a hyphen and a single digit running 1-7 for Monday-Sunday.
Tip: To see ISO 8601 week numbers by default on your computer, you may need to adjust your OS setting. For example, on macOS set System Preferences > Language & Region > Calendar > ISO 8601 to make apps such as Calendar.app to display week numbers with this standard definition.
2017-W01-7
By the way, a couple of similar representations:
An ordinal date meaning the year and the day-of-year-number running from 1-366 is year, a hyphen, and a three-digit number: 2017-123
Month-Day without year is two hyphens, month number, hyphen, and day-of-month number: --01-07
Note that the use of Locale as seen in the Question is irrelevant here with the standard ISO 8601 formats.
YearWeek
Unfortunatley there is no object like YearMonth for weeks...
Ahhh, but there is such a class.
For a class to directly represent the idea of a week-year, see the correct Answer by Henrik. That Answer shows the ThreeTen-Extra library’s class YearWeek.
The YearWeek class can directly parse and generate strings in standard format.
YearWeek yw = YearWeek.parse( "2017-W01" );
You can compare the YearWeek objects with methods: compareTo, equals, isBefore, isAfter.
yw.isBefore( thatYw )
The ThreeTen-Extra project offers other classes such as YearQuarter that you may find useful.

Show 0001 year in Telerik grid column from extensions for ASP.NET MVC

Telerik extensions for ASP.NET MVC ( click ). Our app widely uses date like 01/01/0001 (DateTime.MinValue). Please don't ask "why not nullable?". Yeap, you are right, but there are a lot of work to rewrite all the stuff, so we need a temporary solution.
Currently date like '01/01/0001' is shown as '01/01/1' in the column below:
columns.Bound(p => p.EffectiveSince).Width(50).Format("{0:MM/dd/yyyy}");
If click click 'Edit' at some row and just press 'Update' w/o any modifications, then such date ('01/01/1') is saved as 01/01/2001, which breaks the logic. But if manually type '01/01/0001' - it is saved as expected. So, telerik "eats" leading zeros.
Could you suggest a solution of this "problem", how to display "01/01/0001" instead of "01/01/1" ? (yes, I know about nullable, another solution..)
Found the reason, telerik ate leading zeros. Just beatify telerik.common.min.js and search for the string "yyyy: aO". aO is year returned by getFullYear(). That's why all the dates like '01/01/0001' are converted to 01/01/1, which cause to problems with displaying / sending / saving to db such dates. Telerik's formatString function displays year in format 'yyyy' in another way vs C# string.Format. The fix is easy. Just change
yyyy: aO // 0001 year == 1
to
yyyy: ('0000' + aO).slice(-4) // 0001 year = 0001

NSDateFormatter date format string

I have an odd issue with an NSDateFormatter, I am passing the following string as a date format "dd/MM/yy"
If I enter 50 for the year I get a conversion to 1950 however anything below that for instance 49 results in 2049. Any ideas how I can remedy this?
Many thanks.
It sounds like you'll need to force a four digit response (or programmatically prepend two digits of "19") to wherever you're drawing your string from. Lots of people are using dates in the near to mid-term future like "12/21/12" (end of the Mayan Calendar era) so it's natural that a 2 digit year assumes 2000+ for digits 1-50 and 1999- for digits (50-99).
I'm also seeing a number of Google hits on the keyword terms "NSDateFormatter" & "century", b.t.w.

Resources