kandi background
Explore Kits

Time4J | Advanced date , time and interval library | Date Time Utils library

 by   MenoData Java Version: v5.9 License: LGPL-2.1

 by   MenoData Java Version: v5.9 License: LGPL-2.1

Download this library from

kandi X-RAY | Time4J Summary

Time4J is a Java library typically used in Utilities, Date Time Utils applications. Time4J has no bugs, it has no vulnerabilities, it has build file available, it has a Weak Copyleft License and it has low support. You can download it from GitHub, Maven.
Advanced date, time and interval library for Java.
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • Time4J has a low active ecosystem.
  • It has 349 star(s) with 50 fork(s). There are 25 watchers for this library.
  • There were 1 major release(s) in the last 12 months.
  • There are 17 open issues and 920 have been closed. On average issues are closed in 31 days. There are no pull requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of Time4J is v5.9
Time4J Support
Best in #Date Time Utils
Average in #Date Time Utils
Time4J Support
Best in #Date Time Utils
Average in #Date Time Utils

quality kandi Quality

  • Time4J has 0 bugs and 0 code smells.
Time4J Quality
Best in #Date Time Utils
Average in #Date Time Utils
Time4J Quality
Best in #Date Time Utils
Average in #Date Time Utils

securitySecurity

  • Time4J has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • Time4J code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
Time4J Security
Best in #Date Time Utils
Average in #Date Time Utils
Time4J Security
Best in #Date Time Utils
Average in #Date Time Utils

license License

  • Time4J is licensed under the LGPL-2.1 License. This license is Weak Copyleft.
  • Weak Copyleft licenses have some restrictions, but you can use them in commercial projects.
Time4J License
Best in #Date Time Utils
Average in #Date Time Utils
Time4J License
Best in #Date Time Utils
Average in #Date Time Utils

buildReuse

  • Time4J releases are available to install and integrate.
  • Deployable package is available in Maven.
  • Build file is available. You can build the component from source.
  • Installation instructions are not available. Examples and code snippets are available.
  • It has 169654 lines of code, 13661 functions and 796 files.
  • It has high code complexity. Code complexity directly impacts maintainability of the code.
Time4J Reuse
Best in #Date Time Utils
Average in #Date Time Utils
Time4J Reuse
Best in #Date Time Utils
Average in #Date Time Utils
Top functions reviewed by kandi - BETA

kandi has reviewed Time4J and discovered the below as its top functions. This is intended to give you an instant insight into Time4J implemented functionality, and help decide if they suit your requirements.

  • Liefert ein Daten einzel ein Dataset .
    • Updates the cells rows .
      • Summarizes sums of sum to sum sums .
        • Calculates the Meeus anomaly for the given Julian point .
          • Parses the start component .
            • Internal method used to parse the raw data .
              • Returns a copy of this attribute set with the specified locale .
                • Returns a new interval composed of this interval with the specified time window .
                  • Checks if an interval is starts with another .
                    • Reads a list of transitions .

                      Get all kandi verified functions for this library.

                      Get all kandi verified functions for this library.

                      Time4J Key Features

                      Advanced date, time and interval library for Java with sun/moon-astronomy and calendars like Chinese, Coptic, Ethiopian, French Republican, Hebrew, Hijri, Historic Christian, Indian National, Japanese, Julian, Korean, Minguo, Persian, Thai, Vietnamese

                      Current state and introduction:

                      copy iconCopydownload iconDownload
                      import net.time4j.*;
                      import net.time4j.format.TextWidth;
                      import net.time4j.format.expert.PatternType;
                      import net.time4j.tz.olson.*;
                      
                      import java.util.Locale;
                      
                      import static net.time4j.CalendarUnit.MONTHS;
                      import static net.time4j.PlainDate.DAY_OF_MONTH;
                      import static net.time4j.PlainDate.DAY_OF_WEEK;
                      import static net.time4j.PlainTime.MINUTE_OF_HOUR;
                      import static net.time4j.Weekday.WEDNESDAY;
                      
                      public class Demo {
                        public static void main(String... args) {
                      	// What is the last day of overnext month?
                      	System.out.println(
                      		SystemClock.inLocalView().today().plus(2, MONTHS).with(DAY_OF_MONTH.maximized()));
                      
                      	// When is next wednesday?
                      	PlainDate today = SystemClock.inLocalView().today();
                      	PlainDate nextWednesday = today.with(DAY_OF_WEEK.setToNext(WEDNESDAY));
                      	System.out.println(nextWednesday);
                      
                      	// What is the current wall time rounded down to multiples of 5 minutes?
                      	PlainTimestamp currentLocalTimestamp = SystemClock.inZonalView(EUROPE.BERLIN).now();
                      	PlainTime roundedTime =
                      		currentLocalTimestamp.getWallTime() // T22:06:52,688
                      		.with(MINUTE_OF_HOUR.atFloor()) // T22:06
                      		.with(MINUTE_OF_HOUR.roundedDown(5)); // T22:05
                      	System.out.println("Rounded wall time: " + roundedTime);
                      
                      	// Example for flexible dayperiods
                      	PlainTime eveningTime = PlainTime.of(20, 45);
                      	ChronoFormatter<PlainTime> formatter =
                      		ChronoFormatter.ofTimePattern("h:mm B", PatternType.CLDR, Locale.ENGLISH);
                      	System.out.println(
                      		"12-hour-format with dayperiod: "
                      		+ formatter.format(eveningTime)); // 8:45 in the evening
                      
                      	// How does last UTC-leapsecond look like in Japan?
                      	Moment leapsecondUTC =
                      		PlainDate.of(2012, Month.JUNE, 30)
                      		.at(PlainTime.midnightAtEndOfDay()) // 2012-06-30T24 => 2012-07-01T00
                      		.atUTC().minus(1, SI.SECONDS);
                      	System.out.println(leapsecondUTC); // 2012-06-30T23:59:60Z
                      
                      	System.out.println(
                      		"Japan-Time: "
                      		+ ChronoFormatter.ofMomentPattern(
                      		     "uuuu-MM-dd'T'HH:mm:ssXX",
                      		     PatternType.CLDR,
                      		     Locale.ROOT,
                      		     ASIA.TOKYO
                      		  ).format(leapsecondUTC)
                      	); // Japan-Time: 2012-07-01T08:59:60+0900
                      
                      	// duration in seconds normalized to hours, minutes and seconds
                      	Duration<ClockUnit> dur = Duration.of(337540, ClockUnit.SECONDS).with(Duration.STD_CLOCK_PERIOD);
                      
                      	// custom duration format => hh:mm:ss
                      	String s1 = Duration.Formatter.ofPattern(ClockUnit.class, "hh:mm:ss").format(dur);
                      	System.out.println(s1); // output: 93:45:40
                      
                      	// localized duration format for french
                      	String s2 = PrettyTime.of(Locale.FRANCE).print(dur, TextWidth.WIDE);
                      	System.out.println(s2); // output: 93 heures, 45 minutes et 40 secondes
                      
                      	// following code requires v4.20 (or later) and Java-8 using java.time.LocalDate
                      	ChronoFormatter<LocalDate> formatter2 =
                      	    ChronoFormatter.setUp(PlainDate.threeten(), new Locale("en", "SE"))
                      	        .addPattern("GGGG yyyy, MMMM ", PatternType.CLDR)
                      	        .addEnglishOrdinal(ChronoHistory.ofSweden().dayOfMonth())
                      	        .build();
                      	System.out.println(formatter2.format(LocalDate.of(1712, 3, 11)));
                      	// output: Anno Domini 1712, February 30th
                        }
                      }

                      Downloads and Requirements:

                      copy iconCopydownload iconDownload
                      <dependency>
                        <groupId>net.time4j</groupId>
                        <artifactId>time4j-base</artifactId>
                        <version>5.8</version>
                      </dependency>
                      <dependency>
                        <groupId>net.time4j</groupId>
                        <artifactId>time4j-sqlxml</artifactId>
                        <version>5.8</version>
                      </dependency>
                      <dependency>
                        <groupId>net.time4j</groupId>
                        <artifactId>time4j-tzdata</artifactId>
                        <version>5.0-2020a</version>
                      </dependency>

                      How to convert a Time4J Duration to a count of minutes?

                      copy iconCopydownload iconDownload
                          List<Duration<ClockUnit>> durations = Arrays.asList(
                                  Duration.of(1, ClockUnit.HOURS),
                                  Duration.of(34, ClockUnit.SECONDS));
                          
                          for (Duration<ClockUnit> dur : durations) {
                              long minutes = dur.with(ClockUnit.MINUTES.only())
                                      .getPartialAmount(ClockUnit.MINUTES);
                              System.out.format("%s = %d minutes%n", dur, minutes);
                          }
                      
                      PT1H = 60 minutes
                      PT34S = 0 minutes
                      
                      private static final long durationToNumber(Duration<ClockUnit> dur, ClockUnit unit) {
                          return dur.with(unit.only()).getPartialAmount(unit);
                      }
                      
                          for (Duration<ClockUnit> dur : durations) {
                              long hours = durationToNumber(dur, ClockUnit.HOURS);
                              long seconds = durationToNumber(dur, ClockUnit.SECONDS);
                              System.out.format("%s = %d hours or %d seconds%n", dur, hours, seconds);
                          }
                      
                      PT1H = 1 hours or 3600 seconds
                      PT34S = 0 hours or 34 seconds
                      
                          List<Duration<ClockUnit>> durations = Arrays.asList(
                                  Duration.of(1, ClockUnit.HOURS),
                                  Duration.of(34, ClockUnit.SECONDS));
                          
                          for (Duration<ClockUnit> dur : durations) {
                              long minutes = dur.with(ClockUnit.MINUTES.only())
                                      .getPartialAmount(ClockUnit.MINUTES);
                              System.out.format("%s = %d minutes%n", dur, minutes);
                          }
                      
                      PT1H = 60 minutes
                      PT34S = 0 minutes
                      
                      private static final long durationToNumber(Duration<ClockUnit> dur, ClockUnit unit) {
                          return dur.with(unit.only()).getPartialAmount(unit);
                      }
                      
                          for (Duration<ClockUnit> dur : durations) {
                              long hours = durationToNumber(dur, ClockUnit.HOURS);
                              long seconds = durationToNumber(dur, ClockUnit.SECONDS);
                              System.out.format("%s = %d hours or %d seconds%n", dur, hours, seconds);
                          }
                      
                      PT1H = 1 hours or 3600 seconds
                      PT34S = 0 hours or 34 seconds
                      
                          List<Duration<ClockUnit>> durations = Arrays.asList(
                                  Duration.of(1, ClockUnit.HOURS),
                                  Duration.of(34, ClockUnit.SECONDS));
                          
                          for (Duration<ClockUnit> dur : durations) {
                              long minutes = dur.with(ClockUnit.MINUTES.only())
                                      .getPartialAmount(ClockUnit.MINUTES);
                              System.out.format("%s = %d minutes%n", dur, minutes);
                          }
                      
                      PT1H = 60 minutes
                      PT34S = 0 minutes
                      
                      private static final long durationToNumber(Duration<ClockUnit> dur, ClockUnit unit) {
                          return dur.with(unit.only()).getPartialAmount(unit);
                      }
                      
                          for (Duration<ClockUnit> dur : durations) {
                              long hours = durationToNumber(dur, ClockUnit.HOURS);
                              long seconds = durationToNumber(dur, ClockUnit.SECONDS);
                              System.out.format("%s = %d hours or %d seconds%n", dur, hours, seconds);
                          }
                      
                      PT1H = 1 hours or 3600 seconds
                      PT34S = 0 hours or 34 seconds
                      
                          List<Duration<ClockUnit>> durations = Arrays.asList(
                                  Duration.of(1, ClockUnit.HOURS),
                                  Duration.of(34, ClockUnit.SECONDS));
                          
                          for (Duration<ClockUnit> dur : durations) {
                              long minutes = dur.with(ClockUnit.MINUTES.only())
                                      .getPartialAmount(ClockUnit.MINUTES);
                              System.out.format("%s = %d minutes%n", dur, minutes);
                          }
                      
                      PT1H = 60 minutes
                      PT34S = 0 minutes
                      
                      private static final long durationToNumber(Duration<ClockUnit> dur, ClockUnit unit) {
                          return dur.with(unit.only()).getPartialAmount(unit);
                      }
                      
                          for (Duration<ClockUnit> dur : durations) {
                              long hours = durationToNumber(dur, ClockUnit.HOURS);
                              long seconds = durationToNumber(dur, ClockUnit.SECONDS);
                              System.out.format("%s = %d hours or %d seconds%n", dur, hours, seconds);
                          }
                      
                      PT1H = 1 hours or 3600 seconds
                      PT34S = 0 hours or 34 seconds
                      
                          List<Duration<ClockUnit>> durations = Arrays.asList(
                                  Duration.of(1, ClockUnit.HOURS),
                                  Duration.of(34, ClockUnit.SECONDS));
                          
                          for (Duration<ClockUnit> dur : durations) {
                              long minutes = dur.with(ClockUnit.MINUTES.only())
                                      .getPartialAmount(ClockUnit.MINUTES);
                              System.out.format("%s = %d minutes%n", dur, minutes);
                          }
                      
                      PT1H = 60 minutes
                      PT34S = 0 minutes
                      
                      private static final long durationToNumber(Duration<ClockUnit> dur, ClockUnit unit) {
                          return dur.with(unit.only()).getPartialAmount(unit);
                      }
                      
                          for (Duration<ClockUnit> dur : durations) {
                              long hours = durationToNumber(dur, ClockUnit.HOURS);
                              long seconds = durationToNumber(dur, ClockUnit.SECONDS);
                              System.out.format("%s = %d hours or %d seconds%n", dur, hours, seconds);
                          }
                      
                      PT1H = 1 hours or 3600 seconds
                      PT34S = 0 hours or 34 seconds
                      

                      javafx open window no effect.application launch with then throw class not found

                      copy iconCopydownload iconDownload
                      package sample;
                      
                      import javafx.application.Application;
                      import javafx.scene.Scene;
                      import javafx.scene.control.Label;
                      import javafx.stage.Stage;
                      
                      public class Main extends Application {
                      
                          @Override
                          public void start(Stage primaryStage) throws Exception {
                              // Launch all your JavaFX code and methods from inside this Entry Point function.
                              Stage stage = new Stage();
                              Scene scene = new Scene(new Label("I am a label object"));
                              stage.setScene(scene);
                              stage.show();
                          }
                      
                      
                          public static void main(String[] args) {
                              launch(args);
                          }
                      }
                      

                      How to use PrettyTime in time4j library?

                      copy iconCopydownload iconDownload
                          <dependency>
                              <groupId>net.time4j</groupId>
                              <artifactId>time4j-base</artifactId>
                              <version>5.6</version>
                          </dependency>
                          <dependency>
                              <groupId>net.time4j</groupId>
                              <artifactId>time4j-sqlxml</artifactId>
                              <version>5.6</version>
                          </dependency>
                          <dependency>
                              <groupId>net.time4j</groupId>
                              <artifactId>time4j-tzdata</artifactId>
                              <version>5.0-2020a</version>
                          </dependency>
                      
                      val duration = Duration.of(7261, ClockUnit.SECONDS).with(Duration.STD_CLOCK_PERIOD)
                      val prettifiedDuration = PrettyTime.of(Locale.ENGLISH).print(duration)
                      
                      println(prettifiedDuration)
                      
                      2 hours, 1 minute, and 1 second
                      
                          <dependency>
                              <groupId>net.time4j</groupId>
                              <artifactId>time4j-base</artifactId>
                              <version>5.6</version>
                          </dependency>
                          <dependency>
                              <groupId>net.time4j</groupId>
                              <artifactId>time4j-sqlxml</artifactId>
                              <version>5.6</version>
                          </dependency>
                          <dependency>
                              <groupId>net.time4j</groupId>
                              <artifactId>time4j-tzdata</artifactId>
                              <version>5.0-2020a</version>
                          </dependency>
                      
                      val duration = Duration.of(7261, ClockUnit.SECONDS).with(Duration.STD_CLOCK_PERIOD)
                      val prettifiedDuration = PrettyTime.of(Locale.ENGLISH).print(duration)
                      
                      println(prettifiedDuration)
                      
                      2 hours, 1 minute, and 1 second
                      
                          <dependency>
                              <groupId>net.time4j</groupId>
                              <artifactId>time4j-base</artifactId>
                              <version>5.6</version>
                          </dependency>
                          <dependency>
                              <groupId>net.time4j</groupId>
                              <artifactId>time4j-sqlxml</artifactId>
                              <version>5.6</version>
                          </dependency>
                          <dependency>
                              <groupId>net.time4j</groupId>
                              <artifactId>time4j-tzdata</artifactId>
                              <version>5.0-2020a</version>
                          </dependency>
                      
                      val duration = Duration.of(7261, ClockUnit.SECONDS).with(Duration.STD_CLOCK_PERIOD)
                      val prettifiedDuration = PrettyTime.of(Locale.ENGLISH).print(duration)
                      
                      println(prettifiedDuration)
                      
                      2 hours, 1 minute, and 1 second
                      
                      implementation("net.time4j:time4j-android:4.6-2020a")
                      
                      class MyApplication : DaggerApplication() {
                      
                          override fun onCreate() {
                              super.onCreate()
                              ApplicationStarter.initialize(this, true)
                          }
                      }
                      
                      implementation("net.time4j:time4j-android:4.6-2020a")
                      
                      class MyApplication : DaggerApplication() {
                      
                          override fun onCreate() {
                              super.onCreate()
                              ApplicationStarter.initialize(this, true)
                          }
                      }
                      

                      Community Discussions

                      Trending Discussions on Time4J
                      • How to convert a Time4J Duration to a count of minutes?
                      • javafx open window no effect.application launch with then throw class not found
                      • Errors when I try to build my Java project in VS Code
                      • How to use PrettyTime in time4j library?
                      Trending Discussions on Time4J

                      QUESTION

                      How to convert a Time4J Duration to a count of minutes?

                      Asked 2021-Aug-04 at 20:37

                      How do I convert a Time4J Duration<ClockUnit> to a number of minutes? I’m fine with truncating any seconds, I just want the whole minutes. A couple of simple examples probably explain the best:

                      • For Duration.of(1, ClockUnit.HOURS) I want 60.
                      • For Duration.of(34, ClockUnit.SECONDS) I want 0.

                      There isn’t any toMinutes method (like there is in java.time.Duration). I played around with a Normalizer, the getTotalLength method and a stream operation and got a 6 lines solution to work, but surely there is a simpler way?

                      The solutions for hours and seconds could also be interesting, but I expect them to be more or less trivial modifications of the solution for minutes.

                      Link: Documentation of net.time4j.Duration

                      ANSWER

                      Answered 2021-Aug-04 at 20:37
                      Normalize to minutes and use getPartialAmount()

                      We do need the normalizer. We get it from ClockUnit.only(). Then getPartialAmount() takes care of the rest.

                          List<Duration<ClockUnit>> durations = Arrays.asList(
                                  Duration.of(1, ClockUnit.HOURS),
                                  Duration.of(34, ClockUnit.SECONDS));
                          
                          for (Duration<ClockUnit> dur : durations) {
                              long minutes = dur.with(ClockUnit.MINUTES.only())
                                      .getPartialAmount(ClockUnit.MINUTES);
                              System.out.format("%s = %d minutes%n", dur, minutes);
                          }
                      

                      Output:

                      PT1H = 60 minutes
                      PT34S = 0 minutes
                      

                      As explained in the tutorial (link at the bottom), Time4J is mainly designed around chronological elements (or fields) like years, months, and yes, minutes. So in code we first need to convert the duration to a duration of only minutes, after which we can take out the value of the minutes element — now the only element in the duration (in the case of 14 seconds, there isn’t even any minutes element, but getPartialAmount() sensibly returns 0 in this case).

                      We should obviously wrap the conversion into a method:

                      private static final long durationToNumber(Duration<ClockUnit> dur, ClockUnit unit) {
                          return dur.with(unit.only()).getPartialAmount(unit);
                      }
                      

                      As a bonus this method gives us the conversion to hours or seconds for free:

                          for (Duration<ClockUnit> dur : durations) {
                              long hours = durationToNumber(dur, ClockUnit.HOURS);
                              long seconds = durationToNumber(dur, ClockUnit.SECONDS);
                              System.out.format("%s = %d hours or %d seconds%n", dur, hours, seconds);
                          }
                      
                      PT1H = 1 hours or 3600 seconds
                      PT34S = 0 hours or 34 seconds
                      

                      Source https://stackoverflow.com/questions/68652953

                      Community Discussions, Code Snippets contain sources that include Stack Exchange Network

                      Vulnerabilities

                      No vulnerabilities reported

                      Install Time4J

                      You can download it from GitHub, Maven.
                      You can use Time4J like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the Time4J component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .

                      Support

                      Ethiopian (including support for Ethiopian time). Hebrew (including support for Hebrew time). Hijri (Islamic) with a lot of customizable variants. Hindu (based on algorithms by Dershowitz/Reingold). Historic christian (includes british, byzantine, swedish etc.). Japanese (including lunisolar part since AD 701). ThaiSolar (Suriyakati), also valid before 1941.

                      DOWNLOAD this Library from

                      Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
                      over 430 million Knowledge Items
                      Find more libraries
                      Reuse Solution Kits and Libraries Curated by Popular Use Cases
                      Explore Kits

                      Save this library and start creating your kit

                      Explore Related Topics

                      Share this Page

                      share link
                      Consider Popular Date Time Utils Libraries
                      Try Top Libraries by MenoData
                      Compare Date Time Utils Libraries with Highest Support
                      Compare Date Time Utils Libraries with Highest Quality
                      Compare Date Time Utils Libraries with Highest Security
                      Compare Date Time Utils Libraries with Permissive License
                      Compare Date Time Utils Libraries with Highest Reuse
                      Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
                      over 430 million Knowledge Items
                      Find more libraries
                      Reuse Solution Kits and Libraries Curated by Popular Use Cases
                      Explore Kits

                      Save this library and start creating your kit

                      • © 2022 Open Weaver Inc.