# idate problems

- Thread: https://externals.io/message/10750
- Original archive: https://news-web.php.net/php.internals/10750
- Started by Nuno Lopes on 2004-06-24T10:16:27+00:00
- Messages: 5
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #10750 — Nuno Lopes — 2004-06-24T10:16:27+00:00

URL: https://externals.io/message/10750#10750

Hello,

I've already reported this to the list some time ago, but nobody answered me
until now.

I think that the idate function has two little problems:

1) (i)date('L') should return the same (1 if is leap year, 0 otherwise), but
they aren't outputing the same
echo date('L'); //1
echo idate('L'); //0


2) idate('y') is supposed to return the year with *two*digits, althought it
returns just 4. This can be fixed with a simple sprintf?


Can somebody look at this, please?

Thanks,
Nuno

---

## #10755 — Christian Schneider — 2004-06-24T12:13:32+00:00

URL: https://externals.io/message/10750#10755 · In reply to: #10750

Nuno Lopes wrote:
> 1) (i)date('L') should return the same (1 if is leap year, 0 otherwise), but
> they aren't outputing the same
> echo date('L'); //1
> echo idate('L'); //0

Yes, this is indeed a bug in the isleap macro (you needed to call it 
with double parens), the fix is

diff -u -r1.120 datetime.c
--- ext/standard/datetime.c     31 Mar 2004 17:57:33 -0000      1.120
+++ ext/standard/datetime.c     24 Jun 2004 12:10:55 -0000
@@ -64,7 +64,7 @@
         {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
  };

-#define isleap(year) (((year % 4) == 0 && (year % 100) != 0) || (year % 
400)==0)
+#define isleap(year) ((((year) % 4) == 0 && ((year) % 100) != 0) || 
((year) % 400)==0)
  #define YEAR_BASE 1900

  /* {{{ proto int time(void)


> 2) idate('y') is supposed to return the year with *two*digits, althought it
> returns just 4. This can be fixed with a simple sprintf?

An integer cannot have leading zeros so the behaviour is correct. The 
documentation could be changed to reflect the fact the the integer value 
of the last two digits is returned, not the actual two digits (which 
would be a string and you should use `date()` for that).

- Chris

---

## #10820 — Nuno Lopes — 2004-06-28T14:20:29+00:00

URL: https://externals.io/message/10750#10820 · In reply to: #10755

Any news on this?
Can someone apply that patch or just add some () to the idate switch/case L
?

Thanks,
Nuno


----- Original Message ----- 
> Nuno Lopes wrote:
> > […]
but
> > […]
>
> Yes, this is indeed a bug in the isleap macro (you needed to call it
> with double parens), the fix is
>
> diff -u -r1.120 datetime.c
> --- ext/standard/datetime.c     31 Mar 2004 17:57:33 -0000      1.120
> +++ ext/standard/datetime.c     24 Jun 2004 12:10:55 -0000
> @@ -64,7 +64,7 @@
>          {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
>   };
>
> -#define isleap(year) (((year % 4) == 0 && (year % 100) != 0) || (year %
> 400)==0)
> +#define isleap(year) ((((year) % 4) == 0 && ((year) % 100) != 0) ||
> ((year) % 400)==0)
>   #define YEAR_BASE 1900
>
>   /* {{{ proto int time(void)
>
> Chris

---

## #10823 — Derick Rethans — 2004-06-28T14:35:52+00:00

URL: https://externals.io/message/10750#10823 · In reply to: #10820

> Any news on this?
> Can someone apply that patch or just add some () to the idate switch/case L
> ?

Done

---

## #10824 — Nuno Lopes — 2004-06-28T14:43:40+00:00

URL: https://externals.io/message/10750#10824 · In reply to: #10823

Thanks Derick!


> 
>
> > […]
switch/case L
> > […]
>
> Done
