Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initiate with a certain nanoTime #980

Open
Shefaee opened this issue Apr 17, 2023 · 1 comment
Open

initiate with a certain nanoTime #980

Shefaee opened this issue Apr 17, 2023 · 1 comment
Labels

Comments

@Shefaee
Copy link

Shefaee commented Apr 17, 2023

Hi,
Is it possible to set the base time manually?
For example: from the server (not the system)

val nanoTime  = 0;//from Server
ApplicationStarter.initialize(context, prefetch, nanoTime);

Thank you very much for your great work

@MenoData
Copy link
Owner

MenoData commented May 9, 2023

Sorry for late reply. Mea culpa.

The third parameter nanoTime does not exist. I interprete your question as proposal to introduce such a third parameter. Well, I think there is no need for such a parameter in this initialization method which is rather about resource and context class loading.

Probably you look for a way to set up an application-wide clock which is once initiated by the server time. Time4J has such a clock package but Time4A unfortunately not yet. You might look at the actual implementations of the clock package of Time4J to model a suitable clock for Time4A.

Maybe this is an inspiration:

public class ServerTimeSource implements TimeSource<Moment> {
  private final long offset;

  public ServerTimeSource(long serverTimeUTInMillisecsSince1970) {
    this.offset = serverTimeUTInMillisecsSince1970 - System.currentTimeMillis();
  }

  public Moment currentTime() {
    long timeInMillis = System.currentTimeMillis() + this.offset;
    return TemporalType.MILLIS_SINCE_UNIX.translate(timeInMillis);
  }
  
}

Then you would instantiate the class once and store it in an application-wide location so it can be reused many times whenever you want to know the server time (as UT). If you also want to use the server time zone you have to store it as TZID or offset, too, in an application-wide location.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants