Blame view

VRGNYMusicLights/Sources/Util.java 1.01 KB
278cdee0   pfrison   VRGNYMusicLights ...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
  
  public class Util {
  	public static long textToTick(String str) {
  		if(str == null || str.equals(""))
  			return 0;
  		String[] strs = str.split(":|\\.");
  		long ticks = 0;
  		
  		try {
  			switch (strs.length) {
  			case 1:
  				ticks += Integer.parseInt(strs[0]);
  				break;
  			case 2:
  				ticks += Integer.parseInt(strs[1]);
  				ticks += Integer.parseInt(strs[0]) * 1000;
  				break;
  			case 3:
  				ticks += Integer.parseInt(strs[2]);
  				ticks += Integer.parseInt(strs[1]) * 1000;
  				ticks += Integer.parseInt(strs[0]) * 60000;
  				break;
  			}
  		} catch (NumberFormatException e) {
  			return 0;
  		}
  		return ticks;
  	}
  	
  	public static String tickToText(long tick) {
  		String str = "";
  		
  		if(tick > 5900000)
  			str += "99:";
  		else
  			str += String.format("%02d", (int) ((double) tick / 60000d)) + ":";
  		
  		tick -= (int) ((double) tick / 60000d) * 60000;
  		str += String.format("%02d", (int) ((double) tick / 1000d)) + ".";
  		
  		tick -= (int) ((double) tick / 1000d) * 1000;
  		str += String.format("%03d", tick);
  		
  		return str;
  	}
  }