All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.gnome.glib.DateTime Maven / Gradle / Ivy

// Java-GI - Java language bindings for GObject-Introspection-based libraries
// Copyright (C) 2022-2024 Jan-Willem Harmannij
//
// SPDX-License-Identifier: LGPL-2.1-or-later
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, see .
//
// This file has been generated with Java-GI.
// Do not edit this file directly!
// Visit  for more information.
//
package org.gnome.glib;

import io.github.jwharm.javagi.base.ManagedInstance;
import io.github.jwharm.javagi.base.Out;
import io.github.jwharm.javagi.interop.Interop;
import io.github.jwharm.javagi.interop.MemoryCleaner;
import java.lang.Deprecated;
import java.lang.Integer;
import java.lang.String;
import java.lang.foreign.Arena;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.ValueLayout;
import javax.annotation.processing.Generated;
import org.jetbrains.annotations.Nullable;

/**
 * An opaque structure that represents a date and time, including a time zone.
 * @version 2.26
 */
@Generated("io.github.jwharm.JavaGI")
public class DateTime extends ManagedInstance {
    static {
        GLib.javagi$ensureInitialized();
    }

    /**
     * Create a DateTime proxy instance for the provided memory address.
     *
     * @param address the memory address of the native object
     */
    public DateTime(MemorySegment address) {
        super(address);
    }

    /**
     * Creates a new {@code GDateTime} corresponding to the given date and time in
     * the time zone {@code tz}.
     * 

* The {@code year} must be between 1 and 9999, {@code month} between 1 and 12 and {@code day} * between 1 and 28, 29, 30 or 31 depending on the month and the year. *

* {@code hour} must be between 0 and 23 and {@code minute} must be between 0 and 59. *

* {@code seconds} must be at least 0.0 and must be strictly less than 60.0. * It will be rounded down to the nearest microsecond. *

* If the given time is not representable in the given time zone (for * example, 02:30 on March 14th 2010 in Toronto, due to daylight savings * time) then the time will be rounded up to the nearest existing time * (in this case, 03:00). If this matters to you then you should verify * the return value for containing the same as the numbers you gave. *

* In the case that the given time is ambiguous in the given time zone * (for example, 01:30 on November 7th 2010 in Toronto, due to daylight * savings time) then the time falling within standard (ie: * non-daylight) time is taken. *

* It not considered a programmer error for the values to this function * to be out of range, but in the case that they are, the function will * return {@code null}. *

* You should release the return value by calling g_date_time_unref() * when you are done with it. * @param tz a {@code GTimeZone} * @param year the year component of the date * @param month the month component of the date * @param day the day component of the date * @param hour the hour component of the date * @param minute the minute component of the date * @param seconds the number of seconds past the minute */ public DateTime(TimeZone tz, int year, int month, int day, int hour, int minute, double seconds) { super(constructNew(tz, year, month, day, hour, minute, seconds)); } /** * Get the GType of the DateTime class * * @return the GType */ public static Type getType() { return Interop.getType("g_date_time_get_type"); } /** * Creates a new {@code GDateTime} corresponding to the given date and time in * the time zone {@code tz}. *

* The {@code year} must be between 1 and 9999, {@code month} between 1 and 12 and {@code day} * between 1 and 28, 29, 30 or 31 depending on the month and the year. *

* {@code hour} must be between 0 and 23 and {@code minute} must be between 0 and 59. *

* {@code seconds} must be at least 0.0 and must be strictly less than 60.0. * It will be rounded down to the nearest microsecond. *

* If the given time is not representable in the given time zone (for * example, 02:30 on March 14th 2010 in Toronto, due to daylight savings * time) then the time will be rounded up to the nearest existing time * (in this case, 03:00). If this matters to you then you should verify * the return value for containing the same as the numbers you gave. *

* In the case that the given time is ambiguous in the given time zone * (for example, 01:30 on November 7th 2010 in Toronto, due to daylight * savings time) then the time falling within standard (ie: * non-daylight) time is taken. *

* It not considered a programmer error for the values to this function * to be out of range, but in the case that they are, the function will * return {@code null}. *

* You should release the return value by calling g_date_time_unref() * when you are done with it. * @param tz a {@code GTimeZone} * @param year the year component of the date * @param month the month component of the date * @param day the day component of the date * @param hour the hour component of the date * @param minute the minute component of the date * @param seconds the number of seconds past the minute */ private static MemorySegment constructNew(TimeZone tz, int year, int month, int day, int hour, int minute, double seconds) { MemorySegment _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT, ValueLayout.JAVA_DOUBLE); _result = (MemorySegment) Interop.downcallHandle("g_date_time_new", _fdesc, false) .invokeExact((MemorySegment) (tz == null ? MemorySegment.NULL : tz.handle()), year, month, day, hour, minute, seconds); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } return _result; } /** * Creates a {@code GDateTime} corresponding to the given * ISO 8601 formatted string * {@code text}. ISO 8601 strings of the form <date><sep><time><tz> are supported, with * some extensions from RFC 3339 as * mentioned below. *

* Note that as {@code GDateTime} "is oblivious to leap seconds", leap seconds information * in an ISO-8601 string will be ignored, so a {@code 23:59:60} time would be parsed as * {@code 23:59:59}. *

* <sep> is the separator and can be either 'T', 't' or ' '. The latter two * separators are an extension from * RFC 3339. *

* <date> is in the form: *

    *
  • {@code YYYY-MM-DD} - Year/month/day, e.g. 2016-08-24. *
  • {@code YYYYMMDD} - Same as above without dividers. *
  • {@code YYYY-DDD} - Ordinal day where DDD is from 001 to 366, e.g. 2016-237. *
  • {@code YYYYDDD} - Same as above without dividers. *
  • {@code YYYY-Www-D} - Week day where ww is from 01 to 52 and D from 1-7, * e.g. 2016-W34-3. *
  • {@code YYYYWwwD} - Same as above without dividers. *
*

* <time> is in the form: *

    *
  • {@code hh:mm:ss(.sss)} - Hours, minutes, seconds (subseconds), e.g. 22:10:42.123. *
  • {@code hhmmss(.sss)} - Same as above without dividers. *
*

* <tz> is an optional timezone suffix of the form: *

    *
  • {@code Z} - UTC. *
  • {@code +hh:mm} or {@code -hh:mm} - Offset from UTC in hours and minutes, e.g. +12:00. *
  • {@code +hh} or {@code -hh} - Offset from UTC in hours, e.g. +12. *
*

* If the timezone is not provided in {@code text} it must be provided in {@code default_tz} * (this field is otherwise ignored). *

* This call can fail (returning {@code null}) if {@code text} is not a valid ISO 8601 * formatted string. *

* You should release the return value by calling g_date_time_unref() * when you are done with it. * @param text an ISO 8601 formatted time string. * @param defaultTz a {@code GTimeZone} to use if the text doesn't contain a * timezone, or {@code null}. * @return a new {@code GDateTime}, or {@code null} */ public static DateTime fromIso8601(String text, @Nullable TimeZone defaultTz) { var _result = constructFromIso8601(text, defaultTz); var _instance = MemorySegment.NULL.equals(_result) ? null : new DateTime(_result); if (_instance != null) { MemoryCleaner.takeOwnership(_instance.handle()); MemoryCleaner.setFreeFunc(_instance.handle(), "g_boxed_free"); MemoryCleaner.setBoxedType(_instance.handle(), DateTime.getType()); } return (DateTime) _instance; } /** * Creates a {@code GDateTime} corresponding to the given * ISO 8601 formatted string * {@code text}. ISO 8601 strings of the form <date><sep><time><tz> are supported, with * some extensions from RFC 3339 as * mentioned below. *

* Note that as {@code GDateTime} "is oblivious to leap seconds", leap seconds information * in an ISO-8601 string will be ignored, so a {@code 23:59:60} time would be parsed as * {@code 23:59:59}. *

* <sep> is the separator and can be either 'T', 't' or ' '. The latter two * separators are an extension from * RFC 3339. *

* <date> is in the form: *

    *
  • {@code YYYY-MM-DD} - Year/month/day, e.g. 2016-08-24. *
  • {@code YYYYMMDD} - Same as above without dividers. *
  • {@code YYYY-DDD} - Ordinal day where DDD is from 001 to 366, e.g. 2016-237. *
  • {@code YYYYDDD} - Same as above without dividers. *
  • {@code YYYY-Www-D} - Week day where ww is from 01 to 52 and D from 1-7, * e.g. 2016-W34-3. *
  • {@code YYYYWwwD} - Same as above without dividers. *
*

* <time> is in the form: *

    *
  • {@code hh:mm:ss(.sss)} - Hours, minutes, seconds (subseconds), e.g. 22:10:42.123. *
  • {@code hhmmss(.sss)} - Same as above without dividers. *
*

* <tz> is an optional timezone suffix of the form: *

    *
  • {@code Z} - UTC. *
  • {@code +hh:mm} or {@code -hh:mm} - Offset from UTC in hours and minutes, e.g. +12:00. *
  • {@code +hh} or {@code -hh} - Offset from UTC in hours, e.g. +12. *
*

* If the timezone is not provided in {@code text} it must be provided in {@code default_tz} * (this field is otherwise ignored). *

* This call can fail (returning {@code null}) if {@code text} is not a valid ISO 8601 * formatted string. *

* You should release the return value by calling g_date_time_unref() * when you are done with it. * @param text an ISO 8601 formatted time string. * @param defaultTz a {@code GTimeZone} to use if the text doesn't contain a * timezone, or {@code null}. * @return a new {@code GDateTime}, or {@code null} */ private static MemorySegment constructFromIso8601(String text, @Nullable TimeZone defaultTz) { try (var _arena = Arena.ofConfined()) { MemorySegment _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.ADDRESS); _result = (MemorySegment) Interop.downcallHandle("g_date_time_new_from_iso8601", _fdesc, false) .invokeExact( (MemorySegment) (text == null ? MemorySegment.NULL : Interop.allocateNativeString(text, _arena)), (MemorySegment) (defaultTz == null ? MemorySegment.NULL : defaultTz.handle())); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } return _result; } } /** * Creates a {@code GDateTime} corresponding to the given {@code GTimeVal} {@code tv} in the * local time zone. *

* The time contained in a {@code GTimeVal} is always stored in the form of * seconds elapsed since 1970-01-01 00:00:00 UTC, regardless of the * local time offset. *

* This call can fail (returning {@code null}) if {@code tv} represents a time outside * of the supported range of {@code GDateTime}. *

* You should release the return value by calling g_date_time_unref() * when you are done with it. * @param tv a {@code GTimeVal} * @return a new {@code GDateTime}, or {@code null} * @deprecated {@code GTimeVal} is not year-2038-safe. Use * g_date_time_new_from_unix_local() instead. */ @Deprecated public static DateTime fromTimevalLocal(TimeVal tv) { var _result = constructFromTimevalLocal(tv); var _instance = MemorySegment.NULL.equals(_result) ? null : new DateTime(_result); if (_instance != null) { MemoryCleaner.takeOwnership(_instance.handle()); MemoryCleaner.setFreeFunc(_instance.handle(), "g_boxed_free"); MemoryCleaner.setBoxedType(_instance.handle(), DateTime.getType()); } return (DateTime) _instance; } /** * Creates a {@code GDateTime} corresponding to the given {@code GTimeVal} {@code tv} in the * local time zone. *

* The time contained in a {@code GTimeVal} is always stored in the form of * seconds elapsed since 1970-01-01 00:00:00 UTC, regardless of the * local time offset. *

* This call can fail (returning {@code null}) if {@code tv} represents a time outside * of the supported range of {@code GDateTime}. *

* You should release the return value by calling g_date_time_unref() * when you are done with it. * @param tv a {@code GTimeVal} * @return a new {@code GDateTime}, or {@code null} * @deprecated {@code GTimeVal} is not year-2038-safe. Use * g_date_time_new_from_unix_local() instead. */ @Deprecated private static MemorySegment constructFromTimevalLocal(TimeVal tv) { MemorySegment _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS); _result = (MemorySegment) Interop.downcallHandle("g_date_time_new_from_timeval_local", _fdesc, false) .invokeExact((MemorySegment) (tv == null ? MemorySegment.NULL : tv.handle())); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } return _result; } /** * Creates a {@code GDateTime} corresponding to the given {@code GTimeVal} {@code tv} in UTC. *

* The time contained in a {@code GTimeVal} is always stored in the form of * seconds elapsed since 1970-01-01 00:00:00 UTC. *

* This call can fail (returning {@code null}) if {@code tv} represents a time outside * of the supported range of {@code GDateTime}. *

* You should release the return value by calling g_date_time_unref() * when you are done with it. * @param tv a {@code GTimeVal} * @return a new {@code GDateTime}, or {@code null} * @deprecated {@code GTimeVal} is not year-2038-safe. Use * g_date_time_new_from_unix_utc() instead. */ @Deprecated public static DateTime fromTimevalUtc(TimeVal tv) { var _result = constructFromTimevalUtc(tv); var _instance = MemorySegment.NULL.equals(_result) ? null : new DateTime(_result); if (_instance != null) { MemoryCleaner.takeOwnership(_instance.handle()); MemoryCleaner.setFreeFunc(_instance.handle(), "g_boxed_free"); MemoryCleaner.setBoxedType(_instance.handle(), DateTime.getType()); } return (DateTime) _instance; } /** * Creates a {@code GDateTime} corresponding to the given {@code GTimeVal} {@code tv} in UTC. *

* The time contained in a {@code GTimeVal} is always stored in the form of * seconds elapsed since 1970-01-01 00:00:00 UTC. *

* This call can fail (returning {@code null}) if {@code tv} represents a time outside * of the supported range of {@code GDateTime}. *

* You should release the return value by calling g_date_time_unref() * when you are done with it. * @param tv a {@code GTimeVal} * @return a new {@code GDateTime}, or {@code null} * @deprecated {@code GTimeVal} is not year-2038-safe. Use * g_date_time_new_from_unix_utc() instead. */ @Deprecated private static MemorySegment constructFromTimevalUtc(TimeVal tv) { MemorySegment _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS); _result = (MemorySegment) Interop.downcallHandle("g_date_time_new_from_timeval_utc", _fdesc, false) .invokeExact((MemorySegment) (tv == null ? MemorySegment.NULL : tv.handle())); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } return _result; } /** * Creates a {@code GDateTime} corresponding to the given Unix time {@code t} in the * local time zone. *

* Unix time is the number of seconds that have elapsed since 1970-01-01 * 00:00:00 UTC, regardless of the local time offset. *

* This call can fail (returning {@code null}) if {@code t} represents a time outside * of the supported range of {@code GDateTime}. *

* You should release the return value by calling g_date_time_unref() * when you are done with it. * @param t the Unix time * @return a new {@code GDateTime}, or {@code null} */ public static DateTime fromUnixLocal(long t) { var _result = constructFromUnixLocal(t); var _instance = MemorySegment.NULL.equals(_result) ? null : new DateTime(_result); if (_instance != null) { MemoryCleaner.takeOwnership(_instance.handle()); MemoryCleaner.setFreeFunc(_instance.handle(), "g_boxed_free"); MemoryCleaner.setBoxedType(_instance.handle(), DateTime.getType()); } return (DateTime) _instance; } /** * Creates a {@code GDateTime} corresponding to the given Unix time {@code t} in the * local time zone. *

* Unix time is the number of seconds that have elapsed since 1970-01-01 * 00:00:00 UTC, regardless of the local time offset. *

* This call can fail (returning {@code null}) if {@code t} represents a time outside * of the supported range of {@code GDateTime}. *

* You should release the return value by calling g_date_time_unref() * when you are done with it. * @param t the Unix time * @return a new {@code GDateTime}, or {@code null} */ private static MemorySegment constructFromUnixLocal(long t) { MemorySegment _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.JAVA_LONG); _result = (MemorySegment) Interop.downcallHandle("g_date_time_new_from_unix_local", _fdesc, false) .invokeExact(t); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } return _result; } /** * Creates a {@code GDateTime} corresponding to the given Unix time {@code t} in UTC. *

* Unix time is the number of seconds that have elapsed since 1970-01-01 * 00:00:00 UTC. *

* This call can fail (returning {@code null}) if {@code t} represents a time outside * of the supported range of {@code GDateTime}. *

* You should release the return value by calling g_date_time_unref() * when you are done with it. * @param t the Unix time * @return a new {@code GDateTime}, or {@code null} */ public static DateTime fromUnixUtc(long t) { var _result = constructFromUnixUtc(t); var _instance = MemorySegment.NULL.equals(_result) ? null : new DateTime(_result); if (_instance != null) { MemoryCleaner.takeOwnership(_instance.handle()); MemoryCleaner.setFreeFunc(_instance.handle(), "g_boxed_free"); MemoryCleaner.setBoxedType(_instance.handle(), DateTime.getType()); } return (DateTime) _instance; } /** * Creates a {@code GDateTime} corresponding to the given Unix time {@code t} in UTC. *

* Unix time is the number of seconds that have elapsed since 1970-01-01 * 00:00:00 UTC. *

* This call can fail (returning {@code null}) if {@code t} represents a time outside * of the supported range of {@code GDateTime}. *

* You should release the return value by calling g_date_time_unref() * when you are done with it. * @param t the Unix time * @return a new {@code GDateTime}, or {@code null} */ private static MemorySegment constructFromUnixUtc(long t) { MemorySegment _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.JAVA_LONG); _result = (MemorySegment) Interop.downcallHandle("g_date_time_new_from_unix_utc", _fdesc, false) .invokeExact(t); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } return _result; } /** * Creates a new {@code GDateTime} corresponding to the given date and time in * the local time zone. *

* This call is equivalent to calling g_date_time_new() with the time * zone returned by g_time_zone_new_local(). * @param year the year component of the date * @param month the month component of the date * @param day the day component of the date * @param hour the hour component of the date * @param minute the minute component of the date * @param seconds the number of seconds past the minute * @return a {@code GDateTime}, or {@code null} */ public static DateTime local(int year, int month, int day, int hour, int minute, double seconds) { var _result = constructLocal(year, month, day, hour, minute, seconds); var _instance = MemorySegment.NULL.equals(_result) ? null : new DateTime(_result); if (_instance != null) { MemoryCleaner.takeOwnership(_instance.handle()); MemoryCleaner.setFreeFunc(_instance.handle(), "g_boxed_free"); MemoryCleaner.setBoxedType(_instance.handle(), DateTime.getType()); } return (DateTime) _instance; } /** * Creates a new {@code GDateTime} corresponding to the given date and time in * the local time zone. *

* This call is equivalent to calling g_date_time_new() with the time * zone returned by g_time_zone_new_local(). * @param year the year component of the date * @param month the month component of the date * @param day the day component of the date * @param hour the hour component of the date * @param minute the minute component of the date * @param seconds the number of seconds past the minute * @return a {@code GDateTime}, or {@code null} */ private static MemorySegment constructLocal(int year, int month, int day, int hour, int minute, double seconds) { MemorySegment _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT, ValueLayout.JAVA_DOUBLE); _result = (MemorySegment) Interop.downcallHandle("g_date_time_new_local", _fdesc, false) .invokeExact(year, month, day, hour, minute, seconds); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } return _result; } /** * Creates a {@code GDateTime} corresponding to this exact instant in the given * time zone {@code tz}. The time is as accurate as the system allows, to a * maximum accuracy of 1 microsecond. *

* This function will always succeed unless GLib is still being used after the * year 9999. *

* You should release the return value by calling g_date_time_unref() * when you are done with it. * @param tz a {@code GTimeZone} * @return a new {@code GDateTime}, or {@code null} */ public static DateTime now(TimeZone tz) { var _result = constructNow(tz); var _instance = MemorySegment.NULL.equals(_result) ? null : new DateTime(_result); if (_instance != null) { MemoryCleaner.takeOwnership(_instance.handle()); MemoryCleaner.setFreeFunc(_instance.handle(), "g_boxed_free"); MemoryCleaner.setBoxedType(_instance.handle(), DateTime.getType()); } return (DateTime) _instance; } /** * Creates a {@code GDateTime} corresponding to this exact instant in the given * time zone {@code tz}. The time is as accurate as the system allows, to a * maximum accuracy of 1 microsecond. *

* This function will always succeed unless GLib is still being used after the * year 9999. *

* You should release the return value by calling g_date_time_unref() * when you are done with it. * @param tz a {@code GTimeZone} * @return a new {@code GDateTime}, or {@code null} */ private static MemorySegment constructNow(TimeZone tz) { MemorySegment _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS); _result = (MemorySegment) Interop.downcallHandle("g_date_time_new_now", _fdesc, false) .invokeExact((MemorySegment) (tz == null ? MemorySegment.NULL : tz.handle())); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } return _result; } /** * Creates a {@code GDateTime} corresponding to this exact instant in the local * time zone. *

* This is equivalent to calling g_date_time_new_now() with the time * zone returned by g_time_zone_new_local(). * @return a new {@code GDateTime}, or {@code null} */ public static DateTime nowLocal() { var _result = constructNowLocal(); var _instance = MemorySegment.NULL.equals(_result) ? null : new DateTime(_result); if (_instance != null) { MemoryCleaner.takeOwnership(_instance.handle()); MemoryCleaner.setFreeFunc(_instance.handle(), "g_boxed_free"); MemoryCleaner.setBoxedType(_instance.handle(), DateTime.getType()); } return (DateTime) _instance; } /** * Creates a {@code GDateTime} corresponding to this exact instant in the local * time zone. *

* This is equivalent to calling g_date_time_new_now() with the time * zone returned by g_time_zone_new_local(). * @return a new {@code GDateTime}, or {@code null} */ private static MemorySegment constructNowLocal() { MemorySegment _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.ADDRESS); _result = (MemorySegment) Interop.downcallHandle("g_date_time_new_now_local", _fdesc, false) .invokeExact(); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } return _result; } /** * Creates a {@code GDateTime} corresponding to this exact instant in UTC. *

* This is equivalent to calling g_date_time_new_now() with the time * zone returned by g_time_zone_new_utc(). * @return a new {@code GDateTime}, or {@code null} */ public static DateTime nowUtc() { var _result = constructNowUtc(); var _instance = MemorySegment.NULL.equals(_result) ? null : new DateTime(_result); if (_instance != null) { MemoryCleaner.takeOwnership(_instance.handle()); MemoryCleaner.setFreeFunc(_instance.handle(), "g_boxed_free"); MemoryCleaner.setBoxedType(_instance.handle(), DateTime.getType()); } return (DateTime) _instance; } /** * Creates a {@code GDateTime} corresponding to this exact instant in UTC. *

* This is equivalent to calling g_date_time_new_now() with the time * zone returned by g_time_zone_new_utc(). * @return a new {@code GDateTime}, or {@code null} */ private static MemorySegment constructNowUtc() { MemorySegment _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.ADDRESS); _result = (MemorySegment) Interop.downcallHandle("g_date_time_new_now_utc", _fdesc, false) .invokeExact(); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } return _result; } /** * Creates a new {@code GDateTime} corresponding to the given date and time in * UTC. *

* This call is equivalent to calling g_date_time_new() with the time * zone returned by g_time_zone_new_utc(). * @param year the year component of the date * @param month the month component of the date * @param day the day component of the date * @param hour the hour component of the date * @param minute the minute component of the date * @param seconds the number of seconds past the minute * @return a {@code GDateTime}, or {@code null} */ public static DateTime utc(int year, int month, int day, int hour, int minute, double seconds) { var _result = constructUtc(year, month, day, hour, minute, seconds); var _instance = MemorySegment.NULL.equals(_result) ? null : new DateTime(_result); if (_instance != null) { MemoryCleaner.takeOwnership(_instance.handle()); MemoryCleaner.setFreeFunc(_instance.handle(), "g_boxed_free"); MemoryCleaner.setBoxedType(_instance.handle(), DateTime.getType()); } return (DateTime) _instance; } /** * Creates a new {@code GDateTime} corresponding to the given date and time in * UTC. *

* This call is equivalent to calling g_date_time_new() with the time * zone returned by g_time_zone_new_utc(). * @param year the year component of the date * @param month the month component of the date * @param day the day component of the date * @param hour the hour component of the date * @param minute the minute component of the date * @param seconds the number of seconds past the minute * @return a {@code GDateTime}, or {@code null} */ private static MemorySegment constructUtc(int year, int month, int day, int hour, int minute, double seconds) { MemorySegment _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT, ValueLayout.JAVA_DOUBLE); _result = (MemorySegment) Interop.downcallHandle("g_date_time_new_utc", _fdesc, false) .invokeExact(year, month, day, hour, minute, seconds); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } return _result; } /** * Creates a copy of {@code datetime} and adds the specified timespan to the copy. * @param timespan a {@code GTimeSpan} * @return the newly created {@code GDateTime} which * should be freed with g_date_time_unref(), or {@code null} */ public DateTime add(TimeSpan timespan) { MemorySegment _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.JAVA_LONG); _result = (MemorySegment) Interop.downcallHandle("g_date_time_add", _fdesc, false) .invokeExact(handle(), timespan.getValue().longValue()); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } var _instance = MemorySegment.NULL.equals(_result) ? null : new DateTime(_result); if (_instance != null) { MemoryCleaner.takeOwnership(_instance.handle()); MemoryCleaner.setFreeFunc(_instance.handle(), "g_boxed_free"); MemoryCleaner.setBoxedType(_instance.handle(), DateTime.getType()); } return _instance; } /** * Creates a copy of {@code datetime} and adds the specified number of days to the * copy. Add negative values to subtract days. * @param days the number of days * @return the newly created {@code GDateTime} which * should be freed with g_date_time_unref(), or {@code null} */ public DateTime addDays(int days) { MemorySegment _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.JAVA_INT); _result = (MemorySegment) Interop.downcallHandle("g_date_time_add_days", _fdesc, false) .invokeExact(handle(), days); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } var _instance = MemorySegment.NULL.equals(_result) ? null : new DateTime(_result); if (_instance != null) { MemoryCleaner.takeOwnership(_instance.handle()); MemoryCleaner.setFreeFunc(_instance.handle(), "g_boxed_free"); MemoryCleaner.setBoxedType(_instance.handle(), DateTime.getType()); } return _instance; } /** * Creates a new {@code GDateTime} adding the specified values to the current date and * time in {@code datetime}. Add negative values to subtract. * @param years the number of years to add * @param months the number of months to add * @param days the number of days to add * @param hours the number of hours to add * @param minutes the number of minutes to add * @param seconds the number of seconds to add * @return the newly created {@code GDateTime} which * should be freed with g_date_time_unref(), or {@code null} */ public DateTime addFull(int years, int months, int days, int hours, int minutes, double seconds) { MemorySegment _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT, ValueLayout.JAVA_DOUBLE); _result = (MemorySegment) Interop.downcallHandle("g_date_time_add_full", _fdesc, false) .invokeExact(handle(), years, months, days, hours, minutes, seconds); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } var _instance = MemorySegment.NULL.equals(_result) ? null : new DateTime(_result); if (_instance != null) { MemoryCleaner.takeOwnership(_instance.handle()); MemoryCleaner.setFreeFunc(_instance.handle(), "g_boxed_free"); MemoryCleaner.setBoxedType(_instance.handle(), DateTime.getType()); } return _instance; } /** * Creates a copy of {@code datetime} and adds the specified number of hours. * Add negative values to subtract hours. * @param hours the number of hours to add * @return the newly created {@code GDateTime} which * should be freed with g_date_time_unref(), or {@code null} */ public DateTime addHours(int hours) { MemorySegment _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.JAVA_INT); _result = (MemorySegment) Interop.downcallHandle("g_date_time_add_hours", _fdesc, false) .invokeExact(handle(), hours); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } var _instance = MemorySegment.NULL.equals(_result) ? null : new DateTime(_result); if (_instance != null) { MemoryCleaner.takeOwnership(_instance.handle()); MemoryCleaner.setFreeFunc(_instance.handle(), "g_boxed_free"); MemoryCleaner.setBoxedType(_instance.handle(), DateTime.getType()); } return _instance; } /** * Creates a copy of {@code datetime} adding the specified number of minutes. * Add negative values to subtract minutes. * @param minutes the number of minutes to add * @return the newly created {@code GDateTime} which * should be freed with g_date_time_unref(), or {@code null} */ public DateTime addMinutes(int minutes) { MemorySegment _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.JAVA_INT); _result = (MemorySegment) Interop.downcallHandle("g_date_time_add_minutes", _fdesc, false) .invokeExact(handle(), minutes); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } var _instance = MemorySegment.NULL.equals(_result) ? null : new DateTime(_result); if (_instance != null) { MemoryCleaner.takeOwnership(_instance.handle()); MemoryCleaner.setFreeFunc(_instance.handle(), "g_boxed_free"); MemoryCleaner.setBoxedType(_instance.handle(), DateTime.getType()); } return _instance; } /** * Creates a copy of {@code datetime} and adds the specified number of months to the * copy. Add negative values to subtract months. *

* The day of the month of the resulting {@code GDateTime} is clamped to the number * of days in the updated calendar month. For example, if adding 1 month to * 31st January 2018, the result would be 28th February 2018. In 2020 (a leap * year), the result would be 29th February. * @param months the number of months * @return the newly created {@code GDateTime} which * should be freed with g_date_time_unref(), or {@code null} */ public DateTime addMonths(int months) { MemorySegment _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.JAVA_INT); _result = (MemorySegment) Interop.downcallHandle("g_date_time_add_months", _fdesc, false) .invokeExact(handle(), months); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } var _instance = MemorySegment.NULL.equals(_result) ? null : new DateTime(_result); if (_instance != null) { MemoryCleaner.takeOwnership(_instance.handle()); MemoryCleaner.setFreeFunc(_instance.handle(), "g_boxed_free"); MemoryCleaner.setBoxedType(_instance.handle(), DateTime.getType()); } return _instance; } /** * Creates a copy of {@code datetime} and adds the specified number of seconds. * Add negative values to subtract seconds. * @param seconds the number of seconds to add * @return the newly created {@code GDateTime} which * should be freed with g_date_time_unref(), or {@code null} */ public DateTime addSeconds(double seconds) { MemorySegment _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.JAVA_DOUBLE); _result = (MemorySegment) Interop.downcallHandle("g_date_time_add_seconds", _fdesc, false) .invokeExact(handle(), seconds); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } var _instance = MemorySegment.NULL.equals(_result) ? null : new DateTime(_result); if (_instance != null) { MemoryCleaner.takeOwnership(_instance.handle()); MemoryCleaner.setFreeFunc(_instance.handle(), "g_boxed_free"); MemoryCleaner.setBoxedType(_instance.handle(), DateTime.getType()); } return _instance; } /** * Creates a copy of {@code datetime} and adds the specified number of weeks to the * copy. Add negative values to subtract weeks. * @param weeks the number of weeks * @return the newly created {@code GDateTime} which * should be freed with g_date_time_unref(), or {@code null} */ public DateTime addWeeks(int weeks) { MemorySegment _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.JAVA_INT); _result = (MemorySegment) Interop.downcallHandle("g_date_time_add_weeks", _fdesc, false) .invokeExact(handle(), weeks); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } var _instance = MemorySegment.NULL.equals(_result) ? null : new DateTime(_result); if (_instance != null) { MemoryCleaner.takeOwnership(_instance.handle()); MemoryCleaner.setFreeFunc(_instance.handle(), "g_boxed_free"); MemoryCleaner.setBoxedType(_instance.handle(), DateTime.getType()); } return _instance; } /** * Creates a copy of {@code datetime} and adds the specified number of years to the * copy. Add negative values to subtract years. *

* As with g_date_time_add_months(), if the resulting date would be 29th * February on a non-leap year, the day will be clamped to 28th February. * @param years the number of years * @return the newly created {@code GDateTime} which * should be freed with g_date_time_unref(), or {@code null} */ public DateTime addYears(int years) { MemorySegment _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.JAVA_INT); _result = (MemorySegment) Interop.downcallHandle("g_date_time_add_years", _fdesc, false) .invokeExact(handle(), years); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } var _instance = MemorySegment.NULL.equals(_result) ? null : new DateTime(_result); if (_instance != null) { MemoryCleaner.takeOwnership(_instance.handle()); MemoryCleaner.setFreeFunc(_instance.handle(), "g_boxed_free"); MemoryCleaner.setBoxedType(_instance.handle(), DateTime.getType()); } return _instance; } /** * A comparison function for {@code GDateTimes} that is suitable * as a {@code GCompareFunc}. Both {@code GDateTimes} must be non-{@code null}. * @param dt2 second {@code GDateTime} to compare * @return -1, 0 or 1 if {@code dt1} is less than, equal to or greater * than {@code dt2}. */ public int compare(DateTime dt2) { int _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS, ValueLayout.ADDRESS); _result = (int) Interop.downcallHandle("g_date_time_compare", _fdesc, false) .invokeExact(handle(), (MemorySegment) (dt2 == null ? MemorySegment.NULL : dt2.handle())); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } return _result; } /** * Calculates the difference in time between {@code end} and {@code begin}. The * {@code GTimeSpan} that is returned is effectively {@code end} - {@code begin} (ie: * positive if the first parameter is larger). * @param begin a {@code GDateTime} * @return the difference between the two {@code GDateTime}, as a time * span expressed in microseconds. */ public TimeSpan difference(DateTime begin) { long _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.JAVA_LONG, ValueLayout.ADDRESS, ValueLayout.ADDRESS); _result = (long) Interop.downcallHandle("g_date_time_difference", _fdesc, false) .invokeExact(handle(), (MemorySegment) (begin == null ? MemorySegment.NULL : begin.handle())); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } return new TimeSpan(_result); } /** * Checks to see if {@code dt1} and {@code dt2} are equal. *

* Equal here means that they represent the same moment after converting * them to the same time zone. * @param dt2 a {@code GDateTime} * @return {@code true} if {@code dt1} and {@code dt2} are equal */ public boolean equal(DateTime dt2) { int _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS, ValueLayout.ADDRESS); _result = (int) Interop.downcallHandle("g_date_time_equal", _fdesc, false).invokeExact( handle(), (MemorySegment) (dt2 == null ? MemorySegment.NULL : dt2.handle())); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } return _result != 0; } /** * Creates a newly allocated string representing the requested {@code format}. *

* The format strings understood by this function are a subset of the * {@code strftime()} format language as specified by C99. The {@code %D}, {@code %U} and {@code %W} * conversions are not supported, nor is the {@code E} modifier. The GNU * extensions {@code %k}, {@code %l}, {@code %s} and {@code %P} are supported, however, as are the * {@code 0}, {@code _} and {@code -} modifiers. The Python extension {@code %f} is also supported. *

* In contrast to {@code strftime()}, this function always produces a UTF-8 * string, regardless of the current locale. Note that the rendering of * many formats is locale-dependent and may not match the {@code strftime()} * output exactly. *

* The following format specifiers are supported: *

    *
  • {@code %a}: the abbreviated weekday name according to the current locale *
  • {@code %A}: the full weekday name according to the current locale *
  • {@code %b}: the abbreviated month name according to the current locale *
  • {@code %B}: the full month name according to the current locale *
  • {@code %c}: the preferred date and time representation for the current locale *
  • {@code %C}: the century number (year/100) as a 2-digit integer (00-99) *
  • {@code %d}: the day of the month as a decimal number (range 01 to 31) *
  • {@code %e}: the day of the month as a decimal number (range 1 to 31); * single digits are preceded by a figure space (U+2007) *
  • {@code %F}: equivalent to {@code %Y-%m-%d} (the ISO 8601 date format) *
  • {@code %g}: the last two digits of the ISO 8601 week-based year as a * decimal number (00-99). This works well with {@code %V} and {@code %u}. *
  • {@code %G}: the ISO 8601 week-based year as a decimal number. This works * well with {@code %V} and {@code %u}. *
  • {@code %h}: equivalent to {@code %b} *
  • {@code %H}: the hour as a decimal number using a 24-hour clock (range 00 to 23) *
  • {@code %I}: the hour as a decimal number using a 12-hour clock (range 01 to 12) *
  • {@code %j}: the day of the year as a decimal number (range 001 to 366) *
  • {@code %k}: the hour (24-hour clock) as a decimal number (range 0 to 23); * single digits are preceded by a figure space (U+2007) *
  • {@code %l}: the hour (12-hour clock) as a decimal number (range 1 to 12); * single digits are preceded by a figure space (U+2007) *
  • {@code %m}: the month as a decimal number (range 01 to 12) *
  • {@code %M}: the minute as a decimal number (range 00 to 59) *
  • {@code %f}: the microsecond as a decimal number (range 000000 to 999999) *
  • {@code %p}: either ‘AM’ or ‘PM’ according to the given time value, or the * corresponding strings for the current locale. Noon is treated as * ‘PM’ and midnight as ‘AM’. Use of this format specifier is discouraged, as * many locales have no concept of AM/PM formatting. Use {@code %c} or {@code %X} instead. *
  • {@code %P}: like {@code %p} but lowercase: ‘am’ or ‘pm’ or a corresponding string for * the current locale. Use of this format specifier is discouraged, as * many locales have no concept of AM/PM formatting. Use {@code %c} or {@code %X} instead. *
  • {@code %r}: the time in a.m. or p.m. notation. Use of this format specifier is * discouraged, as many locales have no concept of AM/PM formatting. Use {@code %c} * or {@code %X} instead. *
  • {@code %R}: the time in 24-hour notation ({@code %H:%M}) *
  • {@code %s}: the number of seconds since the Epoch, that is, since 1970-01-01 * 00:00:00 UTC *
  • {@code %S}: the second as a decimal number (range 00 to 60) *
  • {@code %t}: a tab character *
  • {@code %T}: the time in 24-hour notation with seconds ({@code %H:%M:%S}) *
  • {@code %u}: the ISO 8601 standard day of the week as a decimal, range 1 to 7, * Monday being 1. This works well with {@code %G} and {@code %V}. *
  • {@code %V}: the ISO 8601 standard week number of the current year as a decimal * number, range 01 to 53, where week 1 is the first week that has at * least 4 days in the new year. See g_date_time_get_week_of_year(). * This works well with {@code %G} and {@code %u}. *
  • {@code %w}: the day of the week as a decimal, range 0 to 6, Sunday being 0. * This is not the ISO 8601 standard format — use {@code %u} instead. *
  • {@code %x}: the preferred date representation for the current locale without * the time *
  • {@code %X}: the preferred time representation for the current locale without * the date *
  • {@code %y}: the year as a decimal number without the century *
  • {@code %Y}: the year as a decimal number including the century *
  • {@code %z}: the time zone as an offset from UTC ({@code +hhmm}) *
  • {@code %:z}: the time zone as an offset from UTC ({@code +hh:mm}). * This is a gnulib {@code strftime()} extension. Since: 2.38 *
  • {@code %::z}: the time zone as an offset from UTC ({@code +hh:mm:ss}). This is a * gnulib {@code strftime()} extension. Since: 2.38 *
  • {@code %:::z}: the time zone as an offset from UTC, with {@code :} to necessary * precision (e.g., {@code -04}, {@code +05:30}). This is a gnulib {@code strftime()} extension. Since: 2.38 *
  • {@code %Z}: the time zone or name or abbreviation *
  • {@code %%}: a literal {@code %} character *
*

* Some conversion specifications can be modified by preceding the * conversion specifier by one or more modifier characters. The * following modifiers are supported for many of the numeric * conversions: *

    *
  • {@code O}: Use alternative numeric symbols, if the current locale supports those. *
  • {@code _}: Pad a numeric result with spaces. This overrides the default padding * for the specifier. *
  • {@code -}: Do not pad a numeric result. This overrides the default padding * for the specifier. *
  • {@code 0}: Pad a numeric result with zeros. This overrides the default padding * for the specifier. *
*

* Additionally, when {@code O} is used with {@code B}, {@code b}, or {@code h}, it produces the alternative * form of a month name. The alternative form should be used when the month * name is used without a day number (e.g., standalone). It is required in * some languages (Baltic, Slavic, Greek, and more) due to their grammatical * rules. For other languages there is no difference. {@code %OB} is a GNU and BSD * {@code strftime()} extension expected to be added to the future POSIX specification, * {@code %Ob} and {@code %Oh} are GNU {@code strftime()} extensions. Since: 2.56 * @param format a valid UTF-8 string, containing the format for the * {@code GDateTime} * @return a newly allocated string formatted to * the requested format or {@code null} in the case that there was an error (such * as a format specifier not being supported in the current locale). The * string should be freed with g_free(). */ public String format(String format) { try (var _arena = Arena.ofConfined()) { MemorySegment _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.ADDRESS); _result = (MemorySegment) Interop.downcallHandle("g_date_time_format", _fdesc, false) .invokeExact(handle(), (MemorySegment) (format == null ? MemorySegment.NULL : Interop.allocateNativeString(format, _arena))); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } return Interop.getStringFrom(_result, true); } } /** * Format {@code datetime} in ISO 8601 format, * including the date, time and time zone, and return that as a UTF-8 encoded * string. *

* Since GLib 2.66, this will output to sub-second precision if needed. * @return a newly allocated string formatted in * ISO 8601 format or {@code null} in the case that there was an error. The string * should be freed with g_free(). */ public String formatIso8601() { MemorySegment _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS); _result = (MemorySegment) Interop.downcallHandle("g_date_time_format_iso8601", _fdesc, false) .invokeExact(handle()); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } return Interop.getStringFrom(_result, true); } /** * Retrieves the day of the month represented by {@code datetime} in the gregorian * calendar. * @return the day of the month */ public int getDayOfMonth() { int _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS); _result = (int) Interop.downcallHandle("g_date_time_get_day_of_month", _fdesc, false) .invokeExact(handle()); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } return _result; } /** * Retrieves the ISO 8601 day of the week on which {@code datetime} falls (1 is * Monday, 2 is Tuesday... 7 is Sunday). * @return the day of the week */ public int getDayOfWeek() { int _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS); _result = (int) Interop.downcallHandle("g_date_time_get_day_of_week", _fdesc, false) .invokeExact(handle()); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } return _result; } /** * Retrieves the day of the year represented by {@code datetime} in the Gregorian * calendar. * @return the day of the year */ public int getDayOfYear() { int _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS); _result = (int) Interop.downcallHandle("g_date_time_get_day_of_year", _fdesc, false) .invokeExact(handle()); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } return _result; } /** * Retrieves the hour of the day represented by {@code datetime} * @return the hour of the day */ public int getHour() { int _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS); _result = (int) Interop.downcallHandle("g_date_time_get_hour", _fdesc, false) .invokeExact(handle()); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } return _result; } /** * Retrieves the microsecond of the date represented by {@code datetime} * @return the microsecond of the second */ public int getMicrosecond() { int _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS); _result = (int) Interop.downcallHandle("g_date_time_get_microsecond", _fdesc, false) .invokeExact(handle()); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } return _result; } /** * Retrieves the minute of the hour represented by {@code datetime} * @return the minute of the hour */ public int getMinute() { int _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS); _result = (int) Interop.downcallHandle("g_date_time_get_minute", _fdesc, false) .invokeExact(handle()); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } return _result; } /** * Retrieves the month of the year represented by {@code datetime} in the Gregorian * calendar. * @return the month represented by {@code datetime} */ public int getMonth() { int _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS); _result = (int) Interop.downcallHandle("g_date_time_get_month", _fdesc, false) .invokeExact(handle()); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } return _result; } /** * Retrieves the second of the minute represented by {@code datetime} * @return the second represented by {@code datetime} */ public int getSecond() { int _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS); _result = (int) Interop.downcallHandle("g_date_time_get_second", _fdesc, false) .invokeExact(handle()); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } return _result; } /** * Retrieves the number of seconds since the start of the last minute, * including the fractional part. * @return the number of seconds */ public double getSeconds() { double _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.JAVA_DOUBLE, ValueLayout.ADDRESS); _result = (double) Interop.downcallHandle("g_date_time_get_seconds", _fdesc, false) .invokeExact(handle()); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } return _result; } /** * Get the time zone for this {@code datetime}. * @return the time zone */ public TimeZone getTimezone() { MemorySegment _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS); _result = (MemorySegment) Interop.downcallHandle("g_date_time_get_timezone", _fdesc, false) .invokeExact(handle()); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } var _instance = MemorySegment.NULL.equals(_result) ? null : new TimeZone(_result); if (_instance != null) { MemoryCleaner.takeOwnership(_instance.handle()); MemoryCleaner.setFreeFunc(_instance.handle(), "g_boxed_free"); MemoryCleaner.setBoxedType(_instance.handle(), TimeZone.getType()); } return _instance; } /** * Determines the time zone abbreviation to be used at the time and in * the time zone of {@code datetime}. *

* For example, in Toronto this is currently "EST" during the winter * months and "EDT" during the summer months when daylight savings * time is in effect. * @return the time zone abbreviation. The returned * string is owned by the {@code GDateTime} and it should not be * modified or freed */ public String getTimezoneAbbreviation() { MemorySegment _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS); _result = (MemorySegment) Interop.downcallHandle("g_date_time_get_timezone_abbreviation", _fdesc, false) .invokeExact(handle()); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } return Interop.getStringFrom(_result, false); } /** * Determines the offset to UTC in effect at the time and in the time * zone of {@code datetime}. *

* The offset is the number of microseconds that you add to UTC time to * arrive at local time for the time zone (ie: negative numbers for time * zones west of GMT, positive numbers for east). *

* If {@code datetime} represents UTC time, then the offset is always zero. * @return the number of microseconds that should be added to UTC to * get the local time */ public TimeSpan getUtcOffset() { long _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.JAVA_LONG, ValueLayout.ADDRESS); _result = (long) Interop.downcallHandle("g_date_time_get_utc_offset", _fdesc, false) .invokeExact(handle()); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } return new TimeSpan(_result); } /** * Returns the ISO 8601 week-numbering year in which the week containing * {@code datetime} falls. *

* This function, taken together with g_date_time_get_week_of_year() and * g_date_time_get_day_of_week() can be used to determine the full ISO * week date on which {@code datetime} falls. *

* This is usually equal to the normal Gregorian year (as returned by * g_date_time_get_year()), except as detailed below: *

* For Thursday, the week-numbering year is always equal to the usual * calendar year. For other days, the number is such that every day * within a complete week (Monday to Sunday) is contained within the * same week-numbering year. *

* For Monday, Tuesday and Wednesday occurring near the end of the year, * this may mean that the week-numbering year is one greater than the * calendar year (so that these days have the same week-numbering year * as the Thursday occurring early in the next year). *

* For Friday, Saturday and Sunday occurring near the start of the year, * this may mean that the week-numbering year is one less than the * calendar year (so that these days have the same week-numbering year * as the Thursday occurring late in the previous year). *

* An equivalent description is that the week-numbering year is equal to * the calendar year containing the majority of the days in the current * week (Monday to Sunday). *

* Note that January 1 0001 in the proleptic Gregorian calendar is a * Monday, so this function never returns 0. * @return the ISO 8601 week-numbering year for {@code datetime} */ public int getWeekNumberingYear() { int _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS); _result = (int) Interop.downcallHandle("g_date_time_get_week_numbering_year", _fdesc, false) .invokeExact(handle()); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } return _result; } /** * Returns the ISO 8601 week number for the week containing {@code datetime}. * The ISO 8601 week number is the same for every day of the week (from * Moday through Sunday). That can produce some unusual results * (described below). *

* The first week of the year is week 1. This is the week that contains * the first Thursday of the year. Equivalently, this is the first week * that has more than 4 of its days falling within the calendar year. *

* The value 0 is never returned by this function. Days contained * within a year but occurring before the first ISO 8601 week of that * year are considered as being contained in the last week of the * previous year. Similarly, the final days of a calendar year may be * considered as being part of the first ISO 8601 week of the next year * if 4 or more days of that week are contained within the new year. * @return the ISO 8601 week number for {@code datetime}. */ public int getWeekOfYear() { int _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS); _result = (int) Interop.downcallHandle("g_date_time_get_week_of_year", _fdesc, false) .invokeExact(handle()); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } return _result; } /** * Retrieves the year represented by {@code datetime} in the Gregorian calendar. * @return the year represented by {@code datetime} */ public int getYear() { int _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS); _result = (int) Interop.downcallHandle("g_date_time_get_year", _fdesc, false) .invokeExact(handle()); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } return _result; } /** * Retrieves the Gregorian day, month, and year of a given {@code GDateTime}. * @param year the return location for the gregorian year, or {@code null}. * @param month the return location for the month of the year, or {@code null}. * @param day the return location for the day of the month, or {@code null}. */ public void getYmd(@Nullable Out year, @Nullable Out month, @Nullable Out day) { try (var _arena = Arena.ofConfined()) { MemorySegment _yearPointer = _arena.allocate(ValueLayout.JAVA_INT); MemorySegment _monthPointer = _arena.allocate(ValueLayout.JAVA_INT); MemorySegment _dayPointer = _arena.allocate(ValueLayout.JAVA_INT); try { FunctionDescriptor _fdesc = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.ADDRESS); Interop.downcallHandle("g_date_time_get_ymd", _fdesc, false).invokeExact(handle(), (MemorySegment) (year == null ? MemorySegment.NULL : _yearPointer), (MemorySegment) (month == null ? MemorySegment.NULL : _monthPointer), (MemorySegment) (day == null ? MemorySegment.NULL : _dayPointer)); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } if (year != null) { year.set(_yearPointer.get(ValueLayout.JAVA_INT, 0)); } if (month != null) { month.set(_monthPointer.get(ValueLayout.JAVA_INT, 0)); } if (day != null) { day.set(_dayPointer.get(ValueLayout.JAVA_INT, 0)); } } } /** * Hashes {@code datetime} into a {@code guint}, suitable for use within {@code GHashTable}. * @return a {@code guint} containing the hash */ public int hash() { int _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS); _result = (int) Interop.downcallHandle("g_date_time_hash", _fdesc, false).invokeExact( handle()); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } return _result; } /** * Determines if daylight savings time is in effect at the time and in * the time zone of {@code datetime}. * @return {@code true} if daylight savings time is in effect */ public boolean isDaylightSavings() { int _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS); _result = (int) Interop.downcallHandle("g_date_time_is_daylight_savings", _fdesc, false) .invokeExact(handle()); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } return _result != 0; } /** * Atomically increments the reference count of {@code datetime} by one. * @return the {@code GDateTime} with the reference count increased */ public DateTime ref() { MemorySegment _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS); _result = (MemorySegment) Interop.downcallHandle("g_date_time_ref", _fdesc, false) .invokeExact(handle()); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } var _instance = MemorySegment.NULL.equals(_result) ? null : new DateTime(_result); if (_instance != null) { MemoryCleaner.takeOwnership(_instance.handle()); MemoryCleaner.setFreeFunc(_instance.handle(), "g_boxed_free"); MemoryCleaner.setBoxedType(_instance.handle(), DateTime.getType()); } return _instance; } /** * Creates a new {@code GDateTime} corresponding to the same instant in time as * {@code datetime}, but in the local time zone. *

* This call is equivalent to calling g_date_time_to_timezone() with the * time zone returned by g_time_zone_new_local(). * @return the newly created {@code GDateTime} which * should be freed with g_date_time_unref(), or {@code null} */ public DateTime toLocal() { MemorySegment _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS); _result = (MemorySegment) Interop.downcallHandle("g_date_time_to_local", _fdesc, false) .invokeExact(handle()); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } var _instance = MemorySegment.NULL.equals(_result) ? null : new DateTime(_result); if (_instance != null) { MemoryCleaner.takeOwnership(_instance.handle()); MemoryCleaner.setFreeFunc(_instance.handle(), "g_boxed_free"); MemoryCleaner.setBoxedType(_instance.handle(), DateTime.getType()); } return _instance; } /** * Stores the instant in time that {@code datetime} represents into {@code tv}. *

* The time contained in a {@code GTimeVal} is always stored in the form of * seconds elapsed since 1970-01-01 00:00:00 UTC, regardless of the time * zone associated with {@code datetime}. *

* On systems where 'long' is 32bit (ie: all 32bit systems and all * Windows systems), a {@code GTimeVal} is incapable of storing the entire * range of values that {@code GDateTime} is capable of expressing. On those * systems, this function returns {@code false} to indicate that the time is * out of range. *

* On systems where 'long' is 64bit, this function never fails. * @param tv a {@code GTimeVal} to modify * @return {@code true} if successful, else {@code false} * @deprecated {@code GTimeVal} is not year-2038-safe. Use * g_date_time_to_unix() instead. */ @Deprecated public boolean toTimeval(TimeVal tv) { int _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS, ValueLayout.ADDRESS); _result = (int) Interop.downcallHandle("g_date_time_to_timeval", _fdesc, false) .invokeExact(handle(), (MemorySegment) (tv == null ? MemorySegment.NULL : tv.handle())); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } return _result != 0; } /** * Create a new {@code GDateTime} corresponding to the same instant in time as * {@code datetime}, but in the time zone {@code tz}. *

* This call can fail in the case that the time goes out of bounds. For * example, converting 0001-01-01 00:00:00 UTC to a time zone west of * Greenwich will fail (due to the year 0 being out of range). * @param tz the new {@code GTimeZone} * @return the newly created {@code GDateTime} which * should be freed with g_date_time_unref(), or {@code null} */ public DateTime toTimezone(TimeZone tz) { MemorySegment _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.ADDRESS); _result = (MemorySegment) Interop.downcallHandle("g_date_time_to_timezone", _fdesc, false) .invokeExact(handle(), (MemorySegment) (tz == null ? MemorySegment.NULL : tz.handle())); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } var _instance = MemorySegment.NULL.equals(_result) ? null : new DateTime(_result); if (_instance != null) { MemoryCleaner.takeOwnership(_instance.handle()); MemoryCleaner.setFreeFunc(_instance.handle(), "g_boxed_free"); MemoryCleaner.setBoxedType(_instance.handle(), DateTime.getType()); } return _instance; } /** * Gives the Unix time corresponding to {@code datetime}, rounding down to the * nearest second. *

* Unix time is the number of seconds that have elapsed since 1970-01-01 * 00:00:00 UTC, regardless of the time zone associated with {@code datetime}. * @return the Unix time corresponding to {@code datetime} */ public long toUnix() { long _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.JAVA_LONG, ValueLayout.ADDRESS); _result = (long) Interop.downcallHandle("g_date_time_to_unix", _fdesc, false) .invokeExact(handle()); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } return _result; } /** * Creates a new {@code GDateTime} corresponding to the same instant in time as * {@code datetime}, but in UTC. *

* This call is equivalent to calling g_date_time_to_timezone() with the * time zone returned by g_time_zone_new_utc(). * @return the newly created {@code GDateTime} which * should be freed with g_date_time_unref(), or {@code null} */ public DateTime toUtc() { MemorySegment _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS); _result = (MemorySegment) Interop.downcallHandle("g_date_time_to_utc", _fdesc, false) .invokeExact(handle()); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } var _instance = MemorySegment.NULL.equals(_result) ? null : new DateTime(_result); if (_instance != null) { MemoryCleaner.takeOwnership(_instance.handle()); MemoryCleaner.setFreeFunc(_instance.handle(), "g_boxed_free"); MemoryCleaner.setBoxedType(_instance.handle(), DateTime.getType()); } return _instance; } /** * Atomically decrements the reference count of {@code datetime} by one. *

* When the reference count reaches zero, the resources allocated by * {@code datetime} are freed */ public void unref() { try { FunctionDescriptor _fdesc = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS); Interop.downcallHandle("g_date_time_unref", _fdesc, false).invokeExact(handle()); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy