Gantt diagram - how to start a project a number of days before today?

0 votes
asked Jul 18, 2022 in Question / help by bob
I would like a Gantt diagram always start certain time before today, for example "project starts two weeks before today". That does not work though, it throws an error. How do I go about this please? Thank you.

1 Answer

+1 vote
answered Jul 21, 2022 by plantuml (295,800 points)
edited Jul 21, 2022 by plantuml

We'd like to know a little more about the context (so why do you need this).

If you generate your diagram daily, you will have a different diagram (since "today" is changing daily :-)

It this correct?

It's not exactly your request, but right now you can have:

@startgantt
!$today = %date("YYYY-MM-dd")
Project starts $today
[foo] lasts 10 days
@endgantt

We should probably add some preprocessor function to handle date/time manipulation.

commented Jul 21, 2022 by bob
Thank you for your reply. I have today highlighted in the chart and a task/number of tasks that actually indicate for example how long I keep books from a public library and the end of the task means when I need to return/renew them. The chart is generated daily. As days go by, the whole chart gets ever longer as it has begun on a certain date. However, I do not need to see the whole past to the beginning of the entire book lending period, one/two weeks suffice and the chart image width does not need to grow indefinitely.

So if I could somehow automatically calculate the project start day (perhaps something like "project starts on (%date - 14 days)" that would fulfill the need.

A simplest example for guarding book borrowing periods (but it can/does serve for more advanced uses as well):

@startgantt

footer %filename()

title Books

saturday are closed

sunday are closed

Project starts 2022-07-18

'does not work: Project starts %date("yyyy-MM-dd") - 3 days

'does not work: Project starts 3 days before today

[Books from Local Public Library] starts 2022-07-31 and ends 2022-08-21

[Books from Campus Library] starts 2022-07-21 and ends 2022-08-11

today is colored in lightseagreen

@endgantt

Thank you for any guidance.
commented Jul 21, 2022 by plantuml (295,800 points)

Thank you for your reply. I have today highlighted in the chart and a task/number of tasks that actually indicate for example how long I keep books from a public library and the end of the task means when I need to return/renew them

This is an unexpected use but definitively a very clever idea :-)

So in last snapshot, we have added a new %now() function which returns the epoch time and %date() is now accepting a second optional argument. So you can use the preprocessor this way:

@startgantt
!$now = %now()
!$past = %date("YYYY-MM-dd", $now - 14*24*3600)
Project starts $past
[foo] lasts 10 days
@endgantt

I think you can now accomplish your goal. Tell us if it works for you!

Do not hesitate to request odd features: I'm sure it will be useful for other users.

commented Jul 21, 2022 by bob
Thank you for your prompt assistance. It exactly solves the need. This feature can be useful for a range of other timeline related uses, such as tracking medicine/other stocks, personal documents/bank cards validity, travel/accommodation schedules, legal limitation periods etc., using appropriate time scales of course. Thanks once again.
...