Duration calculates the duration of the session from message timestamps.
()
| 595 | |
| 596 | // Duration calculates the duration of the session from message timestamps. |
| 597 | func (s *Session) Duration() time.Duration { |
| 598 | messages := s.GetAllMessages() |
| 599 | if len(messages) < 2 { |
| 600 | return 0 |
| 601 | } |
| 602 | |
| 603 | first, err := time.Parse(time.RFC3339, messages[0].Message.CreatedAt) |
| 604 | if err != nil { |
| 605 | return 0 |
| 606 | } |
| 607 | |
| 608 | last, err := time.Parse(time.RFC3339, messages[len(messages)-1].Message.CreatedAt) |
| 609 | if err != nil { |
| 610 | return 0 |
| 611 | } |
| 612 | |
| 613 | return last.Sub(first) |
| 614 | } |
| 615 | |
| 616 | // AllowedDirectories returns the directories that should be considered safe for tools |
| 617 | func (s *Session) AllowedDirectories() []string { |