FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Error en ISLEAP()?, SOLUCIONADO
Posts: 3358
Joined: Fri Oct 07, 2005 08:20 PM
Error en ISLEAP()?, SOLUCIONADO
Posted: Wed Jul 03, 2024 04:55 PM

Amigos del foro:

Estoy probando la función IsLeap() para determinar si el año dado es bisiesto

? IsLeap(2024) => .T.

? IsLeap(2025) => .T.

? IsLeap(2026) => .T.

2024 sí es bisiesto pero 2025 y 2026 No.

Que estoy haciendo mal?

Saludos

Fue mi error, debemos pasar la fecha completa y yo estoy pasando solo el año

Mil disculpas

SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
Posts: 26
Joined: Thu Mar 17, 2022 06:47 PM
Re: Error en ISLEAP()?, SOLUCIONADO
Posted: Wed Jul 03, 2024 05:23 PM

IsLeap()

Checks if a Date value belongs to a leap year.

Syntax

IsLeap( [<dDate>] ) --> lIsLeapYear

Arguments

<dDate>

Any Date value, except for an empty date, can be passed. The default is the return value of Date(). Return

The function returns .F. (true), when <dDate> falls into a leap year, otherwise .F. (false) is returned.

Posts: 318
Joined: Fri Jan 14, 2022 08:37 AM
Re: Error en ISLEAP()?, SOLUCIONADO
Posted: Wed Jul 03, 2024 05:44 PM
Code (fw): Select all Collapse
#Define lYEAR_BISIESTO(nYear) ( Mod(nYear, 4) == 0 )
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Error en ISLEAP()?, SOLUCIONADO
Posted: Wed Jul 03, 2024 07:17 PM
paquitohm wrote:
Code (fw): Select all Collapse
#Define lYEAR_BISIESTO(nYear) ( Mod(nYear, 4) == 0 )
It is not correct.
Posts: 318
Joined: Fri Jan 14, 2022 08:37 AM
Re: Error en ISLEAP()?, SOLUCIONADO
Posted: Thu Jul 04, 2024 07:27 AM
Enrico Maria Giordano wrote:
Code (fw): Select all Collapse
#Define lYEAR_BISIESTO(nYear) ( Mod(nYear, 4) == 0 )
It is not correct.
Ok ! Sorry, my error !!!

From ChatGPT:
Code (fw): Select all Collapse
FUNCTION EsBisiesto(nAno)
    // Comprueba si el año es divisible por 4
    IF (nAno % 4 == 0)
        // Si es divisible por 4, comprueba si también es divisible por 100
        IF (nAno % 100 == 0)
            // Si es divisible por 100, debe ser también divisible por 400 para ser bisiesto
            IF (nAno % 400 == 0)
                RETURN .T.  // Es bisiesto
            ELSE
                RETURN .F.  // No es bisiesto
            ENDIF
        ELSE
            RETURN .T.  // Es bisiesto
        ENDIF
    ELSE
        RETURN .F.  // No es bisiesto
    ENDIF
RETURN .F.  // Por defecto, no es bisiesto (aunque esta línea nunca se alcanzará)
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Error en ISLEAP()?, SOLUCIONADO
Posted: Thu Jul 04, 2024 07:44 AM
paquitohm wrote:
Code (fw): Select all Collapse
#Define lYEAR_BISIESTO(nYear) ( Mod(nYear, 4) == 0 )
It is not correct.
Ok ! Sorry, my error !!!

From ChatGPT:
Code (fw): Select all Collapse
FUNCTION EsBisiesto(nAno)
    // Comprueba si el año es divisible por 4
    IF (nAno % 4 == 0)
        // Si es divisible por 4, comprueba si también es divisible por 100
        IF (nAno % 100 == 0)
            // Si es divisible por 100, debe ser también divisible por 400 para ser bisiesto
            IF (nAno % 400 == 0)
                RETURN .T.  // Es bisiesto
            ELSE
                RETURN .F.  // No es bisiesto
            ENDIF
        ELSE
            RETURN .T.  // Es bisiesto
        ENDIF
    ELSE
        RETURN .F.  // No es bisiesto
    ENDIF
RETURN .F.  // Por defecto, no es bisiesto (aunque esta línea nunca se alcanzará)
Why such long code with so many lines?
Code (fw): Select all Collapse
function IsLeapYear( nYear ); return ( nYear % 4 ) == 0 .and. ( nYear % 100 ) != 0
Regards



G. N. Rao.

Hyderabad, India
Posts: 318
Joined: Fri Jan 14, 2022 08:37 AM
Re: Error en ISLEAP()?, SOLUCIONADO
Posted: Thu Jul 04, 2024 02:48 PM
Why such long code with so many lines?
Code (fw): Select all Collapse
function IsLeapYear( nYear ); return ( nYear % 4 ) == 0 .and. ( nYear % 100 ) != 0

IMHO, It is not correct.
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Error en ISLEAP()?, SOLUCIONADO
Posted: Thu Jul 04, 2024 02:56 PM

Why not using the function ISLEAP() that Harbour and xHarbour already provide?

Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Error en ISLEAP()?, SOLUCIONADO
Posted: Thu Jul 04, 2024 03:11 PM
Enrico Maria Giordano wrote:Why not using the function ISLEAP() that Harbour and xHarbour already provide?
Code (fw): Select all Collapse
// C:\FHW\SAMPLES\SLEEPARM.PRG

#include "FiveWin.ch"

FUNCTION Main()

   SET CENTURY ON
   SET DATE BRITISH
   SET EPOCH TO YEAR( DATE() ) - 30

   ? Date(), IsLeap()

   ? AddMonth( 12 ),  IsLeap( AddMonth(  12 ) )

   ? AddMonth( -12 ), IsLeap( AddMonth( -12 ) )

RETURN NIL

// FIN / END
Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 3358
Joined: Fri Oct 07, 2005 08:20 PM
Re: Error en ISLEAP()?, SOLUCIONADO
Posted: Thu Jul 04, 2024 04:15 PM
Friends:
Amigos:

This is my IsLeap function.
Esta es mi función IsLeap
Code (fw): Select all Collapse
FUNCTION IsLeap(nAmo)
RETURN( ((nAmo % 4) == 0 .AND.;
    (nAmo % 100) <> 0) .OR.;
    ((nAmo % 400) == 0) )
As you can see, in my function I only require the year while in Harbor's function
it requires the full date, that created confusion for me in my first post

Como pueden ver, solo requiero el año mientras que IsLeap de Harbour requiere
la fecha completa, eso me creó la confusión de mi primer post, estaba usando la función de Harbour.

With many greetings
SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero

Continue the discussion