Announcement

Collapse
No announcement yet.

ISO weeknumber - still up-to-date?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Egbert Zijlema
    replied
    Edwin,

    I'm not sure what you mean. My function "WeekNumber" does not force a specific vartype. If a negative value (-1) is passed through its optional param, the function returns a weeknumber based upon the following ISO rules:
    • Monday is supposed to be the first day of the week
    • Week #1 is the week that contains the first Thursday of the year


    Also read: http://zijlema.basicguru.eu/wrongweek.html

    Leave a comment:


  • Edwin Knoppert
    replied
    Thanks.
    Will you ever take care of the values used during calculation?
    I personally had trouble by not explictly force a specific vartype.
    I now always do.

    Part 365.25 for example, i know some programmers lift along with a behaviour of the compiler and in some cases the fraction may result in specific (rounded) values.

    Leave a comment:


  • Egbert Zijlema
    replied
    Edwin,

    If I were you I wouldn't use that old Julian routine, but the Gregorian Date Library: http://zijlema.basicguru.eu/files/gregorian.zip. In its week number function you can force a correct ISO week number.
    Good luck.

    Leave a comment:


  • Scott Slater
    replied
    LONGs can be changed to DWORDs where no negative values are used, and this will double the max upper value of that parameter.

    I have not looked at the code so I do not know if this is the case or not, but would venture to guess that no negative values would be used.

    Leave a comment:


  • Bern Ertl
    replied
    I don't think that changing yearsBC and yearsAD to DOUBLEs will affect the calculation of that expression if they are always holding LONG values.

    I'm guessing PB is interpreting the numeric literal is as a SINGLE by default and converting the value of the sum to same. Adding the # specifier to force the literal to a DOUBLE should force PB to convert the sum to same and maintain the extra precision it offers through the multiplication.

    Operator precedence with MOD always confuses me too, so I prefer to add explicit parenthesis when using it as you have shown. MOD is calculated before addition (and I doubt that PB has ever changed operator precedence as it would likely break legacy code), so it is calculated:

    FUNCTION = (JDN MOD 7) + 1

    Leave a comment:


  • Edwin Knoppert
    started a topic ISO weeknumber - still up-to-date?

    ISO weeknumber - still up-to-date?

    I am using this code:
    http://www.powerbasic.com/support/fo...ML/001585.html

    I know Egbert is very serious about dates however, a calculation like this:
    INT((yearsBC + yearsAD) * 365.25)

    may be very cpu and programming depending.

    Imo at least vars like: yearsBC AS LONG, yearsAD AS LONG should be double.
    And 365.25 should be tagged as double like:

    Local yearsBC AS Double, yearsAD AS Double

    INT((yearsBC + yearsAD) * 365.25#)

    Not sure if this is ok: FUNCTION = JDN MOD 7 + 1

    FUNCTION = (JDN MOD 7) + 1
    Or:
    FUNCTION = (JDN MOD (7 + 1))

    Opinions?
Working...
X