2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.xmltv.internal.jaxb;
15 import java.time.Instant;
16 import java.time.ZonedDateTime;
17 import java.time.format.DateTimeFormatter;
18 import java.util.ArrayList;
19 import java.util.List;
21 import javax.xml.bind.annotation.XmlAccessType;
22 import javax.xml.bind.annotation.XmlAccessorType;
23 import javax.xml.bind.annotation.XmlAttribute;
24 import javax.xml.bind.annotation.XmlElement;
25 import javax.xml.bind.annotation.XmlType;
26 import javax.xml.bind.annotation.adapters.CollapsedStringAdapter;
27 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
29 import org.eclipse.jdt.annotation.NonNullByDefault;
32 * Java class for a programme XML element
34 * @author Gaƫl L'hopital - Initial contribution
36 @XmlAccessorType(XmlAccessType.FIELD)
39 public class Programme {
40 private static final DateTimeFormatter XMLTV_DATE_FORMAT = DateTimeFormatter.ofPattern("yyyyMMddHHmmss Z");
42 @XmlElement(name = "title", required = true)
43 protected List<WithLangType> titles = new ArrayList<>();
45 @XmlElement(name = "category")
46 protected List<WithLangType> categories = new ArrayList<>();
48 @XmlElement(name = "icon")
49 protected List<Icon> icons = new ArrayList<>();
51 @XmlAttribute(required = true)
52 private String start = "";
55 private String stop = "";
57 @XmlAttribute(required = true)
58 @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
59 protected String channel = "";
61 public List<WithLangType> getTitles() {
65 public List<WithLangType> getCategories() {
69 public Instant getProgrammeStart() {
70 long epoch = iso860DateToEpoch(start);
71 return Instant.ofEpochMilli(epoch);
74 public Instant getProgrammeStop() {
75 long epoch = iso860DateToEpoch(stop);
76 return Instant.ofEpochMilli(epoch);
79 private long iso860DateToEpoch(String date) {
80 long epoch = ZonedDateTime.parse(date, XMLTV_DATE_FORMAT).toInstant().toEpochMilli();
84 public List<Icon> getIcons() {
88 public String getChannel() {