2 * Copyright (c) 2010-2022 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.velbus.internal.packets;
15 import static org.openhab.binding.velbus.internal.VelbusBindingConstants.COMMAND_SET_REALTIME_DATE;
17 import java.time.ZonedDateTime;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
22 * The {@link VelbusSetDatePacket} represents a Velbus packet that can be used to
23 * set the date of the given Velbus module.
25 * @author Cedric Boon - Initial contribution
28 public class VelbusSetDatePacket extends VelbusPacket {
29 private ZonedDateTime zonedDateTime;
31 public VelbusSetDatePacket(byte address, ZonedDateTime zonedDateTime) {
32 super(address, PRIO_LOW);
34 this.zonedDateTime = zonedDateTime;
37 public byte getDay() {
38 return (byte) this.zonedDateTime.getDayOfMonth();
41 public byte getMonth() {
42 return (byte) this.zonedDateTime.getMonthValue();
45 public byte getYearHighByte() {
46 return (byte) ((zonedDateTime.getYear() & 0xff00) / 0x100);
49 public byte getYearLowByte() {
50 return (byte) (zonedDateTime.getYear() & 0xff);
54 protected byte[] getDataBytes() {
55 return new byte[] { COMMAND_SET_REALTIME_DATE, getDay(), getMonth(), getYearHighByte(), getYearLowByte() };