Fossil SCM
Document the timeline-utc setting. Provide C-language interfaces to access that setting consistently.
Commit
b1bb31e838138c8ee768abd63c149734abf8f9907e7ee6235d5d1bfaec655072
Parent
15df204706e2713…
1 file changed
+42
-16
M
src/db.c
+42
-16
| --- src/db.c | ||
| +++ src/db.c | ||
| @@ -1349,10 +1349,50 @@ | ||
| 1349 | 1349 | sqlite3_result_int64(context, rid); |
| 1350 | 1350 | } |
| 1351 | 1351 | } |
| 1352 | 1352 | } |
| 1353 | 1353 | |
| 1354 | + | |
| 1355 | +/* | |
| 1356 | +** SETTING: timeline-utc boolean default=on | |
| 1357 | +** | |
| 1358 | +** If the timeline-utc setting is true, then Fossil tries to understand | |
| 1359 | +** and display all time values using UTC. If this setting is false, Fossil | |
| 1360 | +** tries to understand and display time values using the local timezone. | |
| 1361 | +** | |
| 1362 | +** The word "timeline" in the name of this setting is historical. | |
| 1363 | +** This setting applies to all user interfaces of Fossil, | |
| 1364 | +** not just the timeline. | |
| 1365 | +** | |
| 1366 | +** Note that when accessing Fossil using the web interface, the localtime | |
| 1367 | +** used is the localtime on the server, not on the client. | |
| 1368 | +*/ | |
| 1369 | +/* | |
| 1370 | +** Return true if Fossil is set to display times as UTC. Return false | |
| 1371 | +** if it wants to display times using the local timezone. | |
| 1372 | +** | |
| 1373 | +** False is returned if display is set to localtime even if the localtime | |
| 1374 | +** happens to be the same as UTC. | |
| 1375 | +*/ | |
| 1376 | +int fossil_ui_utctime(void){ | |
| 1377 | + if( g.fTimeFormat==0 ){ | |
| 1378 | + if( db_get_int("timeline-utc", 1) ){ | |
| 1379 | + g.fTimeFormat = 1; /* UTC */ | |
| 1380 | + }else{ | |
| 1381 | + g.fTimeFormat = 2; /* Localtime */ | |
| 1382 | + } | |
| 1383 | + } | |
| 1384 | + return g.fTimeFormat==1; | |
| 1385 | +} | |
| 1386 | + | |
| 1387 | +/* | |
| 1388 | +** Return true if Fossil is set to display times using the local timezone. | |
| 1389 | +*/ | |
| 1390 | +int fossil_use_localtime(void){ | |
| 1391 | + return fossil_ui_utctime()==0; | |
| 1392 | +} | |
| 1393 | + | |
| 1354 | 1394 | /* |
| 1355 | 1395 | ** The toLocal() SQL function returns a string that is an argument to a |
| 1356 | 1396 | ** date/time function that is appropriate for modifying the time for display. |
| 1357 | 1397 | ** If UTC time display is selected, no modification occurs. If local time |
| 1358 | 1398 | ** display is selected, the time is adjusted appropriately. |
| @@ -1364,18 +1404,11 @@ | ||
| 1364 | 1404 | void db_tolocal_function( |
| 1365 | 1405 | sqlite3_context *context, |
| 1366 | 1406 | int argc, |
| 1367 | 1407 | sqlite3_value **argv |
| 1368 | 1408 | ){ |
| 1369 | - if( g.fTimeFormat==0 ){ | |
| 1370 | - if( db_get_int("timeline-utc", 1) ){ | |
| 1371 | - g.fTimeFormat = 1; | |
| 1372 | - }else{ | |
| 1373 | - g.fTimeFormat = 2; | |
| 1374 | - } | |
| 1375 | - } | |
| 1376 | - if( g.fTimeFormat==1 ){ | |
| 1409 | + if( fossil_ui_utctime() ){ | |
| 1377 | 1410 | sqlite3_result_text(context, "0 seconds", -1, SQLITE_STATIC); |
| 1378 | 1411 | }else{ |
| 1379 | 1412 | sqlite3_result_text(context, "localtime", -1, SQLITE_STATIC); |
| 1380 | 1413 | } |
| 1381 | 1414 | } |
| @@ -1393,18 +1426,11 @@ | ||
| 1393 | 1426 | void db_fromlocal_function( |
| 1394 | 1427 | sqlite3_context *context, |
| 1395 | 1428 | int argc, |
| 1396 | 1429 | sqlite3_value **argv |
| 1397 | 1430 | ){ |
| 1398 | - if( g.fTimeFormat==0 ){ | |
| 1399 | - if( db_get_int("timeline-utc", 1) ){ | |
| 1400 | - g.fTimeFormat = 1; | |
| 1401 | - }else{ | |
| 1402 | - g.fTimeFormat = 2; | |
| 1403 | - } | |
| 1404 | - } | |
| 1405 | - if( g.fTimeFormat==1 ){ | |
| 1431 | + if( fossil_ui_utctime() ){ | |
| 1406 | 1432 | sqlite3_result_text(context, "0 seconds", -1, SQLITE_STATIC); |
| 1407 | 1433 | }else{ |
| 1408 | 1434 | sqlite3_result_text(context, "utc", -1, SQLITE_STATIC); |
| 1409 | 1435 | } |
| 1410 | 1436 | } |
| 1411 | 1437 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -1349,10 +1349,50 @@ | |
| 1349 | sqlite3_result_int64(context, rid); |
| 1350 | } |
| 1351 | } |
| 1352 | } |
| 1353 | |
| 1354 | /* |
| 1355 | ** The toLocal() SQL function returns a string that is an argument to a |
| 1356 | ** date/time function that is appropriate for modifying the time for display. |
| 1357 | ** If UTC time display is selected, no modification occurs. If local time |
| 1358 | ** display is selected, the time is adjusted appropriately. |
| @@ -1364,18 +1404,11 @@ | |
| 1364 | void db_tolocal_function( |
| 1365 | sqlite3_context *context, |
| 1366 | int argc, |
| 1367 | sqlite3_value **argv |
| 1368 | ){ |
| 1369 | if( g.fTimeFormat==0 ){ |
| 1370 | if( db_get_int("timeline-utc", 1) ){ |
| 1371 | g.fTimeFormat = 1; |
| 1372 | }else{ |
| 1373 | g.fTimeFormat = 2; |
| 1374 | } |
| 1375 | } |
| 1376 | if( g.fTimeFormat==1 ){ |
| 1377 | sqlite3_result_text(context, "0 seconds", -1, SQLITE_STATIC); |
| 1378 | }else{ |
| 1379 | sqlite3_result_text(context, "localtime", -1, SQLITE_STATIC); |
| 1380 | } |
| 1381 | } |
| @@ -1393,18 +1426,11 @@ | |
| 1393 | void db_fromlocal_function( |
| 1394 | sqlite3_context *context, |
| 1395 | int argc, |
| 1396 | sqlite3_value **argv |
| 1397 | ){ |
| 1398 | if( g.fTimeFormat==0 ){ |
| 1399 | if( db_get_int("timeline-utc", 1) ){ |
| 1400 | g.fTimeFormat = 1; |
| 1401 | }else{ |
| 1402 | g.fTimeFormat = 2; |
| 1403 | } |
| 1404 | } |
| 1405 | if( g.fTimeFormat==1 ){ |
| 1406 | sqlite3_result_text(context, "0 seconds", -1, SQLITE_STATIC); |
| 1407 | }else{ |
| 1408 | sqlite3_result_text(context, "utc", -1, SQLITE_STATIC); |
| 1409 | } |
| 1410 | } |
| 1411 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -1349,10 +1349,50 @@ | |
| 1349 | sqlite3_result_int64(context, rid); |
| 1350 | } |
| 1351 | } |
| 1352 | } |
| 1353 | |
| 1354 | |
| 1355 | /* |
| 1356 | ** SETTING: timeline-utc boolean default=on |
| 1357 | ** |
| 1358 | ** If the timeline-utc setting is true, then Fossil tries to understand |
| 1359 | ** and display all time values using UTC. If this setting is false, Fossil |
| 1360 | ** tries to understand and display time values using the local timezone. |
| 1361 | ** |
| 1362 | ** The word "timeline" in the name of this setting is historical. |
| 1363 | ** This setting applies to all user interfaces of Fossil, |
| 1364 | ** not just the timeline. |
| 1365 | ** |
| 1366 | ** Note that when accessing Fossil using the web interface, the localtime |
| 1367 | ** used is the localtime on the server, not on the client. |
| 1368 | */ |
| 1369 | /* |
| 1370 | ** Return true if Fossil is set to display times as UTC. Return false |
| 1371 | ** if it wants to display times using the local timezone. |
| 1372 | ** |
| 1373 | ** False is returned if display is set to localtime even if the localtime |
| 1374 | ** happens to be the same as UTC. |
| 1375 | */ |
| 1376 | int fossil_ui_utctime(void){ |
| 1377 | if( g.fTimeFormat==0 ){ |
| 1378 | if( db_get_int("timeline-utc", 1) ){ |
| 1379 | g.fTimeFormat = 1; /* UTC */ |
| 1380 | }else{ |
| 1381 | g.fTimeFormat = 2; /* Localtime */ |
| 1382 | } |
| 1383 | } |
| 1384 | return g.fTimeFormat==1; |
| 1385 | } |
| 1386 | |
| 1387 | /* |
| 1388 | ** Return true if Fossil is set to display times using the local timezone. |
| 1389 | */ |
| 1390 | int fossil_use_localtime(void){ |
| 1391 | return fossil_ui_utctime()==0; |
| 1392 | } |
| 1393 | |
| 1394 | /* |
| 1395 | ** The toLocal() SQL function returns a string that is an argument to a |
| 1396 | ** date/time function that is appropriate for modifying the time for display. |
| 1397 | ** If UTC time display is selected, no modification occurs. If local time |
| 1398 | ** display is selected, the time is adjusted appropriately. |
| @@ -1364,18 +1404,11 @@ | |
| 1404 | void db_tolocal_function( |
| 1405 | sqlite3_context *context, |
| 1406 | int argc, |
| 1407 | sqlite3_value **argv |
| 1408 | ){ |
| 1409 | if( fossil_ui_utctime() ){ |
| 1410 | sqlite3_result_text(context, "0 seconds", -1, SQLITE_STATIC); |
| 1411 | }else{ |
| 1412 | sqlite3_result_text(context, "localtime", -1, SQLITE_STATIC); |
| 1413 | } |
| 1414 | } |
| @@ -1393,18 +1426,11 @@ | |
| 1426 | void db_fromlocal_function( |
| 1427 | sqlite3_context *context, |
| 1428 | int argc, |
| 1429 | sqlite3_value **argv |
| 1430 | ){ |
| 1431 | if( fossil_ui_utctime() ){ |
| 1432 | sqlite3_result_text(context, "0 seconds", -1, SQLITE_STATIC); |
| 1433 | }else{ |
| 1434 | sqlite3_result_text(context, "utc", -1, SQLITE_STATIC); |
| 1435 | } |
| 1436 | } |
| 1437 |