this post was submitted on 16 May 2026
448 points (99.8% liked)

Technology

84700 readers
4618 users here now

This is a most excellent place for technology news and articles.


Our Rules


  1. Follow the lemmy.world rules.
  2. Only tech related news or articles.
  3. Be excellent to each other!
  4. Mod approved content bots can post up to 10 articles per day.
  5. Threads asking for personal tech support may be deleted.
  6. Politics threads may be removed.
  7. No memes allowed as posts, OK to post as comments.
  8. Only approved bots from the list below, this includes using AI responses and summaries. To ask if your bot can be added please contact a mod.
  9. Check for duplicates before posting, duplicates may be removed
  10. Accounts 7 days and younger will have their posts automatically removed.

Approved Bots


founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] yaroto98@lemmy.world 80 points 23 hours ago* (last edited 23 hours ago) (1 children)

there's a pretty simple solution IMHO. The faker python library is awesome at generating test data. Return a random dob everytime a site requests it.

import faker
faker fake
return fake.date_of_birth(minimum_age=18, maximum_age=90)
[–] artwork@lemmy.world 7 points 20 hours ago* (last edited 17 hours ago) (3 children)

A whole library, or a yet another ad for Python, sorry? Why not marvelous Perl, or any lovely PHP's or a JavaScript faker?
Why a library in the first place?

In case of PHP (checked in v8.1)

echo date('Y-m-d', rand(strtotime('-90 years'), strtotime('-18 years')));
// 2007-07-30

And, I had a snippet for JavaScript (tested in the current Chrome's EcmaScript).
We get the years in milliseconds, and substract from the current time.

console.log(new Date(Date.now() - 365*24*60*60*1000 * (18 + Math.random()*72)).toISOString().slice(0, 10));
// 1984-07-20

In shell even! Let's use the common suit GNU coreutils (e.g. v9.4).
We have 90y - 18y = 72 years, that is 26,280 days or ~26,297 days (source)

$ date -d "-18 years -$(( RANDOM % 26297 )) days" -- '+%F';
# 1976-04-06
[–] yaroto98@lemmy.world 10 points 10 hours ago* (last edited 10 hours ago) (1 children)

Mostly because it's starting with dob, what happens when they require a phone number, address, credit card, or social security number? Faker can fake all those in that library. But you're absolutely right, for one dob it is massive overkill.

Also, I'm do test automation for my career. Litterally use faker daily for generating test data. Defaulting to it is natural and familiar. Most use what they're familiar with, rarely the best solution for a task.

[–] artwork@lemmy.world 1 points 4 hours ago* (last edited 4 hours ago)

Roger that! Thank you for being a developer and improving the ineffably magnificent world! ✨

In this case, we do relatively the same, and usually in database seeding and model factories, I believe, but personally I am more into the Laravel and Symfony, where the mentioned above PHP library is used there under the hood.

Please to stay safe!

Related: https://laravel.com/docs/13.x/eloquent-factories

[–] ripcord@lemmy.world 15 points 14 hours ago (1 children)

Wtf is going on in this thread

[–] jimmy90@lemmy.world 2 points 8 hours ago

ikr

a couple of distro admins remind lawmakers that people can do what they want with their computers and it's python day on lemmy

[–] jesta@lemmy.world 26 points 17 hours ago

A whole library, or a yet another ad for Python, sorry?

This is more of a problem with how some people code more than python. I also find it irritating that some people import random libraries out of the internet to do simple things instead of actually spending the time to write two lines of code. Python has built in datetime library that could be used for this similar to the examples you gave.