Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Birthday module give database error when member/contact is born on 29 february #1535

Open
johnsonbrothers opened this issue Dec 14, 2023 · 0 comments

Comments

@johnsonbrothers
Copy link

Describe the bug

I have a member born on february 29 1964. This gives the following error in my postgres log.

2023-12-14 13:54:46.594 UTC [3554] ERROR: date/time field value out of range: "2023-02-29"
2023-12-14 13:54:46.594 UTC [3554] STATEMENT: SELECT DISTINCT usr_id, usr_uuid, usr_login_name,
last_name.usd_value AS last_name, first_name.usd_value AS first_name,
birthday.bday AS birthday, birthday.bdate,
EXTRACT(DAY FROM TO_TIMESTAMP($1, 'YYYY-MM-DD') - birthday.bdate) * (-1) AS days_to_bdate, -- DATE_NOW
EXTRACT(YEAR FROM bdate) - EXTRACT(YEAR FROM TO_TIMESTAMP(bday, 'YYYY-MM-DD')) AS age,
email.usd_value AS email, gender.usd_value AS gender
FROM adm_users AS users
INNER JOIN ( (SELECT usd_usr_id, usd_value AS bday,
TO_DATE(EXTRACT(YEAR FROM TO_TIMESTAMP($2, 'YYYY-MM-DD')) || TO_CHAR(TO_TIMESTAMP(bd1.usd_value, 'YYYY-MM-DD'), '-MM-DD'), 'YYYY-MM-DD') AS bdate -- DATE_NOW
FROM adm_user_data AS bd1
WHERE EXTRACT(DAY FROM TO_TIMESTAMP($3, 'YYYY-MM-DD') - TO_TIMESTAMP(EXTRACT(YEAR FROM TO_TIMESTAMP($4, 'YYYY-MM-DD')) || TO_CHAR(TO_TIMESTAMP(bd1.usd_value, 'YYYY-MM-DD'), '-MM-DD'), 'YYYY-MM-DD')) -- DATE_NOW,DATE_NOW
BETWEEN $5 AND $6 -- -$plg_show_zeitraum AND $plg_show_future
AND usd_usf_id = $7) -- $fieldBirthday
UNION
(SELECT usd_usr_id, usd_value AS bday,
TO_DATE(EXTRACT(YEAR FROM TO_TIMESTAMP($8, 'YYYY-MM-DD'))-1 || TO_CHAR(TO_TIMESTAMP(bd2.usd_value, 'YYYY-MM-DD'), '-MM-DD'), 'YYYY-MM-DD') AS bdate -- DATE_NOW
FROM adm_user_data AS bd2
WHERE EXTRACT(DAY FROM TO_TIMESTAMP($9, 'YYYY-MM-DD') - TO_TIMESTAMP(EXTRACT(YEAR FROM TO_TIMESTAMP($10, 'YYYY-MM-DD')- INTERVAL '1 year') || TO_CHAR(TO_TIMESTAMP(bd2.usd_value, 'YYYY-MM-DD'), '-MM-DD'), 'YYYY-MM-DD')) -- DATE_NOW,DATE_NOW
BETWEEN $11 AND $12 -- -$plg_show_zeitraum AND $plg_show_future
AND usd_usf_id = $13) -- $fieldBirthday
UNION
(SELECT usd_usr_id, usd_value AS bday,
TO_DATE(EXTRACT(YEAR FROM TO_TIMESTAMP($14, 'YYYY-MM-DD'))+1 || TO_CHAR(TO_TIMESTAMP(bd3.usd_value, 'YYYY-MM-DD'), '-MM-DD'), 'YYYY-MM-DD') AS bdate -- DATE_NOW
FROM adm_user_data AS bd3
WHERE EXTRACT(DAY FROM TO_TIMESTAMP($15, 'YYYY-MM-DD') - TO_TIMESTAMP(EXTRACT(YEAR FROM TO_TIMESTAMP($16, 'YYYY-MM-DD')+ INTERVAL '1 year') || TO_CHAR(TO_TIMESTAMP(bd3.usd_value, 'YYYY-MM-DD'), '-MM-DD'), 'YYYY-MM-DD')) -- DATE_NOW,DATE_NOW
BETWEEN $17 AND $18 -- -$plg_show_zeitraum AND $plg_show_future
AND usd_usf_id = $19) -- $fieldBirthday
) AS birthday
ON birthday.usd_usr_id = usr_id
LEFT JOIN adm_user_data AS last_name
ON last_name.usd_usr_id = usr_id
AND last_name.usd_usf_id = $20 -- $gProfileFields->getProperty('LAST_NAME', 'usf_id')
LEFT JOIN adm_user_data AS first_name
ON first_name.usd_usr_id = usr_id
AND first_name.usd_usf_id = $21 -- $gProfileFields->getProperty('FIRST_NAME', 'usf_id')
LEFT JOIN adm_user_data AS email
ON email.usd_usr_id = usr_id
AND email.usd_usf_id = $22 -- $gProfileFields->getProperty('EMAIL', 'usf_id')
LEFT JOIN adm_user_data AS gender
ON gender.usd_usr_id = usr_id
AND gender.usd_usf_id = $23 -- $gProfileFields->getProperty('GENDER', 'usf_id')
LEFT JOIN adm_members
ON mem_usr_id = usr_id
AND mem_begin <= $24 -- DATE_NOW
AND mem_end > $25 -- DATE_NOW
INNER JOIN adm_roles
ON mem_rol_id = rol_id
AND rol_valid = true
INNER JOIN adm_categories
ON rol_cat_id = cat_id
AND cat_org_id = $26 -- $gCurrentOrgId
WHERE usr_valid = true
AND mem_rol_id IS NOT NULL
ORDER BY days_to_bdate DESC, last_name, first_name

I can imagine this happens somewhere if the birthday date is not handled with database-functions when a year is added or substracted. The year today is no leap year and the 29 of february 2023 don't exist.

To Reproduce
Steps to reproduce the behavior:

  1. Go to Members
  2. Click on a member and change birthday to 29 february a leap year.
  3. save
  4. click on another member and change birthday to any year and current month and day
  5. go to overview and check birthday module
  6. no birthdays is shown

Expected behavior
You should see the member that you changed birthday to this month and day

System (please complete the following information):

  • Admidio-Version Container with tag 4.2.14
  • PHP n/a - in Container
  • Database PostgreSQL
  • Browser firefox
  • Browser-Version 120.0.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants