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).

1  
srecord Timestamp(long date) implements Comparable<Timestamp> {
2  
  *() { date = now(); }
3  
  *(Date date) { if (date != null) this.date = date.getTime(); }
4  
  
5  
  long unixDate aka toLong() { ret date; }
6  
  long unixSeconds() { ret unixDate()/1000; }
7  
  
8  
  toString { ret formatLocalDateWithSeconds(date); }
9  
  
10  
  // Hmm. Should Timestamp(0) be equal to null? Question, questions...
11  
  public int compareTo(Timestamp t) {
12  
    ret t == null ? 1 : cmp(date, t.date);
13  
  }
14  
  
15  
  Timestamp plus(Seconds seconds) {
16  
    ret plus(seconds?.getDouble());
17  
  }
18  
  
19  
  Timestamp plus aka plusSeconds(double seconds) {
20  
    ret Timestamp(date+toMS(seconds));
21  
  }
22  
  
23  
  // returns milliseconds
24  
  long minus(Timestamp ts) {
25  
    ret unixDate()-ts.unixDate();
26  
  }
27  
  
28  
  Timestamp minus(long milliseconds) {
29  
    ret Timestamp(date-milliseconds);
30  
  }
31  
  
32  
  long sysTime() {
33  
    ret clockTimeToSystemTime(date);
34  
  }
35  
  
36  
  Duration minusAsDuration(Timestamp ts) {
37  
    ret Duration.ofMillis(minus(ts));
38  
  }
39  
}

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: 375 / 771
Version history: 16 change(s)
Referenced in: [show references]