▲ 295 ▼ I'm new to using Ruby and this tickled me pink (europe.pub) submitted 1 year ago by sunshine@lemmy.ml to c/programmerhumor@lemmy.ml 96 comments fedilink hide all child comments
[–] Semi_Hemi_Demigod@lemmy.world 32 points 1 year ago (9 children) And the best part is the Ruby way accounts for leap years. permalink fedilink source hideshow 9 child comments replies: [–] deadbeef79000@lemmy.nz 22 points 1 year ago Well, 365 * 10 certainly doesn't ;-) permalink fedilink source parent [–] eager_eagle@lemmy.world 10 points 1 year ago (4 children) 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. permalink fedilink source parent hideshow 4 child comments replies: [–] Diplomjodler3@lemmy.world 3 points 1 year ago* (3 children) 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') permalink fedilink source parent hideshow 3 child comments replies: [–] mdhughes@lemmy.sdf.org 4 points 1 year ago (1 child) And what happens when you run that on Feb 29, 2024? permalink fedilink source parent hideshow 1 child comment replies: [–] eager_eagle@lemmy.world 2 points 1 year ago datetime raises a ValueError when trying to create an invalid date permalink fedilink source parent [–] eager_eagle@lemmy.world 3 points 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()) permalink fedilink source parent [–] pulsey@feddit.org 3 points 1 year ago (2 children) there is a simple fix to account for leap years, just add 10/4 days. /s permalink fedilink source parent hideshow 2 child comments replies: [–] Feathercrown@lemmy.world 2 points 1 year ago (1 child) Don't forget non-leap-days every 200 years! permalink fedilink source parent hideshow 1 child comment replies: [–] sexybenfranklin@ttrpg.network 4 points 1 year ago Every 100 years but not every 400 years! Isn't it fun? permalink fedilink source parent
[–] deadbeef79000@lemmy.nz 22 points 1 year ago Well, 365 * 10 certainly doesn't ;-) permalink fedilink source parent
[–] eager_eagle@lemmy.world 10 points 1 year ago (4 children) 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. permalink fedilink source parent hideshow 4 child comments replies: [–] Diplomjodler3@lemmy.world 3 points 1 year ago* (3 children) 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') permalink fedilink source parent hideshow 3 child comments replies: [–] mdhughes@lemmy.sdf.org 4 points 1 year ago (1 child) And what happens when you run that on Feb 29, 2024? permalink fedilink source parent hideshow 1 child comment replies: [–] eager_eagle@lemmy.world 2 points 1 year ago datetime raises a ValueError when trying to create an invalid date permalink fedilink source parent [–] eager_eagle@lemmy.world 3 points 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()) permalink fedilink source parent
[–] Diplomjodler3@lemmy.world 3 points 1 year ago* (3 children) 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') permalink fedilink source parent hideshow 3 child comments replies: [–] mdhughes@lemmy.sdf.org 4 points 1 year ago (1 child) And what happens when you run that on Feb 29, 2024? permalink fedilink source parent hideshow 1 child comment replies: [–] eager_eagle@lemmy.world 2 points 1 year ago datetime raises a ValueError when trying to create an invalid date permalink fedilink source parent [–] eager_eagle@lemmy.world 3 points 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()) permalink fedilink source parent
[–] mdhughes@lemmy.sdf.org 4 points 1 year ago (1 child) And what happens when you run that on Feb 29, 2024? permalink fedilink source parent hideshow 1 child comment replies: [–] eager_eagle@lemmy.world 2 points 1 year ago datetime raises a ValueError when trying to create an invalid date permalink fedilink source parent
[–] eager_eagle@lemmy.world 2 points 1 year ago datetime raises a ValueError when trying to create an invalid date permalink fedilink source parent
[–] eager_eagle@lemmy.world 3 points 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()) permalink fedilink source parent
[–] pulsey@feddit.org 3 points 1 year ago (2 children) there is a simple fix to account for leap years, just add 10/4 days. /s permalink fedilink source parent hideshow 2 child comments replies: [–] Feathercrown@lemmy.world 2 points 1 year ago (1 child) Don't forget non-leap-days every 200 years! permalink fedilink source parent hideshow 1 child comment replies: [–] sexybenfranklin@ttrpg.network 4 points 1 year ago Every 100 years but not every 400 years! Isn't it fun? permalink fedilink source parent
[–] Feathercrown@lemmy.world 2 points 1 year ago (1 child) Don't forget non-leap-days every 200 years! permalink fedilink source parent hideshow 1 child comment replies: [–] sexybenfranklin@ttrpg.network 4 points 1 year ago Every 100 years but not every 400 years! Isn't it fun? permalink fedilink source parent
[–] sexybenfranklin@ttrpg.network 4 points 1 year ago Every 100 years but not every 400 years! Isn't it fun? permalink fedilink source parent