# Class CivilTimeEncoder (3.29.0)

3.27.0 (latest) 3.24.0 3.23.0 3.21.0 3.20.0 3.19.1 3.18.0 3.17.3 3.16.3 3.15.3 3.14.1 3.12.0 3.11.4 3.10.3 3.9.3 3.8.0 3.6.1 3.5.2 3.4.0 3.3.1 3.2.0 3.1.0 3.0.1 2.47.0 2.45.0 2.44.1 2.43.0

    public final class CivilTimeEncoder

Ported from ZetaSQL CivilTimeEncoder Original code can be found at:
<https://github.com/google/zetasql/blob/master/java/com/google/zetasql/CivilTimeEncoder.java>
Encoder for TIME and DATETIME values, according to civil_time encoding.

The valid range and number of bits required by each date/time field is as the following:

| Field | Range | #Bits |
|---|---|---|
| Year | \[1, 9999\] | 14 |
| Month | \[1, 12\] | 4 |
| Day | \[1, 31\] | 5 |
| Hour | \[0, 23\] | 5 |
| Minute | \[0, 59\] | 6 |
| Second | \[0, 59\]\* | 6 |
| Micros | \[0, 999999\] | 20 |
| Nanos | \[0, 999999999\] | 30 |
[Range and bits for date/time fields]

\* Leap second is not supported.

When encoding the TIME or DATETIME into a bit field, larger date/time field is on the more
significant side.

## Inheritance

[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> CivilTimeEncoder

## Inherited Members

[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) [Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) [Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) [Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) [Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) [Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) [Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) [Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)

## Static Methods

### decodePacked64DatetimeMicros(long bitFieldDatetimeMicros)

    public static LocalDateTime decodePacked64DatetimeMicros(long bitFieldDatetimeMicros)

> [!WARNING]
> **Obsolete**
>
> *Use decodePacked64DatetimeMicrosLocalDateTime(long) instead*
>
> This feature is stable for usage in this major version, but may be deprecated in a future release.

This method is obsolete. Use [#decodePacked64DatetimeMicrosLocalDateTime(long)](https://docs.cloud.google.com/java/docs/reference/google-cloud-bigquerystorage/latest/com.google.cloud.bigquery.storage.v1.CivilTimeEncoder#com_google_cloud_bigquery_storage_v1_CivilTimeEncoder_decodePacked64DatetimeMicrosLocalDateTime_long_) instead.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `bitFieldDatetimeMicros` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `org.threeten.bp.LocalDateTime` |   |

### decodePacked64DatetimeMicrosLocalDateTime(long bitFieldDatetimeMicros)

    public static LocalDateTime decodePacked64DatetimeMicrosLocalDateTime(long bitFieldDatetimeMicros)

Decodes `bitFieldDatetimeMicros` as a [java.time.LocalDateTime](https://docs.oracle.com/javase/8/docs/api/java/time/LocalDateTime.html) with microseconds
precision.

Encoding is as the following:

        6         5         4         3         2         1

MSB 3210987654321098765432109876543210987654321098765432109876543210 LSB
\|--- year ---\|\|m \|\| D \|\| H \|\| M \|\| S \|\|---micros---\|

See Also: [#encodePacked64DatetimeMicros(LocalDateTime)](https://docs.cloud.google.com/java/docs/reference/google-cloud-bigquerystorage/latest/com.google.cloud.bigquery.storage.v1.CivilTimeEncoder#com_google_cloud_bigquery_storage_v1_CivilTimeEncoder_encodePacked64DatetimeMicros_org_threeten_bp_LocalDateTime_)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `bitFieldDatetimeMicros` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/time/LocalDateTime.html` |   |

### decodePacked64TimeMicros(long bitFieldTimeMicros)

    public static LocalTime decodePacked64TimeMicros(long bitFieldTimeMicros)

> [!WARNING]
> **Obsolete**
>
> *Use decodePacked64TimeMicrosLocalTime(long) instead*
>
> This feature is stable for usage in this major version, but may be deprecated in a future release.

This method is obsolete. Use [#decodePacked64TimeMicrosLocalTime(long)](https://docs.cloud.google.com/java/docs/reference/google-cloud-bigquerystorage/latest/com.google.cloud.bigquery.storage.v1.CivilTimeEncoder#com_google_cloud_bigquery_storage_v1_CivilTimeEncoder_decodePacked64TimeMicrosLocalTime_long_) instead.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `bitFieldTimeMicros` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `org.threeten.bp.LocalTime` |   |

### decodePacked64TimeMicrosLocalTime(long bitFieldTimeMicros)

    public static LocalTime decodePacked64TimeMicrosLocalTime(long bitFieldTimeMicros)

Decodes `bitFieldTimeMicros` as a [java.time.LocalTime](https://docs.oracle.com/javase/8/docs/api/java/time/LocalTime.html) with microseconds
precision.

Encoding is as the following:

        6         5         4         3         2         1

MSB 3210987654321098765432109876543210987654321098765432109876543210 LSB
\| H \|\| M \|\| S \|\|---micros---\|

See Also: [#encodePacked64TimeMicros(LocalTime)](https://docs.cloud.google.com/java/docs/reference/google-cloud-bigquerystorage/latest/com.google.cloud.bigquery.storage.v1.CivilTimeEncoder#com_google_cloud_bigquery_storage_v1_CivilTimeEncoder_encodePacked64TimeMicros_org_threeten_bp_LocalTime_)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `bitFieldTimeMicros` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/time/LocalTime.html` |   |

### encodePacked64DatetimeMicros(LocalDateTime dateTime)

    public static long encodePacked64DatetimeMicros(LocalDateTime dateTime)

> [!WARNING]
> **Obsolete**
>
> *Use encodePacked64DatetimeMicrosLocalDateTime(java.time.LocalDateTime) instead*
>
> This feature is stable for usage in this major version, but may be deprecated in a future release.

This method is obsolete. Use [#encodePacked64DatetimeMicrosLocalDateTime(java.time.LocalDateTime)](https://docs.cloud.google.com/java/docs/reference/google-cloud-bigquerystorage/latest/com.google.cloud.bigquery.storage.v1.CivilTimeEncoder#com_google_cloud_bigquery_storage_v1_CivilTimeEncoder_encodePacked64DatetimeMicrosLocalDateTime_java_time_LocalDateTime_) instead.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `dateTime` | `org.threeten.bp.LocalDateTime` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### encodePacked64DatetimeMicrosLocalDateTime(LocalDateTime dateTime)

    public static long encodePacked64DatetimeMicrosLocalDateTime(LocalDateTime dateTime)

Encodes `dateTime` as a 8-byte integer with microseconds precision.

Encoding is as the following:

        6         5         4         3         2         1

MSB 3210987654321098765432109876543210987654321098765432109876543210 LSB
\|--- year ---\|\|m \|\| D \|\| H \|\| M \|\| S \|\|---micros---\|

See Also: [#decodePacked64DatetimeMicros(long)](https://docs.cloud.google.com/java/docs/reference/google-cloud-bigquerystorage/latest/com.google.cloud.bigquery.storage.v1.CivilTimeEncoder#com_google_cloud_bigquery_storage_v1_CivilTimeEncoder_decodePacked64DatetimeMicros_long_)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `dateTime` | `https://docs.oracle.com/javase/8/docs/api/java/time/LocalDateTime.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### encodePacked64TimeMicros(LocalTime time)

    public static long encodePacked64TimeMicros(LocalTime time)

> [!WARNING]
> **Obsolete**
>
> *Use encodePacked64TimeMicrosLocalTime(java.time.LocalTime) instead*
>
> This feature is stable for usage in this major version, but may be deprecated in a future release.

This method is obsolete. Use [#encodePacked64TimeMicrosLocalTime(java.time.LocalTime)](https://docs.cloud.google.com/java/docs/reference/google-cloud-bigquerystorage/latest/com.google.cloud.bigquery.storage.v1.CivilTimeEncoder#com_google_cloud_bigquery_storage_v1_CivilTimeEncoder_encodePacked64TimeMicrosLocalTime_java_time_LocalTime_)
instead.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `time` | `org.threeten.bp.LocalTime` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### encodePacked64TimeMicrosLocalTime(LocalTime time)

    public static long encodePacked64TimeMicrosLocalTime(LocalTime time)

Encodes `time` as a 8-byte integer with microseconds precision.

Encoding is as the following:

        6         5         4         3         2         1

MSB 3210987654321098765432109876543210987654321098765432109876543210 LSB
\| H \|\| M \|\| S \|\|---micros---\|

See Also: [#decodePacked64TimeMicros(long)](https://docs.cloud.google.com/java/docs/reference/google-cloud-bigquerystorage/latest/com.google.cloud.bigquery.storage.v1.CivilTimeEncoder#com_google_cloud_bigquery_storage_v1_CivilTimeEncoder_decodePacked64TimeMicros_long_), [#encodePacked64TimeMicros(LocalTime)](https://docs.cloud.google.com/java/docs/reference/google-cloud-bigquerystorage/latest/com.google.cloud.bigquery.storage.v1.CivilTimeEncoder#com_google_cloud_bigquery_storage_v1_CivilTimeEncoder_encodePacked64TimeMicros_org_threeten_bp_LocalTime_)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `time` | `https://docs.oracle.com/javase/8/docs/api/java/time/LocalTime.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |