Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Code Samples & Tips > Additional Libraries
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Additional Libraries Users contributed libraries.
This sub-forum is only available to licensed users.

SysTime- Library

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-07-2007, 09:50 PM
Filippo's Avatar
Basic4ppc Expert
 
Join Date: May 2007
Location: Schwäb. Gmünd, Germany
Posts: 906
Awards Showcase
Beta Tester 
Total Awards: 1
Default SysTime- Library

Hi,

SysTime is a small library to get and set the current system time and system date.
There are two different dll's, one for the desktop and one for the device.

20.09.2009: Version 1.01


Ciao.
Filippo
Attached Files
File Type: zip SystemTime_v1.01.zip (11.4 KB, 165 views)
__________________
PPC: MDA Pro, 2GB SD
Device: HTC Desire , Android 2.2
______________________

Last edited by Filippo : 09-20-2009 at 02:43 PM. Reason: Update
Reply With Quote
  #2 (permalink)  
Old 10-08-2007, 11:45 AM
alfcen's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: Okinawa, Ryukyu Islands
Posts: 768
Send a message via Skype™ to alfcen
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Ciao Filippo,
Execellent! Awesome!

Thanks to your DLL, I can set the clock with GPS date and time.
Here is the source for everybody. Perhaps someone can shorten it

Code:
'Requires Registry DLL (object reg), Bitwise DLL (object bit) and Filippo's SysTime DLL (object SysTime)

Sub Globals
  
Dim zti(0As Byte  'binary array for GetTimeZone
End Sub

Sub App_Start
  Reg.New1
  SysTime.New1
End Sub

Sub mnuSetSystemDateTime_Click
  
If GPS.Status<>"A" Then Return    'Aborts if no stable GPS signal present
  'GPS.UTCDate and GPS.UTCTime available from Sub GPS_GPSDecoded. Please see gps.dll Help for details
  Dim x, y, i, zt
  zt = GetTimeZone
  x = DateParse(GPS2Date(
GPS.UTCDate))
  y = TimeParse(GPS2Time(
GPS.UTCTime)) + zt/24 * cTicksPerDay      'add your local time zone
  i = Msgbox("GPS date and time converted to local is " & CrLf & Date(x) & " " & Time(y) & CrLf & "Set the device?"," Confirmation",cMsgBoxYesNo,cMsgBoxQuestion)
  
If i = cNo Then Return
  ErrorLabel(SetError)            
'There is no success flag in the SysTime DLL
  SysTime.New1
  Systime.SetDate(DateMonth(x),DateDay(x),DateYear(x))
  Systime.SetTime(TimeHour(y),TimeMinute(y),TimeSecond(y))
  
Msgbox("GPS Date and Time set."," GPS Date and Time",cMsgBoxNone,cMsgBoxAsterisk)    
  
Return
SetError:
  
Msgbox("Error setting Date and Time."," GPS Date and Time",cMsgBoxNone,cMsgBoxHand)
End Sub

Sub GPS2Time(x)
  
Dim colon
  TimeFormat(
"HH:mm:ss")
  colon=SubString(x,
0,6)
  colon=StrInsert(colon,
2,":")
  colon=StrInsert(colon,
5,":")
  x = TimeParse(colon)
  
if chkAMPM.Checked=True Then TimeFormat("hh:mm:ss tt")  'A check box selects EU or US format
  Return Time(x)
End Sub

Sub GPS2Date(x)
  
Dim dash
  DateFormat (
"yyyy/mm/dd")
  dash=
"20" & SubString(x,4,2) & "/"
  dash=dash & SubString(x,
2,2) & "/"
  dash=dash & SubString(x,
0,2)
  x = DateParse(dash)
  
if chkAMPM.Checked=false then    'A check box selects EU or US format
    DateFormat("dd/mm/yyyy")
  
else
    DateFormat(
"mm/dd/yyyy")
  
End if 
  
Return Date(x)
End Sub

Sub GetTimeZone
  
Dim m, i, b
  Reg.RootKey(Reg.rtLocalMachine)
  
If cPPC = True Then
    zti()=Reg.GetValue(
"Time","TimeZoneInformation")
    
For i = 3 To 0 Step -1
      m = m & 
bit.DecToHex(zti(i))
    
Next
    m = 
bit.HexToDec(m) / 60 * (-1)
  
Else
    m = Reg.GetValue(
"System\CurrentControlSet\Control\TimeZoneInformation","ActiveTimeBias")
    m = m  / 
60 * (-1)
  
End If
  
If m > 0 Then m = "+" & m
  
Return m    
End Sub
Reply With Quote
  #3 (permalink)  
Old 10-09-2007, 07:17 AM
alfcen's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: Okinawa, Ryukyu Islands
Posts: 768
Send a message via Skype™ to alfcen
Awards Showcase
Beta Tester 
Total Awards: 1
Default Correction

Sorry gents,
There is an error in
mnuSetSystemDateTime_Click
which I have corrected as:

Code:
Sub mnuSetSystemDateTime_Click
  
If GPS.Status="A" Then
    
Dim x, i
    x =DateParse(GPS2Time(
GPS.UTCTime))   'addition of time zone must account for date change
    x = x - x Mod cTicksPerDay 
    x = x + TimeParse(GPS2Time(
GPS.UTCTime)) + zt * cTicksPerHour
    i = 
Msgbox("GPS date and time converted to local is " & CrLf & Date(x) & " " & Time(x) & CrLF & "Set the device?"," Confirmation",cMsgBoxYesNo,cMsgBoxQuestion)
    
If i = cNo Then Return
    ErrorLabel(SetError)
    SysTime.New1
    Systime.SetDate(DateMonth(x),DateDay(x),DateYear(x))
    Systime.SetTime(TimeHour(x),TimeMinute(x),TimeSecond(x))
    
Msgbox("GPS Date and Time set."," GPS Date and Time",cMsgBoxNone,cMsgBoxAsterisk)    
    
Return
SetError:
    
Msgbox("Error setting Date and Time."," GPS Date and Time",cMsgBoxNone,cMsgBoxHand)
  
Else
    
Msgbox("GPS data unstable or not available."," GPS Status",cMsgBoxNone,cMsgBoxHand)
    
Return
  
End If        
End Sub
Reply With Quote
Old 02-01-2008, 04:51 AM
Georg
This message has been deleted by Georg.
  #4 (permalink)  
Old 02-01-2008, 04:53 AM
Knows the basics
 
Join Date: Jan 2008
Posts: 78
Default SysTime.dll

Hi

is there also an version for NET 1 compact?
Reply With Quote
  #5 (permalink)  
Old 02-01-2008, 03:27 PM
derez's Avatar
Basic4ppc Expert
 
Join Date: May 2007
Posts: 918
Awards Showcase
Beta Tester Competition Winner 
Total Awards: 2
Default

Thanks Filippo
It's already integrated and working in my navigation program.
__________________
David Erez
Ramat Hasharon, Israel
Reply With Quote
  #6 (permalink)  
Old 07-05-2008, 08:01 PM
Basic4ppc Veteran
 
Join Date: May 2008
Location: Newcastle Upon Tyne - England
Posts: 269
Awards Showcase
Beta Tester 
Total Awards: 1
Default Error in help

Hi Filippo,

I think there is an error in your help file for SetDate

Quote:
Syntax: SetDate(Day As Integer, Month As Integer, Year As Integer)
Its looking as if the Day and Month are swapped i.e. it should read:
Syntax: SetDate(Month As Integer, Day As Integer, Year As Integer)

Edit: "Does anyone know how to set the BIOS date & time in the Desktop?" I see that it does!

Last edited by Zenerdiode : 07-05-2008 at 08:12 PM.
Reply With Quote
  #7 (permalink)  
Old 09-18-2009, 10:53 PM
Basic4ppc Expert
 
Join Date: May 2008
Location: Berkshire, UK
Posts: 762
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Quote:
Originally Posted by alfcen View Post

Code:
Sub mnuSetSystemDateTime_Click
...
    i = 
Msgbox("GPS date and time converted to local is " & CrLf & Date(x) & " " & Time(x) & CrLF & "Set the device?"," Confirmation",cMsgBoxYesNo,cMsgBoxQuestion)
...
    
Return
nd 
Sub
It's not ideal to ask the user a question and then set the time to what was determined before asking the question.

In a Psion program that I wrote years ago to do this I showed the disparity when asking the question (as well as GPS and system times) and then if the user requested time alteration I adjusted the system time by the disparity amount. This is then independent of the user's decision time...
Reply With Quote
  #8 (permalink)  
Old 09-19-2009, 09:41 AM
Basic4ppc Expert
 
Join Date: May 2008
Location: Berkshire, UK
Posts: 762
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Quote:
Originally Posted by Filippo View Post
Hi,

SysTime is a small library to get and set the current system time and system date.
There are two different dll's, one for the desktop and one for the device.

Ciao.
Filippo
This looks jolly useful (surprising it is not already included in other libraries!).

But when I add the DLLs I get offered objects of type "SysTime" (as I expected) but also "SYSTEMTIME". What is the difference, please (and how to remember the distinction; it's not in the Help!).

Mike.
Reply With Quote
  #9 (permalink)  
Old 09-19-2009, 09:50 AM
Basic4ppc Expert
 
Join Date: May 2008
Location: Berkshire, UK
Posts: 762
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Quote:
Originally Posted by alfcen View Post
Ciao Filippo,
Execellent! Awesome!

Thanks to your DLL, I can set the clock with GPS date and time.
Here is the source for everybody. Perhaps someone can shorten it

Code:
...

Sub GetTimeZone
  
Dim m, i, b
  Reg.RootKey(Reg.rtLocalMachine)
  
If cPPC = True Then
    zti()=Reg.GetValue(
"Time","TimeZoneInformation")
    
For i = 3 To 0 Step -1
      m = m & 
bit.DecToHex(zti(i))
    
Next
    m = 
bit.HexToDec(m) / 60 * (-1)
  
Else
    m = Reg.GetValue(
"System\CurrentControlSet\Control\TimeZoneInformation","ActiveTimeBias")
    m = m  / 
60 * (-1)
  
End If
  
If m > 0 Then m = "+" & m
  
Return m    
End Sub
I guess all that stuff with DecToHex and HexToDec is just to convert 4 bytes to a 32-bit integer. Which could be done with some *256 or neatly with the ByteConverter DLL using Int32FromBytes().

But reading the registry item separately on my PDA gives four zeroes (but lots of other following bytes; goodness knows what they mean!). This is fair enough since I am in Zulu time zone. But I am also in daylight saving time, so where would that other hour correction come from?

Mike.
Reply With Quote
  #10 (permalink)  
Old 09-19-2009, 11:14 AM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 5,953
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Quote:
Originally Posted by mjcoon View Post
lots of other following bytes; goodness knows what they mean!
I suspect they contain the DST information for the time zone.

Quote:
SYSTEMTIME
That is a struct definition that shouldn't really be visible. An instance of it is passed to the OS to set or get the time and date information. It is of no use as a Basic4ppc object.

@Filippo - how about hiding "SYSTEMTIME" by renaming it "_SYSTEMTIME" and providing the sources for merging?
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.

Last edited by agraham : 09-19-2009 at 11:16 AM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Door library (Beta) - Special library Erel Official Updates 60 01-13-2011 12:23 PM
Merging Outlook library and Phone library Erel Official Updates 11 09-15-2010 10:22 AM
PhoneticAlgorithms Library (ex-StringComparison Library) moster67 Additional Libraries 10 11-11-2008 08:46 PM


All times are GMT. The time now is 10:14 PM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0