diff options
author | Sven Göthel <[email protected]> | 2024-02-03 02:55:43 +0100 |
---|---|---|
committer | Sven Göthel <[email protected]> | 2024-02-03 02:55:43 +0100 |
commit | 7cc0bf0d58a3e3f672ce2e4f179de21f1f67dc93 (patch) | |
tree | 5ce57b30f9e5ca8c3022352ae1b938f184757727 /src/jogl | |
parent | fcf10b35daeab6356e389487a37196f14523df71 (diff) |
Hausmacher Merge: Complete merge part-1 into JOGL from our typecast branch; Adding missing LongDateTime class
haumacher https://github.com/haumacher/typecast
https://jogamp.org/cgit/typecast.git/log/?h=jogl_patches
Status:
- Compile clean
- Graph/GraphUI Bring-Up OK
- Fixes CJK ttf font parsing due to fixed Cmap table
Diffstat (limited to 'src/jogl')
-rw-r--r-- | src/jogl/classes/jogamp/graph/font/typecast/ot/LongDateTime.java | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/LongDateTime.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/LongDateTime.java new file mode 100644 index 000000000..b5db921ff --- /dev/null +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/LongDateTime.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2020 Business Operation Systems GmbH. All Rights Reserved. + */ +package jogamp.graph.font.typecast.ot; + +import java.time.ZoneId; +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.TimeZone; + +/** + * Utility to convert number of seconds since 12:00 midnight that started + * January 1st 1904 in GMT/UTC time zone to a {@link Date} value. + * + * @author <a href="mailto:[email protected]">Bernhard Haumacher</a> + */ +public class LongDateTime { + + private static final long BASE; + + static { + GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone(ZoneId.of("UTC"))); + calendar.set(Calendar.YEAR, 1904); + calendar.set(Calendar.MONTH, Calendar.JANUARY); + calendar.set(Calendar.DAY_OF_MONTH, 1); + calendar.set(Calendar.HOUR, 0); + calendar.set(Calendar.MINUTE, 0); + calendar.set(Calendar.SECOND, 0); + calendar.set(Calendar.MILLISECOND, 0); + + BASE = calendar.getTimeInMillis(); + } + + /** + * Converts a {@link LongDateTime} value to a {@link Date}. + */ + public static Date toDate(long longDateTime) { + return new Date(toSystemMillis(longDateTime)); + } + + /** + * Converts a {@link LongDateTime} value to a Java system millis value compatible + * with {@link System#currentTimeMillis()}. + */ + public static long toSystemMillis(long longDateTime) { + return BASE + 1000L * longDateTime; + } + + /** + * Converts a {@link Date} to a {@link LongDateTime} value. + */ + public static long fromDate(Date date) { + return fromSystemMillis(date.getTime()); + } + + /** + * Converts a Java system millis value compatible + * with {@link System#currentTimeMillis()} to a {@link LongDateTime} value. + */ + public static long fromSystemMillis(long systemMillis) { + return (systemMillis - BASE) / 1000L; + } + +} |