Editing the year in date field in EXTJS 4.0 is defaulting the year to 2020 - extjs4.2

I have a date field in a form
xtype: 'datefield',
id: 'dateId',
maskRe: /[0-9\/]/,
format : 'm/d/Y',
for ex - if the date populated in that field is 07/30/2014. now i want to manually edit the date, if i give two backspaces, which means 07/30/20. and then click some where in the form, the year is getting defaulted to 07/30/2020. how to stop this getting defaulted to that 2020 year.

I answered this in my comment, but I will try to expand on that comment as much as possible, and make it as clear as possible. Here is the original comment:
"07/30/20 is equivalent to 07/30/2020. This is expected and normal behavior. When a year is only two digits, it is always the last two digits, so 20 == 2020, 00 == 2000, 14 == 2014, etc."
So, let me step you through an example.
You type 08/08/2014 into the datefield.
Hit backspace twice, removing the 1 and the 4.
Now you have 08/08/20.
When writing dates, the year can be written as 2 digits or 4. If written as two, the last two digits are used. So, the year 20 is the same as the year 2020.
The datefield has logic to handle 2 digit dates, so it knows that 08/08/20 is actually 08/08/2020.
That is why when you have 08/08/20 in a datefield, it interprets it as 08/08/2020.

Related

Google Sheets function "=Year(2001)" returns 1905

When I enter =Year() with any year as argument (e.g. 2010), I always get 1905 as a result
At first i thought that my cell reference is broken, but it also happens when I enter the year directly into the formula.
The same thing happens when I enter =TEXT(2010;"YYYY") --> 1905 ???
What am I doing wrong?
You need to write
=YEAR(DATE(2010,1,1))
What 2005 is equivalent to
=INT(DATE(1905,3,19))
YEAR takes an integer value, DATE will convert for you the year, month and day to an integer.

Cakephp 3 i18nFormat string for the number of weeks in a specified date

How to get number of week for specific date in cakephp 3?
$this->mydate->i18nFormat('yyyy-MM-dd') will display year-month-date.
But what about string format for week number?
Thanks.
Have a closer look at the docs for Cake\I18n\Time::i18nFormat(), it tells you what you can pass as the format, and where to find a list of the accepted formatting patterns:
[...] You can either pass IntlDateFormatter constants as the first
argument of this function, or pass a full ICU date formatting string
as specified in the following resource:
https://unicode-org.github.io/icu/userguide/format_parse/datetime/#datetime-format-syntax.
Cookbook > Date & Time > Formatting > Cake\I18n\Time::i18nFormat()
So long story short, the pattern letter for the week of the year is w, or ww if you want a leading zero, and for the week of the month it's W or WW.

unexpected result converting date using datestr

Can anyone tell me why if I type in MATLAB
datestr('17-03-2016','dd-mmmm-yyyy')
I get
06-September-0022
From the datestr docs
DateString = datestr(___,formatOut) specifies the format of the output text using formatOut. You can use formatOut with any of the input arguments in the above syntaxes.
So in your example the 'dd-mmmm-yyyy' is specifying the output format, not the input format.
Also
DateString = datestr(DateStringIn) converts DateStringIn to text in the format, day-month-year hour:minute:second. All dates and times represented in DateStringIn must have the same format.
where
'dd-mm-yyyy' is not in the list of allowed DateStringIn formats AND the documentation explicitly recommends using datenum to ensure correct behaviour. (Note: I underlined the wrong must in the sentence, it's the second must I wanted to emphasise)
So Sandar_Usama's answer of
datestr(datenum('17-03-2016','dd-mmmm-yyyy'))
is the officially correct method straight out of the docs.
Bottom line, always read the documentation.
Use this instead: datestr(datenum('17-03-2016','dd-mmmm-yyyy'))
To address the last unanswered point in this question, why does datenum behave like this?
>> datestr(datenum('17-03-2016'))
ans =
06-Sep-0022
Without explicitly telling datestr and datenum how it should treat the input, it will try to match against the expected formats. Since none of the documented formats match (see #dan's answer), it fails.
Although what it does next is undocumented, at least up to whatever version of Matlab we are running, it falls into a "last resource" attempt to give you a date number.
Matlab will try to parse different month names from your input, remove non-numeric characters, and then timedate elements from the string. In your case, they are 17, 03, and 2016. The first is expected to be either month or year. Since there's no 17th month, it is treated as year. Then 03 is the month, and 2016 is the day.
Now, March 2016th, 17 is not a valid date, but Matlab will give it a slack and read as 1985 days past March 31st, 17. And that gives us September 6th, 22.
Because Matlab's timestamp is a floating number for the number of days since its epoch, you can trigger that answer, using valid dates, like so:
>> datestr(datenum('0017-03-31') + 1985)
ans =
06-Sep-0022

ISO emacs/elisp to determines dates corresponding to first/last days of a week, e.g. ISO 8601 2013-WW47

I like creating headings that look like
** WW47 (Monday November 18 - Sunday November 24, 2013)
I know how to use format-time-string, etc., in emacs/elisp to determine various definitions of the week-number (%U, %V, %W).
Q: how can I go backwards? In emacs/elisp, determine the dates of the first and last days of the week, given a year and week number?
More generally, parse a time-string such as ISO 8601 week-dates 2006-W52-7, or the week without day within week 2013-W46.
More generally still - many date and time representations imply date intervals. Weeks and months in particular imply intervals, although I suppose almost any time representation of a given precision can be interpreted as corresponding to an interval of time units less than the precision.
Q: are there (reasonably standard) emacs/elisp functions for determining first and last dates of a month, e.g. in terms of year/day-of-year format? Etc.
--
This post is mainly a "how do I do this in emacs/elisp?" question.
This sort of question appears to be quire common - there are similar questions on stackoverflow asking "how do I do this in Javascript/C#/..." etc., etc., etc.
I can do the math myself. But (a) better if there is a standard emacs/elisp function to do this, and (b) it is apparent from googling that there are many gotchas and issues, further emphasizing the goodness of using a standard library function, if one exists.
E.g. Getting first date in week given a year and weeknumber
I had a similar problem (see https://emacs.stackexchange.com/questions/43984/convert-between-iso-week-and-a-normal-date).
Using my solution on https://emacs.stackexchange.com/questions/43984/convert-between-iso-week-and-a-normal-date, the solution to your first question is found below.
Example:
(iso-header 2018 32)
"** WW32 (Monday August 06 - Sunday August 12, 2018)"
(iso-header 2018 53)
"** WW01 (Monday December 31 - Sunday January 06, 2019)"
(defun iso-header(year week)
(concat
(format-time-string "** WW%V (%A %B %d - " (iso-beginning-of-week year week))
(format-time-string "%A %B %d, %Y)" (iso-end-of-week year week))))

Bug in Zend_Date (back in time)

I have a very strange problem, Zend_Date is converting my timestamp to a year earlier.
In my action:
// Timestamp
$intTime = 1293922800;
// Zend_Date object
$objZendDate = new Zend_Date($intTime);
// Get date
echo date('Y-m-d',$intTime).'<br>';
echo $objZendDate->get('YYYY-MM-dd');
This outputs:
2011-01-02
2010-01-02
Can anyone tell me what i'm doing wrong?
From the ZF issue tracker it seems this is a known issue:
Recently a lot of ZF users are filing a bug that Zend_Date returns the wrong year, 2009 instead of 2008. This is however expected behaviour, and NOT A BUG!
From the FAQ:
When using own formats in your code you could come to a situation where you get for example 29.12.2009, but you expected to get 29.12.2008.
There is one year difference: 2009 instead of 2008. You should use the lower cased year constant. See this example:
$date->toString('dd.MM.yyyy');
instead of
$date->toString('dd.MM.YYYY');
From the manual
Note that the default ISO format differs from PHP's format which can be irritating if you have not used in previous. Especially the format specifiers for Year and Minute are often not used in the intended way.
For year there are two specifiers available which are often mistaken. The Y specifier for the ISO year and the y specifier for the real year. The difference is small but significant. Y calculates the ISO year, which is often used for calendar formats. See for example the 31. December 2007. The real year is 2007, but it is the first day of the first week in the week 1 of the year 2008. So, if you are using 'dd.MM.yyyy' you will get '31.December.2007' but if you use 'dd.MM.YYYY' you will get '31.December.2008'. As you see this is no bug but a expected behaviour depending on the used specifiers.
For minute the difference is not so big. ISO uses the specifier m for the minute, unlike PHP which uses i. So if you are getting no minute in your format check if you have used the right specifier.
To add to zwip's answer, what happens behind the scenes is that your date format YYYY-MM-dd is actually translated into o\-m\-d, which is then passed to PHP's date() function internally with the timestamp you provided.
Like mentioned in the other answer, and in the documentation for the o format on the date format page, the calculation of the year based on the ISO week can sometimes result in the year being one different to the value that you expect.