Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
15 additions
and
33 deletions.
There are no files selected for viewing
48 changes: 15 additions & 33 deletions
48
xchange-bittrex/src/main/java/org/knowm/xchange/bittrex/v1/BittrexUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,35 @@ | ||
package org.knowm.xchange.bittrex.v1; | ||
|
||
import java.text.ParseException; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Calendar; | ||
import java.util.Date; | ||
import java.util.TimeZone; | ||
|
||
import javax.xml.bind.DatatypeConverter; | ||
|
||
import org.knowm.xchange.currency.CurrencyPair; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* A central place for shared Bittrex properties | ||
*/ | ||
public final class BittrexUtils { | ||
|
||
private static final Date EPOCH = new Date(0); | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(BittrexUtils.class); | ||
|
||
/** | ||
* private Constructor | ||
*/ | ||
private BittrexUtils() { | ||
private static final String TIMEZONE = "UTC"; | ||
|
||
} | ||
/** | ||
* private Constructor | ||
*/ | ||
private BittrexUtils() { | ||
|
||
public static String toPairString(CurrencyPair currencyPair) { | ||
|
||
return currencyPair.counter.getCurrencyCode().toUpperCase() + "-" + currencyPair.base.getCurrencyCode().toUpperCase(); | ||
} | ||
|
||
public static Date toDate(String datetime) { | ||
// Bittrex can truncate the millisecond component of datetime fields (e.g. 2015-12-20T02:07:51.5) | ||
// to the point where if the milliseconds are zero then they are not shown (e.g. 2015-12-26T09:55:23). | ||
} | ||
|
||
SimpleDateFormat sdf; | ||
if (datetime.length() == 19) { | ||
sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); | ||
} else { | ||
sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); | ||
public static String toPairString(CurrencyPair currencyPair) { | ||
return currencyPair.counter.getCurrencyCode().toUpperCase() + "-" + currencyPair.base.getCurrencyCode().toUpperCase(); | ||
} | ||
sdf.setTimeZone(TimeZone.getTimeZone("UTC")); | ||
|
||
try { | ||
return sdf.parse(datetime); | ||
} catch (ParseException e) { | ||
logger.warn("Unable to parse datetime={}", datetime, e); | ||
return EPOCH; | ||
public static Date toDate(String date) { | ||
Calendar cal = DatatypeConverter.parseDateTime(date); | ||
cal.setTimeZone(TimeZone.getTimeZone(TIMEZONE)); | ||
return cal.getTime(); | ||
} | ||
} | ||
|
||
} |