In FileMaker Pro, I am trying to append the current date and time to a filename to which I export data. If I use
Get (CurrentTime)
I get 12-hour time, complete with " PM" or " AM" at the end. Is there built-in functionality to return 24-hour time, instead?
FileMaker help says that the format follows the format of system time, but that is not the case. System time is showing as 17:22, but CurrentTime is returning 52218 PM. (Mac OS 10.8.5, FileMaker Pro 12.0v4.)
Filemaker's internal time storage notation is simply the number of seconds elapsed since midnight of the current day.
I.e. 56659 seconds since midnight = 3:44:19 PM.
When exporting data, you can check off the "Apply current layout's data formatting to exported data" checkbox, so that times displayed as 24-hour in FMP layouts are exported as such.
But, for other internal use such as the file-naming case you're asking about, you will need to use a custom function to convert the output of Get(currentTime) to 24-hour format.
For example, see the TimeFormatAs ( theTime ; type12or24 ) function at Briandunning.com.
(Full code of the custom function is pasted below for protection against dead links in the future, but if the link above still works, use that version as it may be more up-to-date:)
/*---------------------------------------------------------------
Function Name: TimeFormatAs
Syntax: TimeFormatAs ( theTime; type12or24 )
Author - Jonathan Mickelson, Thought Development Corp.
(www.thought-dev.com)
---------------------------------------------------------------*/
Case ( not IsEmpty ( theTime ) ;
Let (
[
// FIXED VARIABLES
padHoursChar = "" ; // Character to pad the Hours with in a text result, (Ex."0", " ", "")
padAMPMChar = " " ; // Character to pad the AM/PM with in a text result, (Ex."0", " ", "")
suffixAM = "AM" ; // <------------ CHANGE AM Suffix Here
suffixPM = "PM" ; // <------------ CHANGE PM Suffix Here
// DYN. VARIABLES
theTime = GetAsTime ( theTime ) ;
hasSeconds = PatternCount ( GetAsText ( theTime ) ; ":" ) = 2 ;
secs = Mod ( Seconds ( theTime ) ; 60 ) ;
mins = Mod ( Minute ( theTime ) ; 60 ) + Div ( Seconds ( theTime ) ; 60 ) ;
hours = Hour ( theTime ) + Div ( Minute ( theTime ) ; 60 ) ;
// -------------- BEGIN 24 HOUR TIME CALC ----------------------
result24 = GetAsTime ( theTime ) + 1 - 1 ;
// -------------- BEGIN 12 HOUR TIME CALC ----------------------
hours = Mod ( Hour ( theTime ) ; 12 ) ;
tempHours = Case ( ( hours < 1 ) or ( hours - 12 = 0 ) ; 12 ; hours ) ;
calc12Hours =
Left (
padHoursChar & padHoursChar ;
2 - Length ( tempHours )
) &
tempHours ;
calc12Minutes = Left ( "00" ; 2 - Length ( mins ) ) & mins ;
calc12Seconds = Left ( "00" ; 2 - Length ( secs ) ) & secs ;
calc12Suffix = Case ( Mod ( Hour ( theTime ) ; 24 ) >= 12 ; suffixPM ; suffixAM ) ;
result12 = calc12Hours &
":" & calc12Minutes &
// if original time included a non-zero seconds value, display seconds
Case ( hasSeconds and secs > 0 ; ":" & calc12Seconds ) &
padAMPMChar & calc12Suffix
] ;
Case ( type12or24 >= "24" ; result24 ; result12 ) // END CASE
) // END LET
) // END CASE
Related
I have a fortran 90 function that is meant to parse a time stamp in the form day as %Y%m%d.%f where %f is fraction of a day /48 and return an array with year, month, day, fraction of day.
function parseTimeStamp (timeStamp)
implicit none
real, dimension(5) :: parseTimeStamp
real, intent(in) :: timeStamp
real :: date, moment
integer :: intdate, day, month, year, t
date = floor(timeStamp) ! remove the part days
parseTimeStamp(4) = timeStamp - date ! save the part days
intdate = int(date)
day = mod(intdate,100); intdate = intdate / 100
month = mod(intdate,100); intdate = intdate / 100
year = intdate
parseTimeStamp(1) = real(year)
parseTimeStamp(2) = real(month)
parseTimeStamp(3) = real(day)
end function parseTimeStamp
The issue is the output shows fraction of the day always at 0. When printing the timestamp (!print *, timeStamp) I get the date without fraction of the day 48 times before rolling over to the next day, even when I know with 100% certainty the data being read contains the proper fraction.
ex: I am getting
20220101.0 20220101.0 20220101.0 .... 20220102.0 20220102.0 ...
instead of
20220101.0 20220101.02083 20220101.04167 .... 20220102.0 20220102.02083 ...
I've tried using several different input files and have confirmed that the input files contain the part day data.
I think you would be better creating a user-defined type to hold your date and time variables than to try to return an array. Year, month and day are more naturally whole numbers (integer type). If you want higher precision use kind=real64 from iso_fortran_env (worth looking up: it has other goodies in that make codes portable).
program test
use iso_fortran_env
implicit none
integer y, m, d ! year, month, day
real(real64) f ! fraction of a day
call parseTimeStamp( "20220101.02083", y, m, d, f )
write( *, "( 3(a, ': ', i0, :, / ) )" ) "year", y, "month", m, "day", d
write( *, "( a, ': ', f7.5 )" ) "fraction", f
contains
subroutine parseTimeStamp( dateTime, year, month, day, dayfraction )
character(len=*), intent(in) :: dateTime
integer, intent(out) :: year, month, day
real(real64), intent(out) :: dayfraction
real(real64) temp
! *** TO DO *** check that timestamp is well formed before anything else
read( dateTime(1:4), * ) year
read( dateTime(5:6), * ) month
read( dateTime(7: ), * ) temp
day = temp
dayfraction = temp - day
end subroutine parseTimeStamp
end program test
year: 2022
month: 1
day: 1
fraction: 0.02083
If you want to go with a user-defined type then you can return that from a function:
module timemod
use iso_fortran_env
implicit none
type DTime
integer year
integer month
integer day
real(real64) fraction ! fraction of a day
end type DTime
contains
type(DTime) function parseTimeStamp( dateStamp ) result( res )
character(len=*), intent(in) :: dateStamp
real(real64) temp
read( dateStamp(1:4), * ) res%year
read( dateStamp(5:6), * ) res%month
read( dateStamp(7: ), * ) temp
res%day = temp
res%fraction = temp - res%day
end function parseTimeStamp
end module timemod
!=======================================================================
program test
use iso_fortran_env
use timemod
implicit none
write( *, "( 3( i0, / ), f7.5 )" ) parseTimeStamp( "20220101.02083" )
end program test
I'm building a simple AudioUnit app which should use an AUGraph to connect a generator (which generates, say, a sine wave) to a format converter (because that seems like what I need) to an output device.
Code snippets:
{
AudioComponentDescription desc ;
desc.componentType = kAudioUnitType_Generator ;
desc.componentSubType = kAudioUnitSubType_ScheduledSoundPlayer ;
desc.componentFlags = 0 ;
desc.componentFlagsMask = 0 ;
desc.componentManufacturer = kAudioUnitManufacturer_Apple ;
status = AUGraphAddNode ( mGraph , &desc , &mGeneratorNode ) ;
checkOSStatus ( "creating generator node" , status ) ;
}
I do similarly for mConverterNode with kAudioUnitType_FormatConverter/kAudioUnitSubType_AUConverter and for mOutputNode with kAudioUnitType_Output/kAudioUnitSubType_DefaultOutput.
I then open the graph:
AUGraphOpen ( mGraph ) ; // error checking code omitted from example
I then get references to them:
AUGraphNodeInfo ( mGraph , mGeneratorNode , 0,&mGeneratorRef ) ; // error checking code omitted from example
I then set the format:
{
AudioStreamBasicDescription format ;
format.mSampleRate = mSamplingRate ;
format.mFormatID = kAudioFormatLinearPCM ;
format.mFormatFlags = kAudioFormatFlagIsSignedInteger ;
format.mFramesPerPacket = 1 ;
format.mChannelsPerFrame = 1 ; // mono
format.mBitsPerChannel = 16 ;
format.mBytesPerFrame = format.mBitsPerChannel*format.mChannelsPerFrame/8 ;
format.mBytesPerPacket = format.mBytesPerFrame*format.mFramesPerPacket ;
status = AudioUnitSetProperty ( mGeneratorRef , kAudioUnitProperty_StreamFormat , kAudioUnitScope_Output , kOutputBus , &format,sizeof(format) ) ;
checkOSStatus ( "setting output format" , status ) ;
}
(Note: kOutputBus is an enum to 0; it's an anachronism from a previous example I found. Also, mSamplingRate is a size_t whose value is 48000)
And set the render callback:
{
AURenderCallbackStruct cb ;
cb.inputProc = &_callbackProxy ;
cb.inputProcRefCon = static_cast<void*> ( this ) ;
status = AudioUnitSetProperty ( mGeneratorRef , kAudioUnitProperty_SetRenderCallback , kAudioUnitScope_Output , 0 , &cb,sizeof(cb) ) ;
checkOSStatus ( "setting the generator callback" , status ) ;
}
However, for both the stream format and the render callback I get kAudio_ParamError back as the resultant status.
No matter what I do (mono/stereo, when I place that command, etc), I cannot make it work.
Note: I later do this:
AUGraphConnectNodeInput ( mGraph , mGeneratorNode,0 , mConverterNode,0 ) ;
AUGraphConnectNodeInput ( mGraph , mConverterNode,0 , mOutputNode,0 ) ;
AUGraphInitialize ( mGraph ) ;
AUGraphStart ( mGraph ) ;
// again, error-checking code omitted from example
And it works........ But I can't set those properties and therefore can't generate audio.
What am I missing?
(To people with 1500+ reputation: please make an "osx-sierra" tag; I'm a bit shy of that mark)
From an obscure comment at the end of this:
https://discussions.apple.com/thread/1989797?tstart=0
I ran AUGraphOpen at the very beginning before creating things (why?) and it worked.
But then I was getting invalid format errors, so I set the format on the input of the converter instead of the output of the generator.
But then it wasn't calling the render callback, so I removed the generator altogether and put the render callback on the input of the converter.
At this point, it worked and is generating my sound.
I hope this helps somebody else in the future with this so-horribly-documented API.
I use below code for #1 screenshot.
int _objfnd = ObjectFind( name );
if ( _objfnd == -1 )
{
ObjectCreate ( _vlineName, OBJ_VLINE, 0, Time[i], 0 );
...
}
and I use below code for #2 screenshot.
int _objfnd = ObjectFind( name );
if ( _objfnd == -1 )
{
datetime _dayTime = Time[i] ;
int _dayNext = PeriodSeconds( _Session_Breaks_Day_Prd ) ;
_dayTime = _dayTime - ( _dayTime % _dayNext ) + _dayNext ;
ObjectCreate ( _vlineName, OBJ_VLINE, 0, _dayTime, 0 ) ;
}
If you figure out my concern,please give me good advice, much appreciate.
A: the code has not handled Daylight Saving Time Shift 2016, Nov-06
I want to load an image from a URL.
I can load an image using this code:
local group = display.newGroup();
local testImg;
testImg = display.newImage( "cells/cellBottom.png");
group:insert( testImg );
but i need to use something like:
testImg = display.loadRemoteImage( "https://www.dropbox.com/s/fqlwsa5gupt5rsj/amcCells.png")
group:insert( testImg );
Please tell me how to load this image.
Cheers :)
Just use example given in Corona. This works with the following url but your url seems to have problem.
local function networkListener( event )
if ( event.isError ) then
print ( "Network error - download failed" )
else
event.target.alpha = 0
transition.to( event.target, { alpha = 1.0 } )
end
print ( "event.response.fullPath: ", event.response.fullPath )
print ( "event.response.filename: ", event.response.filename )
print ( "event.response.baseDirectory: ", event.response.baseDirectory )
end
display.loadRemoteImage( "http://coronalabs.com/images/coronalogogrey.png", "GET", networkListener, "coronalogogrey.png", system.TemporaryDirectory, 50, 50 )
try add yougroup:insert(event.target) in listener
local function networkListener( event )
if ( event.isError ) then
print ( "Network error - download failed" )
else
event.target.alpha = 0
transition.to( event.target, { alpha = 1.0 } )
**yourgroup:insert(event.target)**
end
print ( "event.response.fullPath: ", event.response.fullPath )
print ( "event.response.filename: ", event.response.filename )
print ( "event.response.baseDirectory: ", event.response.baseDirectory )
end
display.loadRemoteImage( "http://coronalabs.com/images/coronalogogrey.png", "GET", networkListener, "coronalogogrey.png", system.TemporaryDirectory, 50, 50 )
I've started learning Maxscripts and i've now hit a wall,
im trying to get the name of my selection, if it's a single object and
then if its more than 1, have the label display the number of objects as a string.
but i keep getting an error... any idea?
group "Current Selection:"
(
label lbl_01 "Nothing Selected"
)
---------------------------------------------------------------------------------------------------------------// Current Selection Function
fn letmeknow obj=
(
local contador = (selection.count as string)
if selection.count != 0 then
(
lbl_01.text = ("Name: " + obj.name)
)
else
(
lbl_01.text = "Nothing Selected"
)
if selection.count >= 2 do (lbl_01.text = ("Objects: " + contador))
)
Looks like the issue is outside the code you've supplied and without seeing the rest of the code, it's hard to tell. Anyway, here's a working example using case expression instead of multiple ifs:
rollout test "Test"
(
group "Current Selection:"
(
label lbl_01 "Nothing Selected"
)
button btnTest "Test"
fn getSelectionString =
(
case selection.count of
(
0 : "Nothing Selected"
1 : "Name: " + selection[1].name
default : "Objects: " + selection.count as string
)
)
on btnTest pressed do
lbl_01.text = getSelectionString()
)
createDialog test