The past_date function serves as a cornerstone within the mock-jutsu library for developers requiring high-quality, temporal mock data. This utility is specifically designed to produce a random date from the preceding five years, ensuring that datasets remain grounded in a realistic timeframe. By generating strings in the standard YYYY-MM-DD format, it aligns perfectly with ISO 8601 requirements, making it immediately compatible with most relational databases and modern web APIs. Whether you are populating a development database or simulating historical records, this function provides a seamless way to inject authenticity into your test environments without the overhead of manual data entry.
Under the hood, the algorithm behind past_date calculates a pseudo-random number of days between one and 1,825. This offset is then subtracted from the current system date to ensure that every execution yields a valid, non-future date. This level of automation is a significant benefit for engineers who would otherwise have to manually calculate and hardcode test data. By using mock-jutsu, teams can maintain dynamic test suites that do not age poorly or require constant manual updates as time progresses, as the "past" window shifts forward relative to the execution date.
Integration is remarkably straightforward across various environments, catering to different stages of the software development lifecycle. Python developers can invoke the utility using the jutsu.generate('past_date') syntax, while those working in terminal environments or shell scripts can leverage the CLI command mockjutsu generate past_date. Furthermore, performance testers can incorporate it directly into their load tests using the JMeter syntax ${__mockjutsu(past_date,)}. This cross-platform flexibility ensures that consistent mock data can be shared between unit tests, integration tests, and large-scale performance simulations, reducing the friction often associated with environment synchronisation.
The practical applications for past_date are extensive and vital for robust quality assurance. It is particularly useful for testing scenarios involving user account creation dates, historical transaction logs, or archival data migration. By providing varied and unpredictable dates, it helps identify edge cases such as leap year handling or date-sorting logic errors that might be missed with static data. Ultimately, this function empowers developers to build more resilient systems by providing reliable, automated, and contextually accurate test data that mimics real-world user activity over a multi-year period.
mockjutsu generate past_datemockjutsu bulk past_date --count 10mockjutsu export past_date --count 10 --format jsonmockjutsu export past_date --count 10 --format csvmockjutsu export past_date --count 10 --format sqlfrom mockjutsu import jutsujutsu.generate('past_date')jutsu.bulk('past_date', count=10)jutsu.template(['past_date'], count=5)${__mockjutsu_datetime(past_date)}# JMeter Function: __mockjutsu_datetime# Parameter 1: past_date# Parameter 2: (not required for this function)GET /generate/past_date# → {"type":"past_date","result":"...","status":"ok"}GET /bulk/past_date?count=10POST /template {"types":["past_date"],"count":1}