ebx-unixtime-sdk

ebx-unixtime-sdk is a simple reusable implementation of a unix time construct.

License

License

GroupId

GroupId

com.echobox
ArtifactId

ArtifactId

ebx-unixtime-sdk
Last Version

Last Version

2.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

ebx-unixtime-sdk
ebx-unixtime-sdk is a simple reusable implementation of a unix time construct.
Project URL

Project URL

https://github.com/ebx/ebx-unixtime-sdk
Source Code Management

Source Code Management

https://github.com/ebx/ebx-unixtime-sdk

Download ebx-unixtime-sdk

How to add to project

<!-- https://jarcasting.com/artifacts/com.echobox/ebx-unixtime-sdk/ -->
<dependency>
    <groupId>com.echobox</groupId>
    <artifactId>ebx-unixtime-sdk</artifactId>
    <version>2.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.echobox/ebx-unixtime-sdk/
implementation 'com.echobox:ebx-unixtime-sdk:2.0.0'
// https://jarcasting.com/artifacts/com.echobox/ebx-unixtime-sdk/
implementation ("com.echobox:ebx-unixtime-sdk:2.0.0")
'com.echobox:ebx-unixtime-sdk:jar:2.0.0'
<dependency org="com.echobox" name="ebx-unixtime-sdk" rev="2.0.0">
  <artifact name="ebx-unixtime-sdk" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.echobox', module='ebx-unixtime-sdk', version='2.0.0')
)
libraryDependencies += "com.echobox" % "ebx-unixtime-sdk" % "2.0.0"
[com.echobox/ebx-unixtime-sdk "2.0.0"]

Dependencies

test (1)

Group / Artifact Type Version
junit : junit jar 4.13.1

Project Modules

There are no modules declared in this project.

Maven Central License Build Status

ebx-unixtime-sdk

A simple reusable implementation of a unix time construct.

This was originally created for use in Java 6-7 to allow for test mocking but since Java 8 we also have:

import java.time.Clock;
...
long unixTimestamp = Clock.systemUTC().instant().getEpochSecond();

and

import java.time.Instant;
...
long unixTimestamp = Instant.now().getEpochSecond();

Wherever unix times are required (and form part of business logic) the preferred usage is to inject java.time.Clock into constructors or failing that Supplier<Long>.

Installation

For our latest stable release use:

<dependency>
  <groupId>com.echobox</groupId>
  <artifactId>ebx-unixtime-sdk</artifactId>
  <version>2.0.0</version>
</dependency>

Example using java.time.Clock

Important: When testing please use Clock.fixed(Instant.parse("2017-10-22T07:52 :11Z "), ZoneOffset.UTC) or similar rather than mocking the clock to avoid NPEs.

public class Test {

  private final Clock clock;

  public Test(Clock clock) {
    this.clock = clock;
  }
 
  public void doSomething() {
    long currentUnixTime = clock.instant().getEpochSecond();
    ...
  }
}

We could then instantiate by:

new Test(Clock.systemUTC())

or

new Test(Clock.fixed(Instant.parse("2017-10-22T07:52:11Z"), ZoneOffset.UTC))

Example using Supplier<Long>

public class Test {

  private final Long<Supplier> unixTimeSupplier;

  public Test(Long<Supplier> unixTimeSupplier) {
    this.unixTimeSupplier = unixTimeSupplier;
  }
 
  public void doSomething() {
    long currentUnixTime = unixTimeSupplier.get();
    ...
  }
}

We could then instantiate by:

new Test(Instant.now()::getEpochSecond)

or where the existing class still has legacy mocks:

new Test(UnixTime::now)
com.echobox

Echobox

Using the power of Microservices, Big Data and ML to intelligently automate publishing.

Versions

Version
2.0.0