npm package: @kakilangit/unix-time
Description: WebAssembly bindings for Unix Time Converter tool
Latest version: 0.2.0

# @kakilangit/unix-time

WebAssembly bindings for Unix Time Converter tool.

## Overview

This package provides Unix timestamp conversion functionality compiled to WebAssembly from Rust. It converts timestamps between various formats and timezones with support for the full IANA timezone database.

## Installation

```bash
npm install @kakilangit/unix-time
```

## Usage

```javascript
import init, { 
  convert_unix_time, 
  get_current_timestamp_seconds, 
  get_current_timestamp_millis,
  get_available_timezones,
  TimeUnit 
} from '@kakilangit/unix-time';

// Initialize the WASM module
await init();

// Convert a Unix timestamp (seconds)
const result = convert_unix_time("1705315800", TimeUnit.Seconds, "UTC");
console.log(result.unix_seconds);    // 1705315800
console.log(result.unix_millis);     // 1705315800000
console.log(result.utc_iso);         // "2024-01-15T12:30:00Z"
console.log(result.utc_rfc2822);     // "Mon, 15 Jan 2024 12:30:00 GMT"

// Localized time with timezone info
console.log(result.localized.timezone);       // "UTC"
console.log(result.localized.abbreviation);   // "UTC"
console.log(result.localized.offset);         // "+0000"
console.log(result.localized.datetime);       // "2024-01-15 12:30:00"
console.log(result.localized.iso);            // "2024-01-15T12:30:00+00:00"

// Date/time components
console.log(result.localized.components.year);        // 2024
console.log(result.localized.components.month);       // 1
console.log(result.localized.components.day);         // 15
console.log(result.localized.components.hour);        // 12
console.log(result.localized.components.minute);      // 30
console.log(result.localized.components.second);      // 0
console.log(result.localized.components.weekday);     // "Mon"
console.log(result.localized.components.month_name);  // "Jan"

// Convert with different timezone
const nyTime = convert_unix_time("1705315800", TimeUnit.Seconds, "America/New_York");
console.log(nyTime.localized.offset); // "-0500"

// Convert milliseconds
const millisResult = convert_unix_time("1705315800123", TimeUnit.Millis, "UTC");

// Get current timestamps
const nowSeconds = get_current_timestamp_seconds();
const nowMillis = get_current_timestamp_millis();

// List available timezones
const timezones = get_available_timezones();
console.log(timezones); // ["UTC", "America/New_York", "Europe/London", ...]
```

## API

### Functions

#### `convert_unix_time(timestamp, unit, timezone)`
Converts a Unix timestamp to human-readable formats.

- `timestamp` (string): The timestamp value as string
- `unit` (TimeUnit): The unit of the timestamp
- `timezone` (string): IANA timezone identifier (e.g., "UTC", "America/New_York")

Returns `TimeResult`:
- `original`: Original input timestamp
- `unix_seconds`: Unix timestamp in seconds
- `unix_millis`: Unix timestamp in milliseconds
- `utc_iso`: UTC time in ISO 8601 format
- `utc_rfc2822`: UTC time in RFC 2822 format
- `localized`: Localized time display object
  - `timezone`: Timezone IANA identifier
  - `abbreviation`: Timezone abbreviation (e.g., "EST", "CET")
  - `offset`: Offset from UTC (e.g., "+0100", "-0500")
  - `datetime`: Formatted date and time (YYYY-MM-DD HH:MM:SS)
  - `iso`: ISO 8601 format with offset
  - `rfc2822`: RFC 2822 format
  - `components`: Individual date/time components
    - `year`, `month`, `day`, `hour`, `minute`, `second`
    - `weekday`: Short weekday name (e.g., "Mon")
    - `month_name`: Short month name (e.g., "Jan")

#### `get_current_timestamp_seconds()`
Returns the current Unix timestamp in seconds.

#### `get_current_timestamp_millis()`
Returns the current Unix timestamp in milliseconds.

#### `get_available_timezones()`
Returns all available IANA timezone identifiers from the bundled database.

### Enums

#### `TimeUnit`
- `Seconds = 0` - Seconds since Unix epoch (January 1, 1970)
- `Millis = 1` - Milliseconds since Unix epoch

## Timezone Support

This package includes the full IANA timezone database, supporting:
- All global timezones (UTC, GMT, etc.)
- Regional timezones (America/New_York, Europe/London, Asia/Tokyo, etc.)
- Historical timezone data and DST transitions

## Features

- Accurate timestamp conversion using jiff library
- Full IANA timezone database support
- Automatic DST handling
- Multiple output formats (ISO 8601, RFC 2822, components)
- WASM-compatible time retrieval via JavaScript Date

## License

MIT