ProIT
  • Communities
  • Create Post
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
sunshine@lemmy.ml to Programmer Humor@lemmy.mlEnglish · 1 year ago

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

lemmy.ml

message-square
95
link
fedilink
  • cross-posted to:
  • [email protected]
290

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

lemmy.ml

sunshine@lemmy.ml to Programmer Humor@lemmy.mlEnglish · 1 year ago
message-square
95
link
fedilink
  • cross-posted to:
  • [email protected]
  • Boomer Humor Doomergod@lemmy.world
    link
    fedilink
    English
    arrow-up
    32
    ·
    1 year ago

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

    • deadbeef79000@lemmy.nz
      link
      fedilink
      arrow-up
      22
      ·
      1 year ago

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

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

      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
        4
        ·
        1 year ago

        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 year ago

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

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

            datetime raises a ValueError when trying to create an invalid date

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

          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 year ago

      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 year ago

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

        • sexybenfranklin@ttrpg.network
          link
          fedilink
          English
          arrow-up
          4
          ·
          1 year ago

          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.

  • 81 users / day
  • 557 users / week
  • 2 users / month
  • 544 users / 6 months
  • 1 local subscriber
  • 38.2K subscribers
  • 1.85K Posts
  • 39.9K Comments
  • Modlog
  • mods:
  • AgreeableLandscape@lemmy.ml
  • cat_programmer@lemmy.ml
  • BE: 0.19.15
  • Modlog
  • Instances
  • Docs
  • Code
  • join-lemmy.org