source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_ISO8601_Util.ipf @ 1129

Last change on this file since 1129 was 1024, checked in by srkline, 6 years ago

minor changes to prefix functions with "V_" to avoid conflicts with non-VSANS functions.

File size: 2.4 KB
Line 
1#pragma rtGlobals=3             // Use modern global access method and strict wave access.
2
3//
4// The general format of the time string is:
5//  1901-01-01T12:00:00-0500
6// (note that the -0500 appears to be incorrect - should be -05:00
7//
8//   Complete date plus hours, minutes and seconds:
9//      YYYY-MM-DDThh:mm:ssTZD (eg 1997-07-16T19:20:30+01:00)
10//
11
12// What utilities do I need to have to interpret these times?
13
14// possible needs:
15// Convert to "Igor" time? (as a number for computation)
16// Find the elapsed time between two ISO times?
17// Convert "Igor" time to ISO time? (as a string for writing)
18//
19
20// What does Igor have built-in to work with...?
21//
22// Unfortunately, there are functions based on the Julian calendar
23// and the ISO standard uses the Gregorian calendar...
24//
25//¥print time()
26//  10:53:42 AM
27//¥print date()
28//  Wed, Oct 7, 2015
29//¥Print DateTime
30//  3.52706e+09
31//¥Print secs2date(DateTime,-2)
32//  2015-10-07
33//¥Print secs2time(DateTime,2)
34//  10:55
35//¥Print secs2time(DateTime,3)
36//  10:55:50
37
38
39
40// The two utilites are self-consistent, at least --
41// passing in an ISO time returns itself atfer comupting the "Igor" seconds
42//
43// print CurrentTime_to_ISO8601String(ISO8601_to_IgorTime("2015-10-07T11:04:26-05:00"))
44//
45
46//
47// Call w/ DateTime as the argument
48//
49// TODO -- verify that this is correct
50Function/S V_CurrentTime_to_ISO8601String(now)
51        Variable now
52       
53        String s1,s2,s3,ISOstr
54       
55        s3 = "-05:00"           // time zone string
56       
57        // Y-M-D
58        s1 = secs2date(now,-2)
59        //H:M:S
60        s2 = secs2time(now,3)
61
62        ISOstr = s1 + "T" + s2 + s3
63       
64        return(ISOstr)
65End
66
67//
68// takes the ISO time and converts it into "Igor" time
69// as if it was reported from DateTime:
70//
71// "The DateTime function returns number of seconds from 1/1/1904 to the current date and time."
72//
73// TODO -- verify that this is correct, since I'm not actually parsing the string, but rather
74// counting on the string to be EXACTLY the correct format
75//
76Function V_ISO8601_to_IgorTime(ISOstr)
77        String ISOstr
78       
79        Variable secs
80        String s1,s2
81        s1 = ISOstr[0,9]                //taking strictly the first 10 characters YYYY-MM-DD
82        s2 = ISOstr[11,18]              // skip the "T" and take the next 8 chars HH:MM:SS
83        // skip the time zone...
84        print s1
85        print s2
86       
87        Variable yr,mo,dy,hh,mm,ss
88        yr = str2num(s1[0,3])
89        mo = str2num(s1[5,6])
90        dy = str2num(s1[8,9])
91        hh = str2num(s2[0,1])
92        mm = str2num(s2[3,4])
93        ss = str2num(s2[6,7])
94
95        secs = date2secs(yr,mo,dy)
96        secs += hh*60*60
97        secs += mm*60
98        secs += ss
99       
100        return(secs)
101End
Note: See TracBrowser for help on using the repository browser.