Operations¶
Every operation returns a new dateconv object. Therefore you can combine/concatenate any of the following operations and formatting options.
Arithmetic Operations¶
The arithmetic operations plus
and minus
are supported.
obj, _ := dateconv.NewConversion("2022-09-10 14:17:00", "datetime", "")
obj.Plus(180).Timestr("", false)
// 142000
obj, _ := dateconv.NewConversion("2022-09-10 14:17:00", "datetime", "")
obj.Minus(120).Timestr("", false)
// 141500
Comparisons¶
You can easily compare two dateconv objects by using the following methods:
Method | Meaning |
---|---|
Equal | left expression is equal to right expression |
NotEqual | left expression is not equal to right expression |
GreaterThan | left expression is greater than right expression |
Greater | left expression is greater right expression |
LowerThan | left expression is lower than right expression |
Lower | left expression is lower right expression |
The result of a comparison is a boolean expression (true or false). Both expressions need to be in dateconv format.
left = dateconv.NewConversion("2022-01-01", "date", "")
right = dateconv.NewConversion("2022-01-01", "date", "")
if left.Equal(right):
fmt.Println("Equal")
// Equal
Substitutions¶
You can substitute strings containing defined keywords. The table below gives an overview of the allowed substitutions.
Keyword | Description |
---|---|
YYYY | Year (4-digit) |
YY | Year (2-digit) |
mm | Month |
DD or DOM | Day of the month |
DDD or DOY | Day of the year |
DOW | Day of the week (short version) |
DOWL | Day of the week (long version) |
HH | Hour of the day |
H | Hour as upper case letter |
h | Hour as lower case letter |
MM | Minute of the day |
SS | Seconds of the day |
ssssss | Microseconds of the day |
sssssssss | Nanoseconds of the day |
GPSW | GPS week (int) |
GPSW0 | GPS week (padded with zeros) |
GPSD | GPS day of the week (int) |
SSSSSS | GPS seconds of the week |
SSSSS | GPS seconds of the day |
MJD | Modified Julian Date (without fraction) |
MJDF | Modified Julian Date (with fraction) |
UNIX | UNIX seconds |
UNIM | UNIX seconds with microsecond resolution |
UNIN | UNIX seconds with nanosecond resolution |
By calling the method Dictionary
you will receive a dictionary with all elements listed above.
obj, _ := dateconv.NewConversion("2022-09-10 14:17:12.020", "datetime", "")
obj.Dictionary()
//
// 'YYYY': '2022'
// 'YY': '22'
// 'mm': '09'
// 'DD': '10'
// 'HH': '14'
// 'H': 'O'
// 'h': 'o'
// 'MM': '17'
// 'SS': '12'
// 'ssssss': '020000'
// 'SSSS': '1032'
// 'SSSSS': '51432'
// 'SSSSSS': '569832'
// 'DOM': '10'
// 'DDD': '253'
// 'DOY': '253'
// 'DOW': 'Saturday'
// 'GPSW': 2226
// 'GPSW0': '2226'
// 'GPSD': 6
// 'MJD': 59832
// 'MJDF': 59832.59527777778
// 'UNIX': 1662819432
Now that you know what kind of elements you can substitute, we can try to create a RINEX v.3 filename. We need to put the keywords into curly brackets.
obj, _ := dateconv.NewConversion("2022-09-10 12:30:00", "datetime", "")
filename := "POTS00DEU_R_{YYYY}{DDD}{HH}{MM}_01H_30S_MO.rnx"
obj.Substitute(filename)
// POTS00DEU_R_{YYYY}{DDD}{HH}{MM}_20222531230_01H_30S_MO.rnx
Rounding¶
A given datetime can be rounded up or down to the pattern or seconds given.
The default round direction is down
.
Options for the parameter pattern
are:
Pattern | Description |
---|---|
week | rounds off to the start of the GPS week |
day | rounds off to the full day |
hour | rounds off to the full hour |
rounds off to |
|
rounds off to |
Range¶
You can create a range of dateconv objects by passing the end time and a pattern as defined in Rounding. The start time will be rounded down to the pattern given.