Locking Time

Hi,

I am creating attendance software which is run on linux.
I have a problem that user doing the trick by reverse the system time manually

Is there anyway to avoid this. I was trying to use,

Dim berlinTZ As New Xojo.Core.TimeZone("Asia/Jakarta")

Dim berlinDate As New Xojo.Core.Date(Xojo.Core.Date.Now.Year, _
Xojo.Core.Date.Now.Month, _
Xojo.Core.Date.Now.Day, _
Xojo.Core.Date.Now.Hour, _
Xojo.Core.Date.Now.Minute, berlinTZ)

Dim interval As Xojo.Core.DateInterval
interval = Xojo.Core.Date.Now - berlinDate

MsgBox str(berlinTZ)

but seems not to work on xojo 2018r4 and xojo 2021r1

any helps?

thanks
Arief

How does this detect if the user changed the system clock? In both cases, it reads from the system clock? If you want to see if the clock has changed you either need to:

  • Access an external time source, e.g. http://worldtimeapi.org/api/timezone/Asia/Jakarta.txt (but you have to have internet connectivity)
  • Keep a hidden file with something like the SecondsSince1970 and check to see if you’ve gone backwards at any point (this is tricky for a number of reasons)

Yes,
this is the one,

http://worldtimeapi.org/api/timezone/Asia/Jakarta.txt

but how to get the date time only?

the software has an internet connection.

the goals is, just print the actual date and time from the internet, I dont want to use Cumputer local system date.

thanks
arief

Use URLConnection to get the time from Time API

Yes, This is the one.
but how to get only the daeTime Pattern only?

thanks
arief

You could either parse the .txt for the unixtime line, or get the json from here: http://worldtimeapi.org/api/timezone/Asia/Jakarta.json

Load the JSON into a JSONItem, get the unixtime key value and create a new DateTime using the secondsFrom1970 constructor.

// Urlconnection1 is a URLConnection on a DesktopWindow
// TextField1 has the user entered IANA timezone name

URLConnection1.ClearRequestHeaders ' Need to do this for multiple uses
URLConnection1.RequestHeader("Accept") = "application/json" ' Want JSON back
Var Result As String = URLConnection1.SendSync("GET", "https://www.timeapi.io/api/TimeZone/zone?timeZone=" + TextField1.Text, 60) ' Get the data from the API
Var d As Dictionary = ParseJSON(Result) ' Convert JSON to a dictionary
Var sDateTime As String = d.Value("currentLocalTime") ' Extract the current time value
// Convert to sqldatetime
Var sqlDateTime As String
sqlDateTime = sDateTime.Left(10) ' Date
sqlDateTime = sqlDateTime + " "
sqlDateTime = sqlDateTime + sDateTime.Middle(11, 8) ' Time

Var dt As DateTime = DateTime.FromString(sqlDateTime, Nil, Nil) ' Create a DateTime object using fromstring

Label3.Text = dt.ToString(DateTime.FormatStyles.Short, DateTime.FormatStyles.Long) ' Output the DateTime object string value to a label
3 Likes

Thanks a lot.

Its worked now.

regards,
arief