Re: hunt-time library 1.0.0 beta1 released

2019-04-07 Thread Sönke Ludwig via Digitalmars-d-announce

Am 07.04.2019 um 09:09 schrieb bauss:

On Thursday, 4 April 2019 at 11:25:34 UTC, Andre Pany wrote:

On Thursday, 4 April 2019 at 10:49:46 UTC, zoujiaqing wrote:

Hunt time released the first beta version.

hunt-time is a time library and similar to Joda-time and Java.time api.

[...]


I am not sure but did you rewrote the java.time library (copyright of 
Oracle) from Java to D? I am not an expert but I have some fear using 
this library due to legal consequences. Did you contacted Oracle and 
asked wheter that is ok?


I honor your work, but if I want to develop commercial applications i 
have to think twice which libraries I use to avoid any legal issues.


Kind regards
Andre


It's only copyrighted by Oracle if you use Oracle's Java implementation 
but if you reference OpenJDK then there shouldn't be any problems.


But as explained above there aren't any in this case anyway since 
Oracle's implementation is based on something with a fine license.


Except that OpenJDK is L-GPL (AFAICS), so that it can't be changed to 
Apache in the process.


Re: hunt-time library 1.0.0 beta1 released

2019-04-07 Thread bauss via Digitalmars-d-announce

On Thursday, 4 April 2019 at 11:25:34 UTC, Andre Pany wrote:

On Thursday, 4 April 2019 at 10:49:46 UTC, zoujiaqing wrote:

Hunt time released the first beta version.

hunt-time is a time library and similar to Joda-time and 
Java.time api.


[...]


I am not sure but did you rewrote the java.time library 
(copyright of Oracle) from Java to D? I am not an expert but I 
have some fear using this library due to legal consequences. 
Did you contacted Oracle and asked wheter that is ok?


I honor your work, but if I want to develop commercial 
applications i have to think twice which libraries I use to 
avoid any legal issues.


Kind regards
Andre


It's only copyrighted by Oracle if you use Oracle's Java 
implementation but if you reference OpenJDK then there shouldn't 
be any problems.


But as explained above there aren't any in this case anyway since 
Oracle's implementation is based on something with a fine license.


Re: hunt-time library 1.0.0 beta1 released

2019-04-04 Thread zoujiaqing via Digitalmars-d-announce

On Thursday, 4 April 2019 at 11:25:34 UTC, Andre Pany wrote:

On Thursday, 4 April 2019 at 10:49:46 UTC, zoujiaqing wrote:

Hunt time released the first beta version.

hunt-time is a time library and similar to Joda-time and 
Java.time api.


[...]


I am not sure but did you rewrote the java.time library 
(copyright of Oracle) from Java to D? I am not an expert but I 
have some fear using this library due to legal consequences. 
Did you contacted Oracle and asked wheter that is ok?


I honor your work, but if I want to develop commercial 
applications i have to think twice which libraries I use to 
avoid any legal issues.


Kind regards
Andre


Java.time using Joda-time api.

PS: Joda-Time is licensed under the business-friendly Apache 2.0 
licence.

https://www.joda.org/joda-time/


Re: hunt-time library 1.0.0 beta1 released

2019-04-04 Thread Andre Pany via Digitalmars-d-announce

On Thursday, 4 April 2019 at 10:49:46 UTC, zoujiaqing wrote:

Hunt time released the first beta version.

hunt-time is a time library and similar to Joda-time and 
Java.time api.


[...]


I am not sure but did you rewrote the java.time library 
(copyright of Oracle) from Java to D? I am not an expert but I 
have some fear using this library due to legal consequences. Did 
you contacted Oracle and asked wheter that is ok?


I honor your work, but if I want to develop commercial 
applications i have to think twice which libraries I use to avoid 
any legal issues.


Kind regards
Andre


hunt-time library 1.0.0 beta1 released

2019-04-04 Thread zoujiaqing via Digitalmars-d-announce

Hunt time released the first beta version.

hunt-time is a time library and similar to Joda-time and 
Java.time api.


The library features:

 * LocalDate - date without time
 * LocalTime - time without date
 * Instant - an instantaneous point on the time-line
 * DateTime - full date and time with time-zone
 * DateTimeZone - a better time-zone
 * Duration and Period - amounts of time
 * Interval - the time between two instants
 * A comprehensive and flexible formatter-parser

Sample codes:

LocalDate/LocalTime/LocalDateTime

LocalDate, a date API that represents a date without time; 
LocalTime, a time representation without a date; and 
LocalDateTime, which is a combination of the previous two. All of 
these types represent the local date and/or time for a region, 
but,they contain zero information about the zone in which it is 
represented, only a representation of the date and time in your 
current timezone.


First of all, these APIs support an easy instantiation:

LocalDate date = LocalDate.of(2018,2,13);
// Uses DateTimeformatter.ISO_LOCAL_DATE for which the format is: 
-MM-dd

LocalDate date = LocalDate.parse("2018-02-13");
LocalTime time = LocalTime.of(6,30);
// Uses DateTimeFormatter.ISO_LOCAL_TIME for which the format is: 
HH:mm[:ss[.S]]
// this means that both seconds and nanoseconds may optionally be 
present.

LocalTime time = LocalTime.parse("06:30");
LocalDateTime dateTime = LocalDateTime.of(2018,2,13,6,30);
// Uses DateTimeFormatter.ISO_LOCAL_DATE_TIME for which the 
format is the
// combination of the ISO date and time format, joined by 'T': 
-MM-dd'T'HH:mm[:ss[.S]]

LocalDateTime dateTime = LocalDateTime.parse("2018-02-13T06:30");

It’s easy to convert between them:

// LocalDate to LocalDateTime
LocalDateTime dateTime = 
LocalDate.parse("2018-02-13").atTime(LocalTime.parse("06:30"));

// LocalTime to LocalDateTime
LocalDateTime dateTime = 
LocalTime.parse("06:30").atDate(LocalDate.parse("2018-02-13"));

// LocalDateTime to LocalDate/LocalTime
LocalDate date = 
LocalDateTime.parse("2018-02-13T06:30").toLocalDate();
LocalTime time = 
LocalDateTime.parse("2018-02-13T06:30").toLocalTime();


Aside from that, it’s incredibly easy to perform operations on 
our date and time representations, using the plus and minus 
methods as well as some utility functions:


LocalDate date = LocalDate.parse("2018-02-13").plusDays(5);
LocalDate date = LocalDate.parse("2018-02-13").plus(3, 
ChronoUnit.MONTHS);

LocalTime time = LocalTime.parse("06:30").minusMinutes(30);
LocalTime time = LocalTime.parse("06:30").minus(500, 
ChronoUnit.MILLIS);
LocalDateTime dateTime = 
LocalDateTime.parse("2018-02-13T06:30").plus(Duration.ofHours(2));

// using TemporalAdjusters, which implements a few useful cases:
LocalDate date = 
LocalDate.parse("2018-02-13").with(TemporalAdjusters.lastDayOfMonth());


Difference in Time: Duration and Period

As you’ve noticed, in one of the above examples we’ve used a 
Duration object. Duration and Period are two representations of 
time between two dates, the former representing the difference of 
time in seconds and nanoseconds, the latter in days, months and 
years.


When should you use these? Period when you need to know the 
difference in time between two LocalDaterepresentations:


Period period = Period.between(LocalDate.parse("2018-01-18"), 
LocalDate.parse("2018-02-14"));


Duration when you’re looking for a difference between a 
representation that holds time information:


Duration duration = 
Duration.between(LocalDateTime.parse("2018-01-18T06:30"), 
LocalDateTime.parse("2018-02-14T22:58"));


When outputting Period or Duration using toString(), a special 
format will be used based on ISO-8601 standard. The pattern used 
for a Period is PnYnMnD, where n defines the number of years, 
months or days present within the period. This means that P1Y2M3D 
defines a period of 1 year, 2 months, and 3 days. The ‘P’ in the 
pattern is the period designator, which tells us that the 
following format represents a period. Using the pattern, we can 
also create a period based on a string using the parse() method.


// represents a period of 27 days
Period period = Period.parse("P27D");

When using Durations, we move away slightly from the ISO-8601 
standard. The pattern defined by ISO-8601 is PnYnMnDTnHnMn.nS. 
This is basically the Period pattern, extended with a time 
representation. In the pattern, T is the time designator, so the 
part that follows defines a duration specified in hours, minutes 
and seconds.


Last but not least, we can also retrieve the various parts of a 
period or duration, by using the corresponding method on a type. 
However, it’s important to know that the various datetime types 
also support this through the use of ChronoUnit enumeration type. 
Let’s take a look at some examples:


// represents PT664H28M
Duration duration = 
Duration.between(LocalDateTime.parse("2018-01-18T06:30"), 
LocalDateTime.parse("2018-02-14T22:58"));

// returns