/*
 * Copyright (C) 2023-2024 Birb Developers
 *
 * Birb is the legal property of its developers, whose names are too
 * numerous to list here. Please refer to the AUTHORS file distributed
 * with this source distribution
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <https://www.gnu.org/licenses/>.
 */

#include "birbdatetime.h"

/******************************************************************************
 * Public API
 *****************************************************************************/
gboolean
birb_date_time_set(GDateTime **datetime_ptr, GDateTime *new_datetime) {
	GDateTime *old = NULL;

	g_return_val_if_fail(datetime_ptr != NULL, FALSE);

	old = *datetime_ptr;

	if(old == new_datetime) {
		return FALSE;
	}

	if(old != NULL) {
		g_date_time_unref(old);
	}

	if(new_datetime != NULL) {
		*datetime_ptr = g_date_time_ref(new_datetime);
	} else {
		*datetime_ptr = NULL;
	}

	return TRUE;
}

void
birb_date_time_clear(GDateTime **datetime_ptr) {
	if(datetime_ptr == NULL || *datetime_ptr == NULL) {
		return;
	}

	g_date_time_unref(*datetime_ptr);
	*datetime_ptr = NULL;
}
