Skip to content

Latest commit

 

History

History
245 lines (181 loc) · 13 KB

README.md

File metadata and controls

245 lines (181 loc) · 13 KB

VS Code Time Converter — timing

Version Downloads Ratings Stars
License Lint, Test, Bundle and Deploy Coverage Status

Description

The timing extension converts and visualizes a given time to various formats. You can invoke all commands via the command palette (sample). In addition, you can just hover over an epoch timestamp in the editor to get a human readable preview of that timestamp (sample).

To view all commands, open the command palette and type Timing.

This extension was inspired by zodiac403's epoch-time-converter.

All breaking changes of v2.0.0 are listed in the changelog

Installation

Via Visual Studio Code

  1. Press Ctrl + P to open the Go to File... view
  2. Type ext install HaaLeo.timing and press Enter

From VSIX

  1. Download the .vsix file of the latest release from GitHub
  2. Run code --install-extension timing-*.*.*.vsix in the command line (reference)

Features

Currently this extension is capable to do the following conversions, where the epoch time can be formated in seconds, milliseconds, microseconds or nanoseconds, and custom is a localized momentjs format, that you can specify in the settings or insert during the conversion. Epoch times can be converted to a human readable timestamp or duration.

Source Format Target Format Example
Epoch (s, ms, μs, ns) ISO 8601 UTC Link
Epoch (s, ms, μs, ns) ISO 8601 Custom Timezone
Epoch (s, ms, μs, ns) ISO 8601 Local
Epoch (s, ms, μs, ns) Custom
Epoch (s, ms, μs, ns) Custom Format and Timezone
Epoch (s, ms, μs, ns) ISO 8601 Duration
Epoch (s, ms, μs, ns) Human Readable Duration
Epoch (s, ms, μs, ns) Gps Epoch
ISO 8601 Duration Epoch (s, ms, μs, ns)
ISO 8601 / RFC 2282 Epoch (s, ms, μs, ns)
ISO 8601 / RFC 2282 Custom Link
- Now as Epoch (s, ms, μs, ns)
- Now as ISO 8601 UTC
- Now as ISO 8601 Local Link
- Now as Custom
Custom Custom
Custom Epoch (s, ms, μs, ns)
Custom ISO 8601 UTC
Custom ISO 8601 Local

Whether the current selection is replaced with the converted time, is indicated by the timing.insertConvertedTime setting. When you already pre-selected a valid epoch time, the extension will directly convert this selection instead of asking for your input.

When the epoch time is the source format of the timestamp conversion its unit is determined by its digit count:

Minimum Length Maximum Length Used Unit
1 11 s
12 14 ms
15 17 μs
18 21 ns

Note: Those boundaries are set with the timing.epochConversionBoundaries setting.

When the epoch time is the target format of the timestamp conversion you can select its unit during the conversion process.

When the epoch time is the source format of the duration conversion you can select its unit during the conversion process.

Further the extension shows a hover preview of the converted timestamp and duration when the mouse is moved over a valid epoch time.

Settings Overview

  • timing.clipboard.readingEnabled: Indicates whether the extension should try to get the input time from the clipboard instead of asking the user for input.

  • timing.clipboard.writingEnabled: Indicates whether the result of the conversion is written to the clipboard. When enabled, no result view will be shown.

  • timing.customFormats: An array of custom source/target formats used to convert from/to.

  • timing.epochConversionBoundaries: Distinguish when to consider an epoch timestamp's unit as "seconds", "milliseconds", "microseconds" or "nanoseconds".

  • timing.hideResultViewOnEnter: Indicates whether the result view is hidden when enter is pressed. When set to false the command will restart.

  • timing.hiddenCommands: An array of commands that shall be hidden from the command palette.

  • timing.hoverDuration.enabled: Controls whether the duration hover is enabled or disabled.

  • timing.hoverDuration.sourceUnit: Indicates the source epoch unit for the duration hover preview. It can be either "s", "ms", "μs" or "ns".

  • timing.hoverDuration.useISOTargetFormat: Indicates whether the ISO 8601 duration definition is used as target format for the hover.

  • timing.hoverTimestamp.enabled: Controls whether the timestamp hover is enabled or disabled.

  • timing.hoverTimestamp.targetFormat: Indicates the target format of the hover preview. Possible values are an array of:

    • utc: Show the hover preview in ISO 8601 UTC time. This is the default value.
    • local: Show the hover preview in ISO 8601 Local time.
    • A custom momentjs format: For instance LLLL.

    In addition, you can specify a custom format via an object. When doing so, you can add further options like the target timezone. E.g.:

    {
        "timing.hoverTimestamp.targetFormat": [
            "local",
            "utc",
            "DD.MM.YYYY HH:mm:ss",
            {
                "customFormat": "DD.MM.YYYY HH:mm:ss",
                "timezone": "Europe/Berlin",
                "name": "My Format"
            }
        ]
    }
  • timing.ignoreFocusOut: Indicates whether the input boxes remain visible when the focus is lost.

  • timing.insertConvertedTime: Indicates whether a converted time is inserted at the cursor's current position after conversion. When enabled, no result view is shown.

Command Overview

To view all commands, open the command palette and type Timing.
Optional arguments can be used to reduce the amount of required user inputs during a conversion. They can only be used when the command is invoked via a hotkey.

Command Id Description Optional Arguments (string)
timing.customToCustom Custom ⟶ Custom sourceFormat, targetFormat
timing.customToEpoch Custom ⟶ Epoch sourceFormat, targetUnit
timing.customToIsoLocal Custom ⟶ ISO 8601 Local sourceFormat
timing.customToIsoUtc Custom ⟶ ISO 8601 UTC sourceFormat
timing.epochToCustom Epoch ⟶ Custom targetFormat
timing.epochToCustomTimezone Epoch ⟶ Custom Timezone targetFormat, timezone
timing.epochToIsoDuration Epoch ⟶ ISO 8601 Duration sourceUnit
timing.epochToIsoLocal Epoch ⟶ ISO 8601 Local
timing.epochToIsoTimezone Epoch ⟶ ISO 8601 Custom Timezone timezone
timing.epochToIsoUtc Epoch ⟶ ISO 8601 UTC
timing.epochToReadableDuration Epoch ⟶ Readable Duration sourceUnit
timing.epochToGps Epoch ⟶ GPS
timing.isoDurationToEpoch ISO 8601 Duration ⟶ Epoch targetUnit
timing.isoRfcToCustom ISO 8601 / RFC 2822 ⟶ Custom targetFormat
timing.isoRfcToEpoch ISO 8601 / RFC 2822 ⟶ Epoch targetUnit
timing.nowAsCustom Now ⟶ Custom targetFormat
timing.nowAsEpoch Now ⟶ Epoch targetUnit
timing.nowAsIsoLocal Now ⟶ ISO 8601 Local
timing.nowAsIsoUtc Now ⟶ ISO 8601 UTC
timing.toggleInsertConvertedTimeUserLevel toggle the timing.insertConvertedTime user setting

Keyboard Shortcuts

Any of the above commands can be bound to its own keyboard shortcut. For that just open the Keyboard Shortcuts view by pressing Ctrl+K Ctrl+S. Now search for the corresponding command and assign it to a shortcut.
Alternatively, you can edit the keybindings.json directly. For example you can add the following entry to the keybindings.json to bind the timing.customToEpoch to the keyboard shortcut Ctrl+K Ctrl+Z.

{
    "key": "ctrl+k ctrl+z",
    "command": "timing.customToEpoch"
}

Further if you know that you will always use the same parameter for the command you can add optional arguments.
Example:

{
    "key": "ctrl+k ctrl+z",
    "command": "timing.customToEpoch",
    "args": {
        "sourceFormat": "DD/MM/YYYY",
        "targetUnit": "ms"
    }
}

For further information check out the docs.

Contribution

If you found a bug or are missing a feature do not hesitate to file an issue.
Pull Requests are welcome!

Support

When you like this extension make sure to star the repo and write a review. I am always looking for new ideas and feedback.
In addition, it is possible to donate via paypal.

Examples

Conversion via Command Palette

Simple Conversion

In order to convert a time via the command palette there exist several commands. Each command will show up an input box where you can enter the time. After pressing Enter it will display the converted time in the input box again, ready to be copied.

Convert Sample

Pre-selection

If a valid time string is pre-selected, the command will directly convert the selection and show the corresponding result.

Convert Selection Sample

Options

If required, the command will ask you to select the target format of the time.

Convert Selection Option Sample

Current Time

In addition, you can also get the current time as epoch, ISO 8601, or custom format.

Now as ISO 8601 Local

Custom Formats

To convert different times from/to custom formats you need to insert a valid momentjs format after you invoke a corresponding command.

Convert To CustomSample

Optionally you can specify custom formats of the following shape in the user settings. Those will be shown as possible options.
Example:

{
    "timing.customFormats": [
        {
            "format": "LLLL",
            "description": "US",
            "detail": "Often used in the US"
        },
        {
            "format": "DD.MM.YYYY HH:mm:ss",
            "description": "GER",
            "detail": "Often used in Germany"
        }
    ]
}

Hover Preview

When you hover over a number the extension shows you the converted UTC, Local, or Custom timestamp and which unit was used for the conversion. The target time is indicated by the timing.hoverTimestamp.targetFormat setting. Its default value is utc. Further it also shows the converted duration.

Both hover provider can be configured via several settings

Hover Sample

Insert Converted Time

You can add the setting "timing.insertConvertedTime": true in order to automatically replace the cursor's selection with the converted time. When timing.insertConvertedTime is set to true, no result view will be shown. To enable that behavior there exists the command timing.toggleInsertConvertedTimeUserLevel to toggle this setting (on User Level).
Alternatively, you can press the pencil button in the top right corner of the result view.

  • "timing.insertConvertedTime": true
    Insert Sample 1
  • "timing.insertConvertedTime": false
    Insert Sample 2