summaryrefslogtreecommitdiff
path: root/epg_events.cpp
blob: 2619b46ce119e7810614c6e4619c5acc27e90d98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <time.h>

#include "tools.h"

#include "epg_events.h"

namespace vdrlive
{
	EpgEvent::EpgEvent(const std::string& id,
					   const std::string& caption,
					   const std::string& title,
					   const std::string& short_descr,
					   const std::string& long_descr,
					   time_t start_time,
					   time_t end_time) :
		m_eventId(id),
		m_caption(caption),
		m_title(title),
		m_short_descr(short_descr),
		m_long_descr(long_descr),
		m_start_time(start_time),
		m_end_time(end_time)
	{
	}

	EpgEvent::EpgEvent(const std::string& id, const cEvent* event, const char* channelName) :
		m_eventId(id),
		m_caption(channelName),
		m_title(event->Title() ? event->Title() : ""),
		m_short_descr(event->ShortText() ? event->ShortText() : ""),
		m_long_descr(event->Description() ? event->Description() : ""),
		m_start_time(event->StartTime()),
		m_end_time(event->EndTime())
	{
	}

	EpgEvent::~EpgEvent()
	{
	}

	const std::string EpgEvent::StartTime(const char* format) const
	{
		return FormatDateTime(format, m_start_time);
	}

	const std::string EpgEvent::EndTime(const char* format) const
	{
		return FormatDateTime(format, m_end_time);
	}

	const std::string EpgEvent::CurrentTime(const char* format) const
	{
		return FormatDateTime(format, time(0));
	}

	int EpgEvent::Elapsed() const
	{
		if (m_end_time > m_start_time) {
			time_t now = time(0);
			if ((m_start_time <= now) && (now <= m_end_time)) {
				return 100 * (now - m_start_time) / (m_end_time - m_start_time);
			}
		}
		return -1;
	}

	EpgEvents::EpgEvents() :
		std::vector<EpgEventPtr>()
	{
	}

	EpgEvents::~EpgEvents()
	{
	}
#ifdef never
	EpgEventsPtr EpgEvents::dim(size_t count)
	{
		EpgEventsPtr ePtr(new EpgEvents(count));
		return ePtr;
	}
#endif
}; // namespace vdrlive