dtg

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 28, 2023 License: MIT Imports: 6 Imported by: 1

README

Date Time Group parser

Go module (package dtg) for parsing and printing time.Time in Allied Communication Publication (ACP) 121 NATO Date Time Group (DTG) format.

Usage

Work in progress, more to come...

package main

import (
	"fmt"
	"log"
	"time"

	"github.com/sa6mwa/dtg"
)

func main() {
	shortDTG := `151337`
	longDTG := `151337JAPR31`
	err := dtg.Validate(shortDTG)
	if err != nil {
		log.Fatal(err)
	}
	err = dtg.Validate(longDTG)
	if err != nil {
		log.Fatal(err)
	}
	sd, err := dtg.Parse(shortDTG)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("Short DTG", shortDTG, "is represented in full as", sd.String())
	fmt.Println("DTG", shortDTG, "time is", sd.Time.Format(time.UnixDate))

	ld, err := dtg.Parse(longDTG)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("Long DTG", longDTG, "is represented in full as", ld)
	fmt.Println("DTG", longDTG, "time is", ld.Time.Format(time.UnixDate))

	newDtg := &dtg.DTG{}
	newDtg.Time = time.Now()
	fmt.Println("DTG now in your time zone is", newDtg, "or", newDtg.Time.Format(time.UnixDate))
}

Documentation

Overview

The dtg package parses and prints time.Time in Allied Communication Publication (ACP) 121 Date-Time Group (DTG) format. This package is Copyright (C) 2022 SA6MWA Michel Blomgren.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Index

Constants

This section is empty.

Variables

View Source
var (
	DtgRegexp                *regexp.Regexp = regexp.MustCompile(`^([0-9]{2})([0-9]{2})([0-9]{2})([A-Z]{0,1})(JAN|FEB|MAR|APR|MAY|MAJ|JUN|JUL|AUG|SEP|OCT|OKT|NOV|DEC){0,1}([0-9]{2}){0,1}$`)
	ErrInvalidDTG            error          = errors.New("invalid DTG format (minimally ddHHMM to complete ddHHMMZmmmYY)")
	ErrInvalidTimeZoneLetter error          = errors.New("invalid time zone letter")
	ErrInvalidDtgVariadic    error          = errors.New("invalid DTG slice passed as variadic")
)

Functions

func GetNumericTimeZone

func GetNumericTimeZone(dtgTimeZoneLetter string, dayHourMinuteMonthYear ...string) (*time.Location, error)

Return a time.Location (and error) with the numeric time zone representation (e.g +0100 or -1100) of an ACP 121 time zone letter (A-Z). Name field will be the numeric time zone (to parse with -0700). The variadic dayHourMinuteMonthYear string slice (optional) will parse this into a time.Time to use instead of time.Now() for the local time zone letter J (to present a daylight saving - DST - compensated offset). There is a String() function in time.Location to extract the numeric time zone as name is non-exported.

UTC-12: Y (e.g., Fiji) UTC-11: X (American Samoa) UTC-10: W (Honolulu, HI) UTC-9: V (Juneau, AK) UTC-8: U (PST, Los Angeles, CA) UTC-7: T (MST, Denver, CO) UTC-6: S (CST, Dallas, TX) UTC-5: R (EST, New York, NY) UTC-4: Q (Halifax, Nova Scotia) UTC-3: P (Buenos Aires, Argentina) UTC-2: O (Godthab, Greenland) UTC-1: N (Azores) UTC+-0: Z (Zulu time) UTC+1: A (France) UTC+2: B (Athens, Greece) UTC+3: C (Arab Standard Time, Iraq, Bahrain, Kuwait, Saudi Arabia, Yemen, Qatar) UTC+4: D (Used for Moscow, Russia, and Afghanistan, however, Afghanistan is technically +4:30 from UTC) UTC+5: E (Pakistan, Kazakhstan, Tajikistan, Uzbekistan, and Turkmenistan) UTC+6: F (Bangladesh) UTC+7: G (Thailand) UTC+8: H (Beijing, China) UTC+9: I (Tokyo, Japan) UTC+10: K (Brisbane, Australia) UTC+11: L (Sydney, Australia) UTC+12: M (Wellington, New Zealand)

func Validate

func Validate(dtgString string) error

Validate attempts to parse the DTG string, discards the DTG object and returns error if parsing failed (invalid DTG) or nil (valid DTG).

Types

type DTG

type DTG struct {
	time.Time
}

func Parse

func Parse(dtgString string) (dtg DTG, err error)

Parse transforms a NATO (ACP 121 Communication Instructions General) Date Time Group into a time.Time object via the DTG struct. The String() function of the DTG object reproduces a full Date Time Group from the time.Time object.

func (DTG) String

func (dtg DTG) String() string

String returns a NATO ACP 121 Date Time Group of the DTG Time field.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL