dttm

package
v0.0.0-...-880cb89 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SafeForTestingRE        = regexp.MustCompile(`.*(\d{2}-[a-zA-Z]{3}-\d{4}_\d{2}-\d{2}-\d{2}.\d{6}).*`)
	HumanReadableRE         = regexp.MustCompile(`.*(\d{2}-[a-zA-Z]{3}-\d{4}_\d{2}:\d{2}:\d{2}).*`)
	HumanReadableOneDriveRE = regexp.MustCompile(`.*(\d{2}-[a-zA-Z]{3}-\d{4}_\d{2}-\d{2}-\d{2}).*`)
)

these regexes are used to extract time formats from strings. Their primary purpose is to identify the folders produced in external data during automated testing. For safety, each time format described above should have a matching regexp.

View Source
var (
	ErrNoTimeString = clues.New("no substring contains a known time format")
)

Functions

func ExtractTime

func ExtractTime(s string) (time.Time, error)

ExtractTime greedily retrieves a timestamp substring from the provided string. returns ErrNoTimeString if no match is found.

func Format

func Format(t time.Time) string

Format produces the standard format for corso time values. Always formats into the UTC timezone.

func FormatNow

func FormatNow(fmt TimeFormat) string

FormatNow produces the current time in UTC using the provided time format.

func FormatTo

func FormatTo(t time.Time, fmt TimeFormat) string

FormatTo produces the a datetime with the given format.

func FormatToHumanReadable

func FormatToHumanReadable(t time.Time) string

FormatToHumanReadable produces a simple datetime of the format "02-Jan-2006_15:04:05"

func FormatToLegacy

func FormatToLegacy(t time.Time) string

FormatToLegacy produces standard format for string values that are placed in SingleValueExtendedProperty tags

func FormatToTabularDisplay

func FormatToTabularDisplay(t time.Time) string

FormatToTabularDisplay produces the standard format for displaying a timestamp as part of user-readable cli output. "2016-01-02T15:04:05Z"

func Now

func Now() string

Now produces the current time as a string in the standard format.

func OrNow

func OrNow(t time.Time) time.Time

func ParseTime

func ParseTime(s string) (time.Time, error)

ParseTime makes a best attempt to produce a time value from the provided string. Always returns a UTC timezone value.

Types

type TimeFormat

type TimeFormat string
const (
	// Standard is the canonical format used for all data storage in corso
	Standard TimeFormat = time.RFC3339Nano

	// DateOnly is accepted by the CLI as a valid input for timestamp-based
	// filters.  Time and timezone are assumed to be 00:00:00 and UTC.
	DateOnly TimeFormat = "2006-01-02"

	// TabularOutput is used when displaying time values to the user in
	// non-json cli outputs.
	TabularOutput TimeFormat = "2006-01-02T15:04:05Z"

	// Legacy is used in /exchange/service_restore to comply with certain
	// graphAPI time format requirements.
	Legacy TimeFormat = time.RFC3339

	// HumanReadable is the default value appended to the root restoration folder name.
	HumanReadable TimeFormat = "02-Jan-2006_15:04:05"
	// HumanReadableDriveItem modifies SimpleDateTimeFormat to comply with onedrive folder
	// restrictions: primarily swapping `-` instead of `:` which is a reserved character.
	HumanReadableDriveItem TimeFormat = "02-Jan-2006_15-04-05"

	// m365 will remove the :00 second suffix on folder names, resulting in the following formats.
	ClippedHuman          TimeFormat = "02-Jan-2006_15:04"
	ClippedHumanDriveItem TimeFormat = "02-Jan-2006_15-04"

	// SafeForTesting is used for testing restore destination folders.
	// Microsecond granularity prevents collisions in parallel package or workflow runs.
	SafeForTesting TimeFormat = HumanReadableDriveItem + ".000000"

	// M365dateTimeTimeZoneTimeFormat is the format used by M365 for datetimetimezone resource
	// https://learn.microsoft.com/en-us/graph/api/resources/datetimetimezone?view=graph-rest-1.0
	M365DateTimeTimeZone TimeFormat = "2006-01-02T15:04:05.0000000"
)

Jump to

Keyboard shortcuts

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