Scam-Lemmy.me
  • Communities
  • Create Post
  • Create Community
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
sunshine@lemmy.ml to Programmer Humor@lemmy.mlEnglish · 1 年前

I'm new to using Ruby and this tickled me pink

lemmy.ml

message-square
96
fedilink
295

I'm new to using Ruby and this tickled me pink

lemmy.ml

sunshine@lemmy.ml to Programmer Humor@lemmy.mlEnglish · 1 年前
message-square
96
fedilink
  • Boomer Humor Doomergod@lemmy.world
    link
    fedilink
    English
    arrow-up
    32
    ·
    1 年前

    And the best part is the Ruby way accounts for leap years.

    • deadbeef79000@lemmy.nz
      link
      fedilink
      arrow-up
      22
      ·
      1 年前

      Well, 365 * 10 certainly doesn’t ;-)

    • Eager Eagle@lemmy.world
      link
      fedilink
      English
      arrow-up
      12
      arrow-down
      2
      ·
      1 年前

      I prefer the one on the left because it’s evident it doesn’t account for leap days, while I’d be questioning whether the one on the right does.

      • Diplomjodler@lemmy.world
        link
        fedilink
        arrow-up
        5
        arrow-down
        1
        ·
        edit-2
        1 年前

        I’ll give it a shot. Looks a bit kludgy and I’ve been typing this on my phone while sitting on the toilet. What am I doing with my life?

        from datetime import datetime 
        
        now = datetime.now()
        year = now.strftime('%Y')
        month = now.strftime('%m')
        day = now.strftime('%d')
        tenyearsago = datetime(year-10, month, day)
        print(tenyearsago.strftime('%d.%m.%Y')
        
        • Digital Mark@lemmy.sdf.org
          link
          fedilink
          English
          arrow-up
          4
          ·
          1 年前

          And what happens when you run that on Feb 29, 2024?

          • Eager Eagle@lemmy.world
            link
            fedilink
            English
            arrow-up
            2
            ·
            1 年前

            datetime raises a ValueError when trying to create an invalid date

        • Eager Eagle@lemmy.world
          link
          fedilink
          English
          arrow-up
          3
          ·
          1 年前

          or just this

          from datetime import datetime
          
          today = datetime.today()
          ten_years_ago = today.replace(year=today.year - 10)
          print("Date 10 years ago:", ten_years_ago.date())
          
    • pulsey@feddit.org
      link
      fedilink
      arrow-up
      3
      ·
      1 年前

      there is a simple fix to account for leap years, just add 10/4 days. /s

      • Feathercrown@lemmy.world
        link
        fedilink
        English
        arrow-up
        2
        ·
        1 年前

        Don’t forget non-leap-days every 200 years!

        • sexybenfranklin@ttrpg.network
          link
          fedilink
          English
          arrow-up
          4
          ·
          1 年前

          Every 100 years but not every 400 years! Isn’t it fun?

Programmer Humor@lemmy.ml

programmerhumor@lemmy.ml

Subscribe from Remote Instance

Create a post
You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: [email protected]

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

  • Posts must be relevant to programming, programmers, or computer science.
  • No NSFW content.
  • Jokes must be in good taste. No hate speech, bigotry, etc.
Visibility: Public
globe

This community can be federated to other instances and be posted/commented in by their users.

  • 19 users / day
  • 76 users / week
  • 1.62K users / month
  • 4.15K users / 6 months
  • 2 local subscribers
  • 44.2K subscribers
  • 1.51K Posts
  • 17.5K Comments
  • Modlog
  • mods:
  • cat_programmer@lemmy.ml
  • BE: 0.19.9
  • Modlog
  • Instances
  • Docs
  • Code
  • join-lemmy.org