Efficiently encode dates and times into compact, human-readable strings - Now in Java AND TypeScript/JavaScript!
What is BitDT?
BitDT is a cross-platform library designed for space-efficient date-time encoding, supporting everything from ancient dates (50,000 BCE) to distant futures (176,980 CE). It uses bit packing and character encoding to compress date-time values into compact strings, making it ideal for storage, transmission, and logging where space matters.
GitHub Repository: (Github repo link)
Cross-Platform Support
BitDT is available in both Java and TypeScript/JavaScript with consistent APIs!
· Java: Full implementation with strong typing and memory optimization
· TypeScript/JavaScript: Same powerful encoding for web, Node.js, and browser applications
The API is completely consistent across both platforms, making it easy to share code and data structures between backend and frontend applications!
Key Features
· ✅ Ultra-compact encoding – Reduces date-time strings to minimal lengths
· ✅ Cross-platform consistency – Identical APIs in Java and TypeScript/JavaScript
· ✅ Millisecond precision – Supports full date-time down to the millisecond
· ✅ Optional timezone support – Handles UTC offsets like +05:30, -08, etc.
· ✅ Multiple date types – Full date-time, date-only, time-only, and empty values
· ✅ Zero compression – Efficiently encodes runs of zeros
· ✅ Epoch utilities – Convert between epoch milliseconds and BitDT strings
· ✅ Memory-efficient arrays – Store multiple BitDT values with minimal overhead
Consistent API Examples
Java Usage
// Create a BitDT instance
BitDT dt = BitDT.fromPrimitives(50000, 5, 15, 14, 30, 45, 123, "+08");
String encoded = dt.encode(); // Compact string
BitDT decoded = BitDT.decode(encoded);
// Epoch conversion
String now = BitDTEpoch.now();
long epoch = BitDTEpoch.fromBitDT(now);
TypeScript/JavaScript Usage
// Create a BitDT instance (identical API!)
const dt = BitDT.fromPrimitives(50000, 5, 15, 14, 30, 45, 123, "+08");
const encoded = dt.encode(); // Same compact string
const decoded = BitDT.decode(encoded);
// Epoch conversion (identical API!)
const now = BitDTEpoch.now();
const epoch = BitDTEpoch.fromBitDT(now);
Seamless Cross-Platform Data Exchange
One of the most powerful features of BitDT is seamless data exchange between Java backend and JavaScript frontend:
// Java backend
BitDT serverTime = BitDT.fromPrimitives(50000, 5, 15, 14, 30, 0, 0, "+00");
String encodedTime = serverTime.encode();
// Send to frontend: "KX3VW7A"
// JavaScript frontend
const clientTime = BitDT.decode("KX3VW7A");
console.log(clientTime.getHour()); // 14 - Same result!
No more format conversion headaches - the same compact string works identically everywhere!
Consistent Encoding Examples (Both Platforms)
Date-Time BitDT Encoding Length Java & JavaScript
2024-06-13 14:30:45.123 UTC KX3VW7A 7 chars ✅ Identical
Date-only (2024-06-13) KX3V 4 chars ✅ Identical
Time-only (14:30:45.123) W7A 3 chars ✅ Identical
Empty value & 1 char ✅ Identical
Guaranteed identical results in Java and JavaScript!
Full-Stack Example
Backend (Java Spring Boot)
@RestController
public class TimeController {
@GetMapping("/api/current-time")
public Map<String, String> getCurrentTime() {
String bitdt = BitDTEpoch.now();
return Map.of("time", bitdt); // {"time": "KX3VW7A"}
}
}
Frontend (TypeScript/React)
async function fetchTime() {
const response = await fetch('/api/current-time');
const data = await response.json();
const serverTime = BitDT.decode(data.time); // Same decoding logic!
console.log(`Server time: ${serverTime.encode()}`);
}
Mobile (React Native)
const storeLocalTime = () => {
const currentTime = BitDTEpoch.now(); // Same API!
AsyncStorage.setItem('lastSync', currentTime); // Compact storage
};
Consistent Testing Across Platforms
Both implementations include comprehensive test suites with identical test cases:
Java Tests:
BitDTTest.testBasicEncodingDecoding();
BitDTEpochTest.testNowFunction();
TypeScript Tests:
BitDTTest.testBasicEncodingDecoding();
BitDTEpochTest.testNowFunction();
Identical test cases ensure consistent behavior across both platforms.
Ideal Use Cases
Full-Stack Applications
· API payload reduction – Smaller date-time strings in JSON responses
· Real-time applications – Efficient WebSocket message formatting
· Mobile apps – Reduced storage footprint for timestamps
Microservices Architecture
· Service-to-service communication – Compact timestamps in event streams
· Database storage – Consistent temporal encoding across services
· Cross-language compatibility – Java services + Node.js APIs
Data Processing
· Log aggregation – Smaller log files with full precision
· Time-series databases – Efficient timestamp storage
· Analytics pipelines – Reduced bandwidth usage
Get Started
Java:
<dependency>
<groupId>com.danexcodr</groupId>
<artifactId>bitdt</artifactId>
<version>1.0.0</version>
</dependency>
TypeScript/JavaScript:
npm install bitdt
Explore the code and contribute:
github.com/DanexCodr/BitDT
BitDT brings consistent, space-efficient time encoding to your entire technology stack. Whether you're building enterprise Java applications or modern web apps, BitDT ensures your temporal data is always compact, fast, and perfectly consistent across platforms!