epochconv

package module
v0.0.0-...-b3fe06b Latest Latest
Warning

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

Go to latest
Published: May 1, 2017 License: Apache-2.0 Imports: 7 Imported by: 0

README

A utility to convert epochs. Currently under development, things may not work.

Documentation to be completed.

Master Build Status

Develop Build Status

Documentation

Index

Constants

View Source
const CustomEpochTimeFormatString = "2006-01-02T15:04:05Z"

The example time formatting string fed to time parse method. This allows custom epochs to be calculated as long as the epoch's date format looks precisely like this string - YYYY-MM-DDTHH:MM:SSZ. All epochs in this file must follow this format.

Variables

View Source
var (
	EpochCommonEra = EpochType{
		EpochName:                   "CommonEra",
		EpochUses:                   []string{"Common Era", "ISO 2014", "RFC 3339", "Microsoft .NET", "Go", "REXX", "Rata Die"},
		EpochDateString:             dateStringCommonEra,
		EpochDate:                   sp(dateStringCommonEra),
		LocalRightNowInSecondsSince: te(dateStringCommonEra, false),
		UTCRightNowInSecondsSince:   te(dateStringCommonEra, true),
		Prevalence:                  1,
	}

	EpochUnix = EpochType{
		EpochName:                   "Unix",
		EpochUses:                   []string{"Unix", "Unix Variants (Linux, MacOS, Solaris, BSD, etc...)", "POSIX"},
		EpochDateString:             dateStringUnixEpoch,
		EpochDate:                   sp(dateStringUnixEpoch),
		LocalRightNowInSecondsSince: te(dateStringUnixEpoch, false),
		UTCRightNowInSecondsSince:   te(dateStringUnixEpoch, true),
		Prevalence:                  5,
	}

	EpochWindowsEpoch = EpochType{
		EpochName:                   "Windows",
		EpochUses:                   []string{"Windows", "NTFS", "COBOL"},
		EpochDateString:             dateStringWindowsEpoch,
		EpochDate:                   sp(dateStringWindowsEpoch),
		LocalRightNowInSecondsSince: te(dateStringWindowsEpoch, false),
		UTCRightNowInSecondsSince:   te(dateStringWindowsEpoch, true),
		Prevalence:                  5,
	}

	EpochVMS = EpochType{
		EpochName:                   "VMS",
		EpochUses:                   []string{"VMS", "United States Naval Observatory", "DVB SI 16-bit day stamps", "Astronomy-related"},
		EpochDateString:             dateStringVMSEpoch,
		EpochDate:                   sp(dateStringVMSEpoch),
		LocalRightNowInSecondsSince: te(dateStringVMSEpoch, false),
		UTCRightNowInSecondsSince:   te(dateStringVMSEpoch, true),
		Prevalence:                  3,
	}

	EpochMicrosoftCOM = EpochType{
		EpochName:                   "Microsoft COM",
		EpochUses:                   []string{"Microsoft COM DATE", "Object Pascal", "LibreOffice Calc", "Google Sheets", "Technical internal value used by Microsoft Excel"},
		EpochDateString:             dateStringMicrosoftCOM,
		EpochDate:                   sp(dateStringMicrosoftCOM),
		LocalRightNowInSecondsSince: te(dateStringMicrosoftCOM, false),
		UTCRightNowInSecondsSince:   te(dateStringMicrosoftCOM, true),
		Prevalence:                  4,
	}

	EpochMicrosoftExcel = EpochType{
		EpochName:                   "Microsoft Excel",
		EpochUses:                   []string{"Microsoft Excel", "Lotus 1-2-3"},
		EpochDateString:             dateStringMicrosoftExcel,
		EpochDate:                   sp(dateStringMicrosoftExcel),
		LocalRightNowInSecondsSince: te(dateStringMicrosoftExcel, false),
		UTCRightNowInSecondsSince:   te(dateStringMicrosoftExcel, true),
		Prevalence:                  3,
	}

	EpochNTP = EpochType{
		EpochName:                   "NTP",
		EpochUses:                   []string{"Network Time Protocol", "IBM CICS", "Mathematica", "RISC OS", "VME", "Common Lisp", "Michigan Terminal System"},
		EpochDateString:             dateStringNTP,
		EpochDate:                   sp(dateStringNTP),
		LocalRightNowInSecondsSince: te(dateStringNTP, false),
		UTCRightNowInSecondsSince:   te(dateStringNTP, true),
		Prevalence:                  2,
	}

	EpochMacClassic = EpochType{
		EpochName:                   "Mac Classic",
		EpochUses:                   []string{"Apple Inc.'s classic Mac OS, LabVIEW, Palm OS, MP4, Microsoft Excel (optionally), IGOR Pro"},
		EpochDateString:             dateStringMacClassic,
		EpochDate:                   sp(dateStringMacClassic),
		LocalRightNowInSecondsSince: te(dateStringMacClassic, false),
		UTCRightNowInSecondsSince:   te(dateStringMacClassic, true),
		Prevalence:                  2,
	}

	EpochFAT = EpochType{
		EpochName:                   "FAT",
		EpochUses:                   []string{"FAT12", "FAT16", "FAT32", "exFAT filesystems", "IBM BIOS", "INT 1Ah", "DOS", "OS/2"},
		EpochDateString:             dateStringMicrosoftFAT,
		EpochDate:                   sp(dateStringMicrosoftFAT),
		LocalRightNowInSecondsSince: te(dateStringMicrosoftFAT, false),
		UTCRightNowInSecondsSince:   te(dateStringMicrosoftFAT, true),
		Prevalence:                  5,
	}

	// This is very close to FAT
	EpochGPS = EpochType{
		EpochName:                   "GPS",
		EpochUses:                   []string{"Qualcomm BREW", "GPS", "ATSC 32-bit time stamps"},
		EpochDateString:             dateStringGPS,
		EpochDate:                   sp(dateStringGPS),
		LocalRightNowInSecondsSince: te(dateStringGPS, false),
		UTCRightNowInSecondsSince:   te(dateStringGPS, true),
		Prevalence:                  2,
	}
	// This epoch is very close to OS X epoch
	EpochPostgreSQL = EpochType{
		EpochName:                   "PostgreSQL",
		EpochUses:                   []string{"PostgreSQL", "AppleSingle", "AppleDouble", "ZigBee UTCTime"},
		EpochDateString:             dateStringPostgreSQL,
		EpochDate:                   sp(dateStringPostgreSQL),
		LocalRightNowInSecondsSince: te(dateStringPostgreSQL, false),
		UTCRightNowInSecondsSince:   te(dateStringPostgreSQL, true),
		Prevalence:                  3,
	}

	EpochMacOSX = EpochType{
		EpochName:                   "Mac OS X",
		EpochUses:                   []string{"OS X, Apple Cocoa"},
		EpochDateString:             dateStringMacOSX,
		EpochDate:                   sp(dateStringMacOSX),
		LocalRightNowInSecondsSince: te(dateStringMacOSX, false),
		UTCRightNowInSecondsSince:   te(dateStringMacOSX, true),
		Prevalence:                  5,
	}
	AllEpochs = EpochCollection{EpochCommonEra, EpochWindowsEpoch, EpochVMS, EpochMicrosoftCOM, EpochMicrosoftExcel,
		EpochNTP, EpochMacClassic, EpochUnix, EpochFAT, EpochGPS, EpochPostgreSQL, EpochMacOSX}
)

Functions

func NumbersInStrings

func NumbersInStrings(stringsToClean []string) (numbersOnly []string)

Given a slice of strings which could have integer data, create a new slice of only numbers in any of the strings

Types

type ByEpochDate

type ByEpochDate EpochCollection

Satisfy the sort.Interface for the collection type so it can be sort.Sort'ed - like sort.Sort(ByEpochDate(ec))

func (ByEpochDate) Len

func (a ByEpochDate) Len() int

func (ByEpochDate) Less

func (a ByEpochDate) Less(i, j int) bool

func (ByEpochDate) Swap

func (a ByEpochDate) Swap(i, j int)

type ByNearestDate

type ByNearestDate EpochCollection

func (ByNearestDate) Len

func (a ByNearestDate) Len() int

func (ByNearestDate) Less

func (a ByNearestDate) Less(i, j int) bool

func (ByNearestDate) Swap

func (a ByNearestDate) Swap(i, j int)

type EpochCollection

type EpochCollection []EpochType

func (EpochCollection) GuessesForStrings

func (ec EpochCollection) GuessesForStrings(stringsToConvert []string) (epochResults []EpochResults, badStrings []string, err error)

GuessesForStrings is a method on any EpochCollection, which can be constructed to pick and choose relevant or custom EpochTypes. Given a slice of strings, return an EpochGuessResults type, which is an array of EpochResults along with the most likely result. Strings in the input slice are parsed in the following way:

  1. Strings are stripped of leading and trailing whitespace characters.
  2. Strings have all data after the first dot character removed. This allows for input of decimal numbers Without needing to convert to floats.

If one string cannot be converted, an Error is created indicating at least one string could not be converted. These strings are returned in the badStrings slice. This can, of course, be ignored - and may be in a typical use case.

func (EpochCollection) OrderedEpochsByClosestMatch

func (ec EpochCollection) OrderedEpochsByClosestMatch(number int64, matchToTime time.Time) (ecOut EpochCollection)

OrderedEpochsByClosestMatch is a Method on an EpochCollection. Given an EpochCollection, typically AllEpochs, return a collection order by closest match of an epoch number given a date to convert to all epoch seconds. Do not alter the collection slice order in-place but, instead, return the sorted EpochCollection. The first item in the returned Collection is the closest match, and matches are less likely at the end of the slice.

Create your own EpochCollection by hand to add and remove existing or custom epochs.

func (EpochCollection) String

func (ec EpochCollection) String() (out string)

String satisfies the Stringer interface, so this is printed when %s is used in a formatting string for this type.

func (EpochCollection) ToJson

func (ec EpochCollection) ToJson() (string, error)

type EpochResults

type EpochResults struct {
	InputNumber    int64           `json:"input_number"`
	EpochTypes     EpochCollection `json:"epoch_types"`
	AllResults     []epochResult   `json:"all_results"`
	MostLikelyType EpochType       `json:"most_likely_epoch"`
}

func GuessesForStrings

func GuessesForStrings(stringsToConvert []string) (epochResults []EpochResults, badStrings []string, err error)

Given a slice of strings, return a slice of EpochGuessResults type, each of which is an array of EpochResults along with the most likely result. Strings in the input slice are parsed in the following way:

  1. Strings are stripped of leading and trailing whitespace characters.
  2. Strings have all data after the first dot character removed. This allows for input of decimal numbers Without needing to convert to floats.

If one string that seemed to match a number cannot be converted, an Error is returned. However, the numbers that were convertible are still returned. Ignore the error and continue, if desired.

type EpochType

type EpochType struct {
	EpochName                   string    `json:"epoch_name"` // Friendly name of epoch
	EpochUses                   []string  `json:"epoch_uses"` // Slice of common uses of this specific epoch
	EpochDateString             string    `json:"-"`          // The date string formatted like CustomEpochTimeFormatString that defines this
	EpochDate                   time.Time `json:"epoch_date"` // The time.Time date representation of the epoch start
	LocalRightNowInSecondsSince int64     `json:"now_local"`  // time.Now().Local - Local time in seconds since epoch start.
	UTCRightNowInSecondsSince   int64     `json:"now_utc"`    // time.Now().UTC - UTC time in seconds since epoch start.
	Prevalence                  int       `json:"prevalence"` // 0-5, 0 being least common. Helps decide most likely matches when it's close.
}

Skeletal type

func (*EpochType) DateForNumber

func (e *EpochType) DateForNumber(epochSeconds int64, utcFlag bool) (timeInEpoch time.Time)

DateForNumber is a method on an EpochType. Given a number (in seconds), return the date (as time.Time) for the epoch

func (*EpochType) NumberForDate

func (e *EpochType) NumberForDate(date time.Time) int64

NumberForDate is a method on an EpochType. Given a date (as time.Time), return the seconds since that epoch.

func (EpochType) String

func (e EpochType) String() string

String satisfies the Stringer interface, so this is printed when %s is used in a formatting string for this type.

func (EpochType) ToJson

func (e EpochType) ToJson() (string, error)

String satisfies the Stringer interface, so this is printed when %s is used in a formatting string for this type.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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