Project

General

Profile

Download (1.37 KB) Statistics
| Branch: | Revision:
1
define([
2
'dojo/date/locale'
3
], function(locale){
4

    
5
    function bytes2mbs(size, rowIds, cell){
6
      return Math.round(Number(size)/(1024*1024));
7
    };
8
    
9
    function bytes2gbs(size, rowIds, cell){
10
      return Math.round(Number(size)/(1024*1024*1024));
11
    };
12
    
13
    function kbytes2mbs(size, rowIds, cell){
14
      return Math.round(Number(size)/1024);
15
    };
16
    
17
    function datetime(/*String*/ timestamp){
18
      return locale.format(new Date(timestamp), this.constraint);
19
    };
20

    
21
    /**
22
     * Converts a long string of bytes into a readable format e.g KB, MB, GB, TB, YB
23
     *
24
     * @param {Int} num The number of bytes.
25
     */
26
    function readableBytes(bytes) {
27
        var i = Math.floor(Math.log(bytes) / Math.log(1024)),
28
            sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
29

    
30
        return (bytes / Math.pow(1024, i)).toFixed(2) * 1 + ' ' + sizes[i];
31
    };
32
    function readableMBytes(mbytes) {
33
        var bytes = mbytes *1024*1024;
34
        var i = Math.floor(Math.log(bytes) / Math.log(1024)),
35
            sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
36

    
37
        return (bytes / Math.pow(1024, i)).toFixed(2) * 1 + ' ' + sizes[i];
38
    }
39

    
40
    return {
41
      bytes2mbs: bytes2mbs,
42
      bytes2gbs: bytes2gbs,
43
      kbytes2mbs: kbytes2mbs,
44
      readableBytes: readableBytes,
45
      readableMBytes: readableMBytes,
46
      datetime:datetime
47
    };
48
})
(5-5/23)