You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@submarine.apache.org by pi...@apache.org on 2022/02/26 16:44:18 UTC

[submarine] branch master updated: SUBMARINE-1158. Humanize the time in model-info page

This is an automated email from the ASF dual-hosted git repository.

pingsutw pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/submarine.git


The following commit(s) were added to refs/heads/master by this push:
     new 4bd8bf3  SUBMARINE-1158. Humanize the time in model-info page
4bd8bf3 is described below

commit 4bd8bf3391341761bf596b00497aec8e56470f02
Author: Ray02250418 <s9...@gmail.com>
AuthorDate: Sat Feb 26 11:26:43 2022 +0800

    SUBMARINE-1158. Humanize the time in model-info page
    
    ### What is this PR for?
    Humanize the Created and Updated time in model-info page.
    
    ### What type of PR is it?
    Improvement
    
    ### Todos
    * [ ] - Humanize time in other pages.
    
    ### What is the Jira issue?
    https://issues.apache.org/jira/projects/SUBMARINE/issues/SUBMARINE-1158?filter=allissues
    
    ### How should this be tested?
    
    ### Screenshots (if appropriate)
    
    ![](https://issues.apache.org/jira/secure/attachment/13040493/13040493_image-2022-02-26-11-20-28-901.png)
    
    ### Questions:
    * Do the license files need updating? No
    * Are there breaking changes for older versions? No
    * Does this need new documentation? No
    
    Author: Ray02250418 <s9...@gmail.com>
    
    Signed-off-by: Kevin <pi...@apache.org>
    
    Closes #890 from Ray02250418/SUBMARINE-1158 and squashes the following commits:
    
    c3fba51b [Ray02250418] SUNMARINE-1158. Bug fix
    0c900ccf [Ray02250418] SUBMARINE-1158. Add humanize-time function and use in model-info page
---
 .../model/model-info/model-info.component.html     |  4 ++--
 .../model/model-info/model-info.component.ts       |  6 +++++
 .../src/app/pages/workbench/utils/humanize-time.ts | 27 ++++++++++++++++++++++
 3 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/submarine-workbench/workbench-web/src/app/pages/workbench/model/model-info/model-info.component.html b/submarine-workbench/workbench-web/src/app/pages/workbench/model/model-info/model-info.component.html
index a8b51b3..d22f35a 100644
--- a/submarine-workbench/workbench-web/src/app/pages/workbench/model/model-info/model-info.component.html
+++ b/submarine-workbench/workbench-web/src/app/pages/workbench/model/model-info/model-info.component.html
@@ -22,11 +22,11 @@
       <h3 nz-typography>{{modelName}}</h3>
       <p nz-typography>
         <span><strong>Creation Time: </strong></span>
-        {{ isModelInfoLoading ? null : selectedModelInfo.creationTime }}
+        {{ isModelInfoLoading ? null : humanizedCreationTime }}
       </p>
       <p nz-typography>
         <span><strong>Last Updated Time: </strong></span>
-        {{ isModelInfoLoading ? null : selectedModelInfo.lastUpdatedTime }}
+        {{ isModelInfoLoading ? null : humanizedLastUpdatedTime }}
       </p>
       <p nz-typography>
         <span><strong>Tags: </strong></span>
diff --git a/submarine-workbench/workbench-web/src/app/pages/workbench/model/model-info/model-info.component.ts b/submarine-workbench/workbench-web/src/app/pages/workbench/model/model-info/model-info.component.ts
index b38fc87..6bcfaf2 100644
--- a/submarine-workbench/workbench-web/src/app/pages/workbench/model/model-info/model-info.component.ts
+++ b/submarine-workbench/workbench-web/src/app/pages/workbench/model/model-info/model-info.component.ts
@@ -23,6 +23,7 @@ import { ModelVersionService } from '@submarine/services/model-version.service';
 import { ModelService } from '@submarine/services/model.service';
 import { ModelInfo } from '@submarine/interfaces/model-info';
 import { ModelVersionInfo } from '@submarine/interfaces/model-version-info';
+import {humanizeTime} from '@submarine/pages/workbench/utils/humanize-time'
 
 @Component({
   selector: 'submarine-model-info',
@@ -35,6 +36,8 @@ export class ModelInfoComponent implements OnInit {
   modelName: string;
   selectedModelInfo: ModelInfo; 
   modelVersions: ModelVersionInfo[];
+  humanizedCreationTime: string;
+  humanizedLastUpdatedTime: string;
 
   constructor(
     private router: Router, 
@@ -54,6 +57,8 @@ export class ModelInfoComponent implements OnInit {
     this.modelService.querySpecificModel(this.modelName).subscribe(
       (res) => {
         this.selectedModelInfo = res;
+        this.humanizedCreationTime = humanizeTime(res.creationTime);
+        this.humanizedLastUpdatedTime = humanizeTime(res.lastUpdatedTime);
         this.isModelInfoLoading = false;
       }
     )
@@ -68,3 +73,4 @@ export class ModelInfoComponent implements OnInit {
     );
   }
 }
+
diff --git a/submarine-workbench/workbench-web/src/app/pages/workbench/utils/humanize-time.ts b/submarine-workbench/workbench-web/src/app/pages/workbench/utils/humanize-time.ts
new file mode 100644
index 0000000..8fc6d10
--- /dev/null
+++ b/submarine-workbench/workbench-web/src/app/pages/workbench/utils/humanize-time.ts
@@ -0,0 +1,27 @@
+export function humanizeTime(time: string){
+    let time_ = time.split(/[\s-:]+/).map(Number);
+    let date = new Date(time_[0], time_[1]-1, time_[2], time_[3], time_[4], time_[5]);
+    let now = new Date;
+    let seconds = (now.getTime() - date.getTime()) / 1000;
+    if (seconds <= 0) {
+        return 0 + "second ago"
+    }
+    var numyears = Math.floor(seconds / 31536000);
+    if (numyears !== 0) {
+        return numyears===1 ? numyears + "year ago" : numyears + "years ago";
+    }
+    var numdays = Math.floor((seconds % 31536000) / 86400);
+    if (numdays !== 0) {
+        return numdays===1 ? numdays + "day ago" : numdays + "days ago";
+    }
+    var numhours = Math.floor(((seconds % 31536000) % 86400) / 3600);
+    if (numhours !== 0) {
+        return numhours===1 ? numhours + "hour ago" : numhours + "hours ago";
+    }
+    var numminutes = Math.floor((((seconds % 31536000) % 86400) % 3600) / 60);
+    if (numminutes !== 0) {
+        return numminutes===1 ? numminutes + "minute ago" : numminutes + "minutes ago";
+    }
+    var numseconds = (((seconds % 31536000) % 86400) % 3600) % 60;
+    return numseconds===1 ? numseconds + "second ago" : numseconds + "seconds ago";
+}
\ No newline at end of file

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@submarine.apache.org
For additional commands, e-mail: dev-help@submarine.apache.org