I know that The etc area time zone boundaries are meridians 15° apart with Longitude;
eg:
ETC/GMT (-7,7)
ETC/GMT -1 (7,15)
...
so i need write a code with a switch or a if-else format;
Is there a simple and pretty code to get it with just a single parmeter "longitude"?
Thanks
Related
I am working on a project that uses a different timezone than the one I currently live in:
moment.tz.add("Asia/Seoul|LMT KST JST KST KDT KDT|-8r.Q -8u -90 -90 -9u -a0|0123141414141414135353|-2um8r.Q 97XV.Q 1m1zu kKo0 2I0u OL0 1FB0 Rb0 1qN0 TX0 1tB0 TX0 1tB0 TX0 1tB0 TX0 2ap0 12FBu 11A0 1o00 11A0|23e6")
Then formatted it as such:
const kST = moment().tz('Asia/Seoul').format("HH:mm");
Now I want to be able to subtract a year from that. Looking at examples of how to do that I found something like var foo = moment(blah, "HH:mm).subtract(1, "years")
I assumed that since I already defined the moment with the 'const kST' I could simply substitute "kST" for "moment" as such:
const firstTimeConverted = kST(firstBus, "HH:mm").subtract(1, "years");
Unfortunately that doesn't work. Any thoughts how I might do this would be much appreciated.
In your code, kST isn't a function - it's a string. The format returns a string formatted as specified.
You probably want:
const firstTimeConverted = moment.tz(firstBus, "HH:mm", `Asia/Seoul`).subtract(1, "years");
This will parse the string in your firstBus variable in HH:mm format (such as "23:45"), and interpret as belonging to the Asia/Seoul time zone on the current date there. Then it will subtract a year and return the result as a moment object. If you want a string, you would then need to call the format function.
Both ftime and gettimeofday are returning 0 for the current timezone in Ubuntu 16. The timezone is set correctly in the date and time settings provided by Ubuntu. There is no TZ env variable set.
I don't want to just "fix" it because this is production software used in many different contexts. So I just want a reliable way of programmatically getting the timezone (and preferably the current DST offset as well).
My attempts so far:
#if 0
timeb tbTime;
ftime(&tbTime);
int CurTz = -tbTime.timezone;
#else
struct timeval tv;
struct timezone tz;
int r = gettimeofday(&tv, &tz);
if (r)
return NO_ZONE;
int CurTz = tz.tz_minuteswest;
#endif
The 'date' command is working:
matthew#mallen-ubuntu:~$ date +%Z
AEDT
matthew#mallen-ubuntu:~$ date +%z
+1100
I could just spawn a process to call "date", but that seems very heavy handed when some API calls are available.
On GNU/Linux, the second argument of gettimeofday is quite useless and should always be NULL. The manual page for gettimeofday says this:
The use of the timezone structure is obsolete; the tz argument should normally be specified as NULL.
Even on non-Linux systems, the tz_dsttime has useless semantics (e.g., it reports that India uses DST because it did so for a brief period about seventy years ago).
If you need to obtain the time zone for the current time, you need to use localtime or localtime_r and examine the broken-down time structure it produces (and not global variables such as daylight). The struct tm members you are probably interested are tm_isdst, tm_gmtoff, and perhaps tm_zone. The latter two are glibc extensions.
I am not able to understand what is the logic behind these lines:
COMPUTE temp = RESULT - 1.843E19.
IF temp IS LESS THAN 1.0E16 THEN
Data definition:
000330 01 VAR1 COMP-1 VALUE 3.4E38. // 3.4 x 10 ^ 38
Here are those lines in context (the sub-program returns a square root):
MOVE VAR1 TO PARM1.
CALL "SQUAREROOT_ROUTINE" USING
BY REFERENCE PARM1,
BY REFERENCE RESULT.
COMPUTE temp = RESULT - 1.843E19.
IF temp IS LESS THAN 1.0E16 THEN
DISPLAY "OK"
ELSE
DISPLAY "False"
END-IF.
These lines are just trying to test if the result returned by the SQUAREROOT_ROUTINE is correct. Since the program is using float-values and rather large numbers this might look a bit complicated. Let's just do the math:
You start with 3.4E38, the squareroot is 1.84390889...E19.
By subtracting 1.843E19 (i.e. the approximate result) and comparing the difference against 1.0E16 the program is testing whether the result is between 1.843E19 and 1.843E19+1.0E16 = 1.844E19.
Not that this test would not catch an error if the result from SQUAREROOT_ROUTINE was too low instead of too high. To catch both types of wrong results you should compare the absolute value of the difference against the tolerance.
You might ask "Why make things so complicated"? The thing is that float-values usually are not exact and depending on the used precision you will get sightly different results due to rounding-errors.
well the logic itself is very straight forward, you are subtracting 1.843*(10^19) from the result you get from the SQUAREROOT_ROUTINE and putting that value in the variable called temp and then If the value of temp is less than 1.0*(10^16) you are going to print a line out to the SYSOUT that says "OK", otherwise you are going to print out "False" (if the value was equal to or greater than).
If you mean the logic as to why this code exists, you will need to talk to the author of the code, but it looks like a debugging display that was left in the program.
I'm trying to parse the tzfile (Olson) format on a Unix system. In the tzfile(5) man page it states the following:
Then there are tzh_ttisstdcnt standard/wall indicators, each stored
as a one-byte value; they tell whether the transition times
associated with local time types were specified as standard time or
wall clock time, and are used when a timezone file is used in
handling POSIX-style timezone environment variables.
Finally, there are tzh_ttisgmtcnt UTC/local indicators, each stored
as a one-byte value; they tell whether the transition times
associated with local time types were specified as UTC or local time,
and are used when a timezone file is used in handling POSIX-style
timezone environment variables.
Does this mean I can ignore isstd and isgmt and still get the correct times? In spot checking, this seems to be the case but in digging around in the C source files, I see unix makes some adjustments dependant on these values.
As requested above, I asked on the mailing list. The answer was to look in the code. So the relevant code is in zic.c (zone compiler) and glib's tzfile.c. Source code for both can be found on github at the time of this wring. The relevant code for zic.c is
switch (lowerit(*ep)) {
case 's': /* Standard */
rp->r_todisstd = true;
rp->r_todisgmt = false;
*ep = '\0';
break;
case 'w': /* Wall */
rp->r_todisstd = false;
rp->r_todisgmt = false;
*ep = '\0';
break;
case 'g': /* Greenwich */
case 'u': /* Universal */
case 'z': /* Zulu */
rp->r_todisstd = true;
rp->r_todisgmt = true;
*ep = '\0';
break;
Which says there are 3 possible cases: isstd = true && isgmt = false, both false and both true. So to see what is done with these flags, the relevant code in tzfile.c is
if (trans_type->isgmt)
/* The transition time is in GMT. No correction to apply. */ ;
else if (isdst && !trans_type->isstd)
/* The type says this transition is in "local wall clock time", and
wall clock time as of the previous transition was DST. Correct
for the difference between the rule's DST offset and the user's
DST offset. */
transitions[i] += dstoff - rule_dstoff;
else
/* This transition is in "local wall clock time", and wall clock
time as of this iteration is non-DST. Correct for the
difference between the rule's standard offset and the user's
standard offset. */
transitions[i] += stdoff - rule_stdoff;
So this seems to say that if isgmt is true we can ignore everything else. If it is false then if the previous transition was DST and the current one is not standard (i.e. case 'w' above, as it's also not gmt) apply the dst offset (the last one found in the file). Otherwise apply the standard offset.
Which seems to mean that glibc ignores the offsets in the individual tt_types and case 's'. I looked in localtime.c in the tz package and it worked the same way.
I can only conclude from all this that most of the information in the tzfile isn't actually used anywhere. Some of this may be due to POSIX requirements. If anyone can expand on the details below, please do. It would be nice to have this behaviour documented somewhere on the internet besides in C source code.
I downloaded Conference Room Usage from outlook.
I want to know
How busy are the conference rooms?
What are the hot times?
Who are the super users?
Who are not the super users?
How many recurrent meetings take place.
This issue i'm having is that I need the duration between the "StartTime" and the "EndTime"; but they are currently strings!
start end starttime endtime
1/1/2014 1/1/2014 5:00:00 PM 5:00:00 PM
Also, it's likely safe to assume that StartTimes and EndTimes do not straddle two days, but perhaps I want to check for this.
Perhaps conversion to a 24-hour clock might help; "Duration" is then "EndTime" - "StartTime". How can i convert back to a 12-hour clock for the uninitiated. Finally, I need the day of the week (Monday, Tuesday, etc) an event falls on.
This can mostly be accomplished through the wizard.
some sudo code that should do the trick would be
COMPUTE Start=number(StartDate, ADATE10).
VARIABLE LEVEL Start (SCALE).
FORMATS Start (ADATE10).
VARIABLE WIDTH Start(10).
EXECUTE.
COMPUTE starttimetest=number(StartTime, TIME8).
VARIABLE LEVEL starttimetest (SCALE).
FORMATS starttimetest (TIME8).
VARIABLE WIDTH starttimetest(8).
EXECUTE.
compute teststartadd=start+starttimetest.
DO if index(starttime,'PM') gt 0 and subs(starttime,1,2) ne '12' .
COMPUTE Realstart=datesum(teststartadd,12,'hours').
ELSE.
COMPUTE REALstart=TESTstartADD.
END IF.
COMPUTE End=number(EndDate, ADATE10).
VARIABLE LEVEL End (SCALE).
FORMATS End (ADATE10).
VARIABLE WIDTH End(10).
EXECUTE.
COMPUTE endtimetest=number(endTime, TIME8).
VARIABLE LEVEL endtimetest (SCALE).
FORMATS endtimetest (TIME8).
VARIABLE WIDTH endtimetest(8).
EXECUTE.
compute testendadd=end+endtimetest.
DO if index(endtime,'PM') gt 0 and subs(endtime,1,2) ne '12' .
COMPUTE RealEnd=datesum(testendadd,12,'hours').
ELSE.
COMPUTE REALEND=TESTENDADD.
END IF.
exe.
delete vars Start
starttimetest
teststartadd
End
endtimetest
testendadd.
exe.
formats RealEnd RealStart(datetime23).
compute Length=datedif(realend,realstart,'hours').
if length > 12 check=1.
freq check.
compute StartWkDay=XDATE.WKDAY(realstart).
compute EndWkDay=XDATE.WKDAY(realEnd).
string StartDayText EndDayText(a8).
you'll have to convert using something like
*if XDATE.WKDAY(realstart)=1 startdaytext="Sunday".