GetLocalDate not work with x86

Mac OSX specific forum
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

GetLocalDate not work with x86

Post by mk-soft »

This is a addition vor Wilbert's QDate...
But is not work as X86

Code: Select all

CompilerSelect #PB_Compiler_OS
  CompilerCase #PB_OS_MacOS
    ImportC ""
      CFAbsoluteTimeGetCurrent.d()
      CFTimeZoneCopyDefault()
      CFAbsoluteTimeGetGregorianDate.q(timeCurrent.d, *timeZone)
      CFAbsoluteTimeGetGregorianDateSecond.d(timeCurrent.d, *timeZone) As "_CFAbsoluteTimeGetGregorianDate"
      CFRelease(*a)
    EndImport
    
    Structure CFGregorianDateHelp
      Year.l
      Month.b
      Day.b
      Hour.b
      Minute.b
    EndStructure
    
    Structure CFGregorianDate
      StructureUnion
        Date.q
        Detail.CFGregorianDateHelp
      EndStructureUnion
    EndStructure
    
    Procedure GetLocalDate(*Year.word, *Month.byte, *Day.byte, *Hour.byte, *Minute.byte, *Second.byte)
      Protected timeCurrent.d, *timeZone
      Protected LocalDateTime.CFGregorianDate, LocalSecond.d
      timeCurrent = CFAbsoluteTimeGetCurrent()
      *timeZone = CFTimeZoneCopyDefault()
      LocalDateTime\Date = CFAbsoluteTimeGetGregorianDate(timeCurrent, *timeZone)
      localsecond = CFAbsoluteTimeGetGregorianDateSecond(timeCurrent, *timeZone)
      CFRelease(*timeZone)
      With LocalDateTime\Detail
        *Year\w = \Year
        *Month\b = \Month
        *Day\b = \Day
        *Hour\b = \Hour
        *Minute\b = \Minute
      EndWith
      *Second\b = Round(LocalSecond, #PB_Round_Down)
    EndProcedure
    
  CompilerCase #PB_OS_Linux
    
  CompilerCase #PB_OS_Windows
    
CompilerEndSelect

Define.w year
Define.b month, day, hour, minute, second

GetLocalDate(@year, @month, @day, @hour, @minute, @second)
Debug "Year: " + Str(year)
Debug "Month: " + Str(month)
Debug "Day: " + Str(day)
Debug "Hour: " + Str(hour)
Debug "Minute: " + Str(minute)
Debug "Second: " + Str(second)
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: GetLocalDate not work with x86

Post by wilbert »

mk-soft wrote:But is not work as X86
You can use CFCalendar but in this case the calendar components need to be of the integer type.

Code: Select all

ImportC ""
  CFCalendarCopyCurrent()
  CFCalendarDecomposeAbsoluteTime(calendar, at.d, componentDesc.p-ascii, *year, *month, *day, *hour, *minute, *second)
EndImport

Procedure GetLocalDate(*Year, *Month, *Day, *Hour, *Minute, *Second)
  Protected.i CurrentCalendar = CFCalendarCopyCurrent()
  CFCalendarDecomposeAbsoluteTime(CurrentCalendar, CFAbsoluteTimeGetCurrent_(), "yMdHms", 
                                  *Year, *Month, *Day, *Hour, *Minute, *Second)
  CFRelease_(CurrentCalendar)
EndProcedure



Define.i year, month, day, hour, minute, second

GetLocalDate(@year, @month, @day, @hour, @minute, @second)
Debug "Year: " + Str(year)
Debug "Month: " + Str(month)
Debug "Day: " + Str(day)
Debug "Hour: " + Str(hour)
Debug "Minute: " + Str(minute)
Debug "Second: " + Str(second)
Another option is to use the NSDateComponents class.

Code: Select all

CurrentDate = CocoaMessage(0, 0, "NSDate date")
CurrentCalendar = CocoaMessage(0, 0, "NSCalendar currentCalendar")
DateComponents = CocoaMessage(0, CurrentCalendar, "components:", %11111100, "fromDate:", CurrentDate)

Debug CocoaMessage(0, DateComponents, "year")
Debug CocoaMessage(0, DateComponents, "month")
Debug CocoaMessage(0, DateComponents, "day")

Debug CocoaMessage(0, DateComponents, "hour")
Debug CocoaMessage(0, DateComponents, "minute")
Debug CocoaMessage(0, DateComponents, "second")
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: GetLocalDate not work with x86

Post by mk-soft »

Thanks Wilbert,

works fine :wink:
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply