Activity diagrams: time events

Activity diagrams: time events

puml.online

Introduction

A “time event” is one of the most frequently overlooked semantics in UML activity diagrams: a waiting activity does not wait forever, it is interrupted by a time condition and takes a different branch. An approval that auto-passes after five minutes with no human action, a cache that falls back to the origin after thirty seconds, a retry that gives up after three attempts — all of these are time events.

The catch is that neither PlantUML nor Mermaid has a timeout keyword you can write to say “fires after 5 minutes”. This article draws the same situation with the most natural mechanism each engine offers, and spells out where they differ on concurrency and on real time.

PlantUML version

PlantUML’s activity diagram (activity beta syntax) has no timeout keyword. To express “waiting for the approval result” and “waiting for a 5-minute timeout” as two parallel paths, fork / fork again is the closest thing to real UML semantics:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
@startuml
title 审批超时建模
start
:提交申请;
:等待审批结果;
fork
:人工审批;
:审批通过;
fork again
:定时器 5 分钟;
:超时自动通过;
end fork
stop
@enduml

fork opens a parallel branch, fork again adds a second one, and end fork merges them back. The two branches stand for two things running at once: a human on one side, a countdown on the other. Whichever branch reaches the merge point first decides the outcome.

If all you want to express is “interrupt the current activity on timeout”, detach is more precise — the activity flow leaves the main path here and waits for an external event (possibly a timer) before coming back:

1
2
3
4
5
6
7
8
9
@startuml
start
:等待审批结果;
note right
超时 5 分钟
end note
detach
stop
@enduml

The note right is only an annotation and does not change the structural semantics of the diagram. To make the time condition visible in the diagram itself, a split / split again branch is more accurate than a note.

Mermaid version

Mermaid has no activity diagram type, so flowchart is the closest equivalent. Draw the same situation as a flowchart, with the waiting state branching to a timeout path via a labelled edge:

1
2
3
4
flowchart TD
A[提交申请] --> B[等待审批结果]
B -->|人工审批| C[审批通过]
B -->|超时 5 分钟| D[超时自动通过]

The |超时 5 分钟| on the edge is Mermaid’s most natural way to express a time condition: the condition lives on the edge and the nodes stay clean. The cost is that this chart has no concurrency semantics — the two edges read like “choose one of these in sequence” rather than “wait on both at once”.

When the time relationship is itself the subject (rather than a condition on one branch), gantt is the right tool in Mermaid, because it has a real timeline and milestones:

1
2
3
4
5
6
gantt
title 审批 SLA
dateFormat YYYY-MM-DD
section 审批
等待审批 :active, a1, 2026-11-28, 5d
超时触发 :milestone, t1, 2026-11-30, 0d

milestone marks a point on the timeline (the moment the timeout fires) and active marks a task as in progress. Note that gantt requires section grouping and that task rows use the task name : status, id, start, end form.

Side-by-side

Aspect PlantUML Mermaid
Diagram type Native activity diagram (activity beta) No activity diagram; approximated with flowchart
Parallel branches fork / fork again / end fork No parallel syntax; only visual implication via edges
Time condition Branch structure plus a note annotation Written on the edge: `B –>
Interrupting a wait detach (waits for an external event) No keyword; use a dotted -.-> edge for a weak relation
Real timeline None (you do the arithmetic) gantt natively supports timelines and milestone

Wrap-up

The two engines are almost opposites here: PlantUML has the UML activity structure (parallelism, interruption, merge) but no time primitive, while Mermaid has a genuine timeline (gantt) but no activity structure. The most practical combination is usually to draw the structure in PlantUML (fork to show “the human and the clock are both waiting”), express the condition in Mermaid with a labelled edge on a flowchart, and switch to gantt only when a real calendar view is what you actually need.

  • Title: Activity diagrams: time events
  • Author: puml.online
  • Created at : 2026-11-28 16:13:00
  • Updated at : 2026-12-05 02:08:58
  • Link: https://puml.online/blog/activity-diagram-time-event-en/
  • License: This work is licensed under CC BY-NC-SA 4.0.
On this page
Activity diagrams: time events