Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3304332
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:03:02+00:00 2026-05-17T21:03:02+00:00

I know this is a bad idea, but I have lots of legacy code

  • 0

I know this is a bad idea, but I have lots of legacy code and I want to run through some historical batch jobs. I dont want to change the systems date because other stuff runs on the same system. Is there any way that I can change the value that Date.today will return for the life of a given process only. The idea here is to rewind and run some older batch scripts that were used to work off of Date.today.

thanks
Joel

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T21:03:03+00:00Added an answer on May 17, 2026 at 9:03 pm

    You can either monkey-patch Ruby like Nikolaus showed you, or can use the TimeCop gem. It was designed to make writing tests easier, but you can use it in your normal code as well.

    # Set the time where you want to go.
    t = Time.local(2008, 9, 1, 10, 5, 0)
    
    Timecop.freeze(t) do
       # Back to the future!
    end
    # And you're back!
    
    # You can also travel (e.g. time continues to go by)
    Timecop.travel(t)
    

    It’s a great, but simple piece of code. Give it a try, it’ll save you some headaches when monkeypatching Date and Time yourself.

    Link: https://rubygems.org/gems/timecop

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a Bad Idea, I know, but... I want to configure log4net programmatically
I know that what I'm trying to do is bad idea, but I have
So I want to know if this is a good idea or a bad
I know it's a bad idea but I need to do this. I'm about
Well I know obfuscation is a bad idea. But I want all of my
I know this might sounds not reasonable, and might be a bad design. But
I know I'm doing this a bad way... but I'm having trouble seeing any
I know this is an old question, but I have spend any hours on
I know this is bad practice. Don't write code like this if at all
I know this may be a silly question. but stil i have a confusion.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.