Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

39
LINES

< > BotCompany Repo | #1029631 // Timestamp

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (10663L/59K).

srecord Timestamp(long date) implements Comparable<Timestamp> {
  *() { date = now(); }
  *(Date date) { if (date != null) this.date = date.getTime(); }
  
  long unixDate aka toLong() { ret date; }
  long unixSeconds() { ret unixDate()/1000; }
  
  toString { ret formatLocalDateWithSeconds(date); }
  
  // Hmm. Should Timestamp(0) be equal to null? Question, questions...
  public int compareTo(Timestamp t) {
    ret t == null ? 1 : cmp(date, t.date);
  }
  
  Timestamp plus(Seconds seconds) {
    ret plus(seconds?.getDouble());
  }
  
  Timestamp plus aka plusSeconds(double seconds) {
    ret Timestamp(date+toMS(seconds));
  }
  
  // returns milliseconds
  long minus(Timestamp ts) {
    ret unixDate()-ts.unixDate();
  }
  
  Timestamp minus(long milliseconds) {
    ret Timestamp(date-milliseconds);
  }
  
  long sysTime() {
    ret clockTimeToSystemTime(date);
  }
  
  Duration minusAsDuration(Timestamp ts) {
    ret Duration.ofMillis(minus(ts));
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 8 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, wnsclhtenguj, xrpafgyirdlv

No comments. add comment

Snippet ID: #1029631
Snippet name: Timestamp
Eternal ID of this version: #1029631/17
Text MD5: 5354b974bb4d614d7b2fe9dee1c8495c
Transpilation MD5: 70a56fd1531d941d65c43637f8f96aa0
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2023-07-07 23:00:40
Source code size: 1006 bytes / 39 lines
Pitched / IR pitched: No / No
Views / Downloads: 296 / 672
Version history: 16 change(s)
Referenced in: [show references]